Hi guys n gals
A quick question around stop orders in the code and when executed. so on the selected pic attached I graphed in the area of the order for 1:1 whether used as a limit or stop order.
In backtesting the limit works fine takes out the desired profit, on stop orders it also takes out the orders howeve in some circumstances it doesn’t when the price rallies, however backtesting on Dax here I’m seeing it extend around 10 pips above and come back 5 pips below which even with spread should stop out and take partial profits but it doesnt. This is 08:45 a.m and looking onthe platform minimum stop is 5.
So my questionis do stop orders have to come past the minimum order distance when set as a stop?
Why do we think this isn’t stopping out?
In the meantime I’ll likely just code in a sell at market for 50% off instead of sitting orders but an explanation of the Stop order not stopping out in that picture be appreciated.
Thanks in advance.
Ok so the spread was 1.2 and when setting to 2pips it does stop out – so I may not understand something as my logic sugests it should stop out on that chart at some point as it passes and comes back down but allows the trade to continue without amount being reduced with 1.2 pips…
Are you sure the pending order was set and at the correct price? Did you graph its level on the chart?
Yes, the line you see is where the order is taken for limit orders and the stop order where spread is set to 2. to be clear it executes the stop order at 2 pips spread and not at 1.2 pips spread.. not sure why…. the order actually executes at the start of the line and the line and is “graphonprice pipslim” which is where pipslim is >= the 1:1 in pips the order level whichremains unable to re-execute a second time around.
y=myamount/2
If not onmarket then
stopstop=0
endif
if stopstop=0 then
pipslim=tradeprice*positionperf
If longonmarket and pipslim>=(tradeprice+SLL)-tradeprice then
sell y contracts at tradeprice+sll stop
stopstop=1
endif
I just had a crash on the platform and it didnt save but without re-testing believe that was the code.
Works for 2 pip spread backtest but not for 1.2 pips but I think based on the 1 second chart price action it shouldn’t matter in relation to those spread differences so a query on what it’s doing really.
It is a backtest
I’ll try the below code and see if it has the same anomaly
If not OnMarket then
NewSLim = 0
Endif
If take50>0 then
if NewSLim = 0 and PositionPerf > 0 then
Pipslim = tradeprice * PositionPerf
If longonmarket and Pipslim >= (SLL*pipsize) then
NewSLim = tradeprice + sll
stopstop=1
elsif shortonmarket and Pipslim >= (SLS*pipsize) Then
NewSLim = tradeprice - sls
stopstop=1
Endif
endif
If NewSLim > 0 Then
SELL y contracts at NewSLim STOP
buy y contracts at NewSLim STOP
endif
endif
might have to add direction there methinks
My simplest solution
y=myamount/2
/////////////////////////////////////////////////////////////////////////
If not onmarket then
stopstop=0
endif
if stopstop=0 and take50=1 then
piplim=tradeprice*positionperf
If longonmarket and piplim>=(tradeprice+SLL)-tradeprice then
sell y contracts at market
stopstop=1
elsif shortonmarket and piplim >=tradeprice-(tradeprice-SLS) then
exitshort y contracts at market
stopstop=1
endif
endif
Broker orders… pwfff!