Execution of Stoploss Orders  [SOLVED]

Questions about MultiCharts and user contributed studies.
Parker
Posts: 22
Joined: 18 May 2018
Has thanked: 7 times

Execution of Stoploss Orders

Postby Parker » 24 Jun 2018

So I want to open a trade and set a stoploss order straight away based on a number of points from the opening price.

The code I am using is:

Code: Select all


if MarketPosition=0 AND EntryFilter=True then BEGIN;
SL = AvgTrueRange(20) * Multiple;
BUY ("LE") 1 Contract next bar at Open;
END;

if MarketPosition<>0 AND SL>0 then setstoploss_pt(SL*PriceScale);
I am finding that the stoploss order is executed one bar after the entry. Is this behaviour expected or am I doing something wrong with the code?

How do I execute the stoploss order at the same time as the entry order?

Thanks.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Execution of Stoploss Orders

Postby TJ » 24 Jun 2018


Parker
Posts: 22
Joined: 18 May 2018
Has thanked: 7 times

Re: Execution of Stoploss Orders  [SOLVED]

Postby Parker » 25 Jun 2018

Thanks, this has worked!

It seems the "marketposition<>0 condition does not work with the SL if need it to be executed straight away. I assume it must not pick up the marketposition change until the next bar.


Return to “MultiCharts”