Avoid a stop loss executed at a ridiculous price at market open

Questions about MultiCharts and user contributed studies.
kinginhk
Posts: 10
Joined: 14 Jul 2022
Has thanked: 3 times

Avoid a stop loss executed at a ridiculous price at market open

Postby kinginhk » 11 Dec 2022

Hello all,

I'm trying to find a way to avoid getting a stop loss or profit trailing triggered when the bid ask spreads are unreasonable. This is for a forex algo.

I have this code already, to restrict the stop loss and profit trail functions:
if (insideask-Close)<(2/10000) and (Close-insidebid)<(2/10000) then begin //hoping this means trade only when bid ask spread is less than 4pips

However, i still get filled at market opens at off market prices, cf picture.

Please help!

Many thanks
Attachments
Execution off reasonable market.jpg
(57.75 KiB) Not downloaded yet

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: Avoid a stop loss executed at a ridiculous price at market open

Postby rrams » 11 Dec 2022

Traditionally the spread refers to the difference between the bid and ask; not the close and ask/bid.

Code: Select all

var: Spread(0); // Forex must be calculated in either pips or percent. // (Ask-Bid)/(Ask)*100 = percent of spread if InsideAsk<>0 then // (InsideAsk-InsideBid)/(10*PointValue)=pips X 10 same as Oanda. Spread=10000*(InsideAsk-InsideBid)/InsideAsk; print(" Spread: "+NumToStr(Spread, 2)+"%");
You could plot the spread in a real-time indicator and check orders against it on the chart to see if that is the problem.
Make sure the bid and ask are in Data2 and Data3, so they aren't just the values at a new bar of Data1.

kinginhk
Posts: 10
Joined: 14 Jul 2022
Has thanked: 3 times

Re: Avoid a stop loss executed at a ridiculous price at market open

Postby kinginhk » 11 Dec 2022

thank you!

Jupp25
Posts: 50
Joined: 17 Sep 2021
Has thanked: 13 times
Been thanked: 7 times

Re: Avoid a stop loss executed at a ridiculous price at market open

Postby Jupp25 » 12 Dec 2022

@kinginhk: just out of curiosity, are your calculations based on the same data that your trades are executed on?

kinginhk
Posts: 10
Joined: 14 Jul 2022
Has thanked: 3 times

Re: Avoid a stop loss executed at a ridiculous price at market open

Postby kinginhk » 12 Dec 2022

@Jupp25, yes, all based on saxo data. but i was told trade prices are nothing more than just mid prices.


Return to “MultiCharts”