Stop order functioning in codes versus limits

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #163616 quote
    Philstrading
    Participant
    Senior

    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.

    dax-stop-orders.jpg dax-stop-orders.jpg
    #163623 quote
    Philstrading
    Participant
    Senior

    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…

    #163624 quote
    Nicolas
    Keymaster
    Master

    Are you sure the pending order was set and at the correct price? Did you graph its level on the chart?

    #163642 quote
    Philstrading
    Participant
    Senior

    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

    #163645 quote
    Philstrading
    Participant
    Senior

    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
    #163646 quote
    Philstrading
    Participant
    Senior

    might have to add direction there methinks

    #163652 quote
    Philstrading
    Participant
    Senior

    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!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Stop order functioning in codes versus limits


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by Philstrading
4 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/09/2021
Status: Active
Attachments: 1 files
Logo Logo
Loading...