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
Avoid a stop loss executed at a ridiculous price at market open
Avoid a stop loss executed at a ridiculous price at market open
- Attachments
-
- Execution off reasonable market.jpg
- (57.75 KiB) Not downloaded yet
- 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
Traditionally the spread refers to the difference between the bid and ask; not the close and ask/bid.
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.
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)+"%");
Make sure the bid and ask are in Data2 and Data3, so they aren't just the values at a new bar of Data1.
Re: Avoid a stop loss executed at a ridiculous price at market open
@Jupp25, yes, all based on saxo data. but i was told trade prices are nothing more than just mid prices.