How to distinguish between a 'setstoploss' or 'setprofittarg

Questions about MultiCharts and user contributed studies.
mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

How to distinguish between a 'setstoploss' or 'setprofittarg

Postby mefTrader » 24 May 2012

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 ?

evdl
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

Postby evdl » 24 May 2012

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.

escamillo
Posts: 203
Joined: 25 Mar 2011
Has thanked: 23 times
Been thanked: 56 times

Re: How to distinguish between a 'setstoploss' or 'setprofit

Postby escamillo » 24 May 2012

Code: Select all

if MP = 1 then amount = 200
else
if MP = -1 then amount = 100 ;
setstoploss(amount) ;

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: How to distinguish between a 'setstoploss' or 'setprofit

Postby mefTrader » 24 May 2012

that will not work - have tried it.

User avatar
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

Postby TJ » 24 May 2012

that will not work - have tried it.
Please post your code that did not work.

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: How to distinguish between a 'setstoploss' or 'setprofit

Postby mefTrader » 24 May 2012

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?

User avatar
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

Postby Henry MultiСharts » 06 Jun 2012

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?
Hello MefTrader,

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);


Return to “MultiCharts”