Add entry when trailing triggered

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #115401 quote
    CKW
    Participant
    Veteran

    Hi All,

    Just wondering if PRT allows add entry when you have trailing feature activated in your source code ?

    For testing, I used sample from Nicholas and add new “market orders” when price triggered “first move of trailing“, and “next moves of trailing“. Apparently, It doesn’t work as I don’t find any trades open with 1.5 contracts or maybe my method is wrong :).

    Basically, my Idea is to add contracts when initial position reaches targeted trailing moves.

    Thanks for your advice

    defparam cumulateorders = false
     
    //order launch (example) would be set to any other entry conditions
    //c1 = close>close[1]
    c2 = close<close[1]
    TrailingFlag = 0
    //if c1 then
    //BUY 1 LOT AT MARKET
    //SET STOP PLOSS 50
    //endif
     
    if c2 then
    SELLSHORT 1 contract AT MARKET
    SET STOP PLOSS 50
    endif
     
    //************************************************************************
    //trailing stop function
    trailingstart = 20 //trailing will start @trailinstart points profit
    trailingstep = 5 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    TrailingFlag = 1
    SELLSHORT 1.5 contract AT MARKET
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    TrailingFlag = 2
    SELLSHORT 1.5 contract AT MARKET
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    Graph TrailingFlag
    //************************************************************************
    
    #115402 quote
    Vonasi
    Moderator
    Master

    Remove:

    defparam cumulateorders = false
    
    #115403 quote
    CKW
    Participant
    Veteran

    Hi Vonasi,

    Thanks.

    Remove first line or “cumulateorders = true” then it works but I encountered another issue. Let me attach the new code to precise the issue.

    Please find the details from the attached screenshot, and my observation below. From Orders list and Closed Positions list, the entry date and exit date are not tally:

    1. (Black) Rectangular for left and right entry time are not tally, and 2nd order always return 0 bar
    2. (green) Rectangular always the same time as 2nd order entry

    Thanks for your advice

    defparam cumulateorders = true
     
    //order launch (example) would be set to any other entry conditions
    //c1 = close>close[1]
    c2 = close<close[1]
    TrailingFlag = 0
    //if c1 then
    //BUY 1 LOT AT MARKET
    //SET STOP PLOSS 50
    //endif
     
    if c2 AND Not ShortOnmarket then
    SELLSHORT 1 contract AT MARKET
    SET STOP PLOSS 50
    endif
     
    //************************************************************************
    //trailing stop function
    trailingstart = 20 //trailing will start @trailinstart points profit
    trailingstep = 5 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT SHORTONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    TrailingFlag = 1
    SELLSHORT 1.5 contract AT MARKET
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    TrailingFlag = 2
    //SELLSHORT 1.5 contract AT MARKET
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    Graph TrailingFlag
    //************************************************************************
    

     

    ode

    Capture-2.jpg Capture-2.jpg
    #116017 quote
    Nicolas
    Keymaster
    Master

    Your 2 orders are closed at the same time by the trailing stop, or I don’t get what is your question?

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

Add entry when trailing triggered


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
CKW @ckw Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by Nicolas
6 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/23/2019
Status: Active
Attachments: 1 files
Logo Logo
Loading...