Adding Orders Near Take Profit/Short Sell Near Stop Loss

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

    Hi I’d like to add Orders Near Take Profit/Short Sell Near Stop Loss levels.

    So far I have this which is to initiate another trade when the price reaches 90% of it’s take profit level. How would I make this so the new order has a different stop loss/take profit level to the orders in the rest of the code?

    So I want a separate stop loss, trailing step and take profit just this part of the code below. How do I do that?

    //within reach of the take profit
    IF Close-TRADEPRICE(1)>(TKPROFIT*0.9) AND CountOfPosition < 3 AND LONGONMARKET THEN
    BUY 1 PERPOINT AT MARKET
    ENDIF
     
    IF TRADEPRICE(1)-Close>(TKPROFIT*0.9) AND CountOfPosition < 3 AND SHORTONMARKET THEN
    SELLSHORT 1 PERPOINT AT MARKET
    ENDIF

    Here is the whole thing

    DEFPARAM CumulateOrders = True // Cumulating positions deactivated
    
    ATR = AverageTrueRange[186]
    
    //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.25)*40
    //trailing step to move the "stoploss"
    TRSTEP = (ATR*0.25)*4
    // Target profit = S*T
    TKPROFIT = (ATR*0.25)*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
    
    //within reach of the take profit
    IF Close-TRADEPRICE(1)>(TKPROFIT*0.9) AND CountOfPosition < 3 AND LONGONMARKET THEN
    BUY 1 PERPOINT AT MARKET
    ENDIF
    
    IF TRADEPRICE(1)-Close>(TKPROFIT*0.9) AND CountOfPosition < 3 AND SHORTONMARKET THEN
    SELLSHORT 1 PERPOINT AT MARKET
    ENDIF
    #134321 quote
    GraHal
    Participant
    Master

    So I want a separate stop loss, trailing step and take profit just this part of the code below. How do I do that?

    That would mean a partial exit and we can’t do that currently in PRT due to IG not allowing us.

    #134607 quote
    tradetrader101
    Participant
    Junior

    Hi Thanks. So just to make sure we are on the same page just wanted to clarify what I was asking and even if we are then I wanted to ask you the part at the end anyway.

    So basically I got the idea from the article at this link https://www.prorealcode.com/documentation/tradeprice/ Here he adds a second order in the same direction as the the first trade when the first trade goes 10 points in his favour.

    So I’m saying can I substitute out 10 point in my favour as a command and substitute in if the price reaches 90% of my take profit number?

    So that’s the first part. Then I was saying if you can then can you set a different take profit level for the second order like for example when they are both buys.

    Then even if you can’t set a different take profit level, stop loss etc, and even if I had to do it his way and order a second trade once it goes ten points in my favour, would the second trade automatically have the same take profit level of e.g. 16 combined or would they both have to hit 16 each. So 32 in total?

     

     

    myMACD = MACD[12,26,9](close)
    long = myMACD crosses over 0
    exit = myMACD crosses under 0
     
    //first order
    IF NOT LongOnMarket AND long THEN
       BUY 1 CONTRACTS AT MARKET
    ENDIF
     
    If LongOnMarket AND exit THEN
       SELL AT MARKET
    ENDIF
     
    //let's add another order while price continue to get higher (more than 10 points) than the last order taken with a condition of 5 bars elapsed since then
    IF BARINDEX-TRADEINDEX(1)>5 AND Close-TRADEPRICE(1)>10 AND LongOnMarket THEN
       BUY 1 CONTRACTS AT MARKET
    ENDIF
     
    //trailing stop for the whole orders
    SET STOP %TRAILING 1.5
    #134638 quote
    Vonasi
    Moderator
    Master

    Topic moved to the correct forum.

    @tradetrader101 – read the rules before posting in the forums again to ensure that you post your topics in the correct place.

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

Adding Orders Near Take Profit/Short Sell Near Stop Loss


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by Vonasi
5 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/03/2020
Status: Active
Attachments: No files
Logo Logo
Loading...