Adding second Traling Stop Loss condition causes countertrend trade. Why?
Forums › ProRealTime English forum › ProOrder support › Adding second Traling Stop Loss condition causes countertrend trade. Why?
- This topic has 4 replies, 2 voices, and was last updated 5 years ago by Sascha.
-
-
04/23/2019 at 4:38 PM #97004
Hi,
So far I had one trailing stop condition which worked fine. Then I added a second condition which works partly.
The short trade was exited after the second Trailing Stop condition was met. However, it created instantly a new long trade which should not happen.
I guess something is not right with the order of the code.
Can anyone help?
Thanks.
Sascha
1234567891011121314151617181920212223242526272829303132333435363738394041424344//if not order on market, reset the breakeven statusif not onmarket thenbreakeven=0endif//check if the current order has made 2*ATR of signal dayif shortonmarket and tradeprice-close >=2*ATR thenbreakeven=1endif//put stoploss at open price - 3 pipif breakeven=1 thenbuy at tradeprice-3*pointsize stopendif//------When adding this second set of Trailing Stop condition it causes a new long trade. Why?//if not order on market, reset the breakeven statusif not onmarket thenbreakeven=0endif//check if the ATR>=39if shortonmarket and ADX[14]>=39 thenbreakeven=1endif//put stoploss at open priceif breakeven=1 thenbuy at tradeprice-1*pointsize stopendif//------// Conditions to exit short positionsignored, indicator3 = CALL "PowerX 2"c6 = (indicator3 > -3)c7 = (close > SMA50)IF c6 OR c7 and (barindex-barorder>=1 and barorder>0) and ONMARKET THENEXITSHORT AT MARKETbarorder=0ENDIF04/23/2019 at 4:51 PM #9700504/23/2019 at 7:45 PM #97015Thanks Nicolas.
However, I don’t just want to close the short position but I only want to adjust the stop loss to breakeven – 3 pip when CONDITION 1 is met and to breakeven – 1 pip when CONDITION 2 is met.
The first part of the code (which contains CONDITION 1) you helped me to create and it works fine in ProBacktest.
123456789101112131415161718192021222324252627//if not order on market, reset the breakeven statusif not onmarket thenbreakeven=0endif// (CONDITION 1)//check if the current order has made 2*ATR of signal dayif shortonmarket and tradeprice-close >=2*ATR thenbreakeven=1endif//put stoploss at open price - 3 pipif breakeven=1 thenbuy at tradeprice-3*pointsize stopendif// Conditions to exit short positionsignored, indicator3 = CALL "PowerX 2"c6 = (indicator3 > -3)c7 = (close > SMA50)IF c6 OR c7 and (barindex-barorder>=1 and barorder>0) and ONMARKET THENEXITSHORT AT MARKETbarorder=0ENDIFI then added the code for CONDITION 2 to it and was hoping it would work. But it now creates a new long position after it closed a trade that met CONDITION 2.
I just want it to adjust the Stop loss.
12345678910111213141516// CONDITION 2//if not order on market, reset the breakeven statusif not onmarket thenbreakeven=0endif//check if the ATR>=39if shortonmarket and ADX[14]>=39 thenbreakeven=1endif//put stoploss at open priceif breakeven=1 thenbuy at tradeprice-1*pointsize stopendif04/23/2019 at 8:07 PM #97020I have to correct myself. I thought that the first part of the code (CONDITION 1) was working, but now when I checked again I realized it is not working.
It produces the same mistake that after closing the short trade when the condition is met, it creates a new long trade.
So I guess the command buy at tradeprice-3*pointsize stop doesn’t work and somehow creates this countertrend trade.
I am confused now. How can I write the code that it changes the Stop Loss to entry price – 3 pips?
Thanks so much for your help.
04/23/2019 at 8:34 PM #97022Problem solved:
I read through everything again and then replaced the BUY instruction with EXITSHORT and now it works.
Somehow I assumed that EXITSHORT would exit the position at market (that was my confusion) but as I use STOP it adjusts the Stop Loss as I wanted.
Thank you again Nicolas.
-
AuthorPosts
Find exclusive trading pro-tools on