Stop Loss & Take Profit Not Working

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #193740 quote
    tradetrader101
    Participant
    Junior

    Hi, wondering if anyone could help. My current stop loss and take profit below only works (displays correctly) with forex and indices and doesn’t display at
    all with any shares. So if I trade GBP/EUR for example it’ll calculate my stop loss and take profit and set it for me and it’ll even update the new stop loss
    and take profit from time to time but with shares such as “Proctor & Gamble” etc the exact same code does not even recognise the stop loss and take profit
    is there and the trades are just initiated as usual but with no stop loss and take profit which can be really costly. So does anyone know how to solve this
    as in is there an issue with the code below or is something else causing this?

    
    //-------------------------------------------------------------------------
    // Main code : SELL AROON 2 TD REV UP6
    //-------------------------------------------------------------------------
    DEFPARAM CumulateOrders = True // Cumulating positions deactivated
    
    ATR = AverageTrueRange[168]
    
    //take profit
    SET TARGET pPROFIT TKPROFIT
    
    IF NOT ONMARKET AND (PositionPerf(1) + PositionPerf(2) +  PositionPerf(3) + PositionPerf(4)) <  -100 OR STRATEGYPROFIT < -100 THEN
    QUIT
    ENDIF
    
    //trailing stop function (make equal to absolute value when trailing stop and absolute value)
    IF CountOfPosition < 2 AND ONMARKET AND PositionPerf(1) > 0 THEN
    //trailing will start @trailinstart points profit
    TRSTART = (ATR*0.50)*40
    //trailing step to move the "stoploss"
    TRSTEP = (ATR*0.50)*4
    // Target profit = S*T
    TKPROFIT = (ATR*0.50)*16
    ENDIF
    IF CountOfPosition < 2 AND ONMARKET AND PositionPerf(1) <= 0 THEN
    //trailing will start @trailinstart points profit
    TRSTART = (ATR*0.45)*40
    //trailing step to move the "stoploss"
    TRSTEP = (ATR*0.45)*4
    // Target profit = S*T
    TKPROFIT = (ATR*0.45)*16
    ENDIF
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    SPLOSS = 0
    ENDIF
    
    //manage long positions
    IF LONGONMARKET THEN
    
    //first move (breakeven)
    IF SPLOSS = 0 AND close-TradePrice(1)>=TRSTART THEN
    SPLOSS = TradePrice(1)+TRSTEP
    ENDIF
    
    //next moves
    IF SPLOSS > 0 AND close-SPLOSS>TRSTEP THEN
    SPLOSS = SPLOSS+TRSTEP
    ENDIF
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF SPLOSS = 0 AND TradePrice(1)-close>=TRSTART THEN
    SPLOSS = TradePrice(1)-TRSTEP
    ENDIF
    
    //next moves
    IF SPLOSS> 0 AND SPLOSS-close>TRSTEP THEN
    SPLOSS = SPLOSS-TRSTEP
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF SPLOSS > 0 THEN
    SELL AT SPLOSS STOP
    EXITSHORT AT SPLOSS STOP
    ENDIF
    
    //put the first stoploss
    IF ONMARKET AND SPLOSS = 0 THEN
    SET STOP pTRAILING TRSTART
    ENDIF
    
    #193754 quote
    robertogozzi
    Moderator
    Master

    Firstly, SET STOP pTRAILING can only be used in ProBackTest, as it’s not allowed in autotrading.

    ProOrder doesn’t allow two combined stops on the same line, it must be either SET STOP pTRAILING or SET STOP pLOSS.

    Secondly, ATR is a price (range), so you shouldn’t use ”p” with both PROFIT and LOSS as it stands for pip (range).

    Thirdly, in case you accumulate positions or partially close positions,  TradePrice(1) will always retain the last price traded, be it entry or exit, not the first entry price.

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

Stop Loss & Take Profit Not Working


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
3 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/24/2022
Status: Active
Attachments: No files
Logo Logo
Loading...