Channel breakout system can't move stoploss level
Forums › ProRealTime English forum › ProOrder support › Channel breakout system can't move stoploss level
- This topic has 5 replies, 2 voices, and was last updated 7 years ago by
TraderC.
-
-
04/20/2017 at 9:56 AM #32699
I have a problem with my code.
My code is a channel breakout system with pyramiding.
My channel breakout system for the short side is:
When the price breaks through 20-day low, I sellshort 1 position. (Pos #1).
My stoploss is the low of the previous day (SL #1).
My rules for pyramiding (Position #2, #3, etc.) are :
Condition: The 20-day low has to be flat or rising for at least five days.
As soon as I enter the second position (breakout of 20-day low) (Pos. #2), the stoploss of Pos #2 is the high of the previous day. I also move the stoploss of the first position (SL #1) to the high of one day before my second position entry day =previous day. (SL #1 à SL #2).
Now I have 2 positions (Pos. #1, Pos.#2) with the same stoploss (SL #2).
I have two more rules to filter out false breakouts after pyramiding.
Rule1: On the breakout day (=first day) the close must be lower than 20-day low of the day before the breakout day.
Rule2: One day after the breakout day (=second day) the close also must be lower than the 20-low of the day before the breakout day.
If rule1 OR rule2 are broken I exit all positions at the close of the day.
This prevents false breakout signals.
If first day and second day both close lower, then I’ll let the positions run until
- There is another condition for pyramiding.
OR - The market reverses and my stoploss (SL #2) is hit.
OR - The 20-day high becomes lower than my (previous day low)stoploss (20-day high < SL #2)- in which case I adjust my stoploss to the 20-day high (SL #2 change toà 20-day high) and it is hit.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104period=20L20=lowest[period](low)fivel20 = L20>=L20[1] and L20>=L20[2] and L20>=L20[3] and L20>=L20[4]H20=highest[20](high)If countOfposition>0 thenfirststop=newstopEndif// no positionIf not shortonmarket thensellshort 1 shares at L20 stopfirststop= high[0]if shortonmarket thenexitshort at firststop stopendifelseif shortonmarket and close > tradeprice and Barindex-Tradeindex=0 thenexitshort at marketelseif shortonmarket and close > tradeprice and Barindex-Tradeindex=1 thenexitshort at marketelseif firststop-newstop>0 thenexitshort at firststop stop //Here is a problem //EndifEndifendifendif//when you have at least one positionnewstop = high[0]If shortonmarket thenexitshort at firststop stopendifIf shortonmarket and fivel20 thensellshort 1 shares at L20 stopnewstop=high[0]exitshort at min(newstop,H20) stop //there is a problemif high[0] - H20 < 0 and countofposition >= 1 thennewstop= high[0]Endif//exitshort at new stop //if shortonmarket and close > tradeprice and Barindex-Tradeindex=0 thenexitshort at marketelseif shortonmarket and close > tradeprice and Barindex-Tradeindex=1 thenexitshort at marketelseif shortonmarket then //must add conditionexitshort at min(high[0],H20) stopendifEndifEndifendifHere is my code.
It’s not working as my rules.
I can’t move my stoploss level lower.
Please help me to fix my code.
Thank you very much.
05/01/2017 at 9:40 AM #3410705/01/2017 at 3:17 PM #3416505/01/2017 at 6:44 PM #34194Thank you Nicolas.
I hope it is better now. 🙂
I really look forward to your answer.
I already struggle for a long with this code. Puuhhh
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859period=20L20=lowest[period](low)fivel20 = L20>=L20[1] and L20>=L20[2] and L20>=L20[3] and L20>=L20[4]H20=highest[20](high)If countOfposition>0 thenfirststop=newstopEndif// no positionIf not shortonmarket thensellshort 1 shares at L20 stopfirststop= high[0]if shortonmarket thenexitshort at firststop stopendifelseif shortonmarket and close > tradeprice and Barindex-Tradeindex=0 thenexitshort at marketelseif shortonmarket and close > tradeprice and Barindex-Tradeindex=1 thenexitshort at marketelseif firststop-newstop>0 thenexitshort at firststop stop //Here is a problem //EndifEndifendifendif//when you have at least one positionnewstop = high[0]If shortonmarket thenexitshort at firststop stopendifIf shortonmarket and fivel20 thensellshort 1 shares at L20 stopnewstop=high[0]exitshort at min(newstop,H20) stop //there is a problemif high[0] - H20 < 0 and countofposition >= 1 thennewstop= high[0]Endif//exitshort at new stop //if shortonmarket and close > tradeprice and Barindex-Tradeindex=0 thenexitshort at marketelseif shortonmarket and close > tradeprice and Barindex-Tradeindex=1 thenexitshort at marketelseif shortonmarket then //must add conditionexitshort at min(high[0],H20) stopendifEndifEndifendif05/04/2017 at 3:50 PM #34542Thanks, I don’t understand the pyramiding function with “Condition: The 20-day low has to be flat or rising for at least five days.”. So you are adding more sellshort orders if the price is rising above the first order? But in this case the first stoploss should have already been triggered? I think I should recode the whole thing to get a better comprehension of the strategy 🙂 Could you please add some screenshots of how the strategy should operate on a price chart please? Thanks in advance.
05/05/2017 at 4:58 PM #34646Thank you, Nicolas!
I try to explain clearer. This is short-side pyramidding system.
My first SL#1 is HIGH of previous bar (sorry – I wrote “low” in my desciption above).
When the 20-day low channel broken to downside, I sellshort 1 position, and my SL is HIGH of last day (=previous day).
I sellshort 2nd position if (20-day channel is flat or rising for at least 5 days (5-day Cond.)) AND (price breaks 20-day channel to DOWNSIDE).
The SL for 2nd position is High of previous bar. I also want to automatically move the SL of 1st position to the 2nd pos. SL. (This is my main issue…)
When the 20-day High channel become < SL#1, I want to switch SL#1 to follow 20-day High channel. Until enter 2nd pos., then move SL to SL#2.
Very Sorry.!!.. My explanation was not clear for you!!I wait eveyr day for Nicolas brilliant code!! 🙂 Thank you! Thank you!!
I make screenshot with all detail below. I hope you understand. - There is another condition for pyramiding.
-
AuthorPosts