I am using the keywords 'setstoploss (amount) ' and 'setprofittarget (amount)'
I would like to have 'amount' variable for a Long trade versus a Short Trade.
What is best practice to do this ?
How to distinguish between a 'setstoploss' or 'setprofittarg
-
- Posts: 401
- Joined: 19 Jan 2011
- Location: Netherlands
- Has thanked: 85 times
- Been thanked: 124 times
Re: How to distinguish between a 'setstoploss' or 'setprofit
If I am not mistaken, the setstoploss and setprofittarget are global exits. Which means that whatever you take as amount will be the setting for long or short and is not used in a condition. (if..then).
Possible option is to not use these reserved words and write your own code. I made some attempt and you can find these on this forum. See http://www.multicharts.com/discussion/v ... =1&t=10330
That is the novice way. The more advance way is what Neil has done (NW27) and replied in the same topic.
Possible option is to not use these reserved words and write your own code. I made some attempt and you can find these on this forum. See http://www.multicharts.com/discussion/v ... =1&t=10330
That is the novice way. The more advance way is what Neil has done (NW27) and replied in the same topic.
Re: How to distinguish between a 'setstoploss' or 'setprofit
Code: Select all
if MP = 1 then amount = 200
else
if MP = -1 then amount = 100 ;
setstoploss(amount) ;
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Re: How to distinguish between a 'setstoploss' or 'setprofit
Please post your code that did not work.that will not work - have tried it.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: How to distinguish between a 'setstoploss' or 'setprofit
Hello MefTrader,Does SetStopLOss and SetProfitTarget 'amount' have to be set before entering a trade and/or can it be set during a trade?
What are the limits on it?
Amount – is the parameter of Setstoploss function. You can specify it during a trade. Here is a sample code we tested:
Code: Select all
var: intrabarpersist MP(0);
var: intrabarpersist amount(0);
if mod(currentbar, 3) = 0 then begin
buy next bar at market;
end;
if mod(currentbar, 2) = 0 then begin
sellshort next bar at market;
end;
MP = MarketPosition_at_Broker;
if MP = 1 then begin amount = 100; end;
if MP = -1 then begin amount = 200; end;
print("MP = ", MP, "amount = ", amount);
SetStopPosition;
setstoploss(amount);