Add entry when trailing triggered
Forums › ProRealTime English forum › ProOrder support › Add entry when trailing triggered
- This topic has 3 replies, 3 voices, and was last updated 4 years ago by Nicolas.
-
-
12/23/2019 at 4:59 AM #115401
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
Sample ShortSell with Trailing123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263defparam 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//endifif c2 thenSELLSHORT 1 contract AT MARKETSET STOP PLOSS 50endif//************************************************************************//trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeTrailingFlag = 1SELLSHORT 1.5 contract AT MARKETENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeTrailingFlag = 2SELLSHORT 1.5 contract AT MARKETENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFGraph TrailingFlag//************************************************************************12/23/2019 at 7:48 AM #11540212/23/2019 at 8:28 AM #115403Hi 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:
- (Black) Rectangular for left and right entry time are not tally, and 2nd order always return 0 bar
- (green) Rectangular always the same time as 2nd order entry
Thanks for your advice
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263defparam 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//endifif c2 AND Not ShortOnmarket thenSELLSHORT 1 contract AT MARKETSET STOP PLOSS 50endif//************************************************************************//trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT SHORTONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeTrailingFlag = 1SELLSHORT 1.5 contract AT MARKETENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeTrailingFlag = 2//SELLSHORT 1.5 contract AT MARKETENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFGraph TrailingFlag//************************************************************************ode
01/06/2020 at 11:19 AM #116017 -
AuthorPosts
Find exclusive trading pro-tools on