Counting green candles
Forums › ProRealTime English forum › ProOrder support › Counting green candles
- This topic has 7 replies, 2 voices, and was last updated 1 year ago by JenniferStrateg.
-
-
02/20/2023 at 8:03 PM #209997
I am trying to code a backtest of a strategy, where I need to count the green candles to get my exit signal. Exit is on close of the first red candle after 3 green candles. Any ideas as to how I code that? I only have part of an idea – something with fractions and true or false. But even if that works – which it doesn’t right now – I still haven’t solved the exit on the red candle. Hope to hear your ideas. Half solutions or quater solutions are more than welcome!
Thank you and hope you write some great stuff today 🙂
02/20/2023 at 8:18 PM #209998Sthg like that…
1234567myred = Close<Openmy3green = summation[3](Close>Open)=3mysequence = my3green[1] and myredif longonmarket and mysequence thensell at marketendif2 users thanked author for this post.
02/20/2023 at 9:49 PM #210005Hi JC
Thank you! That is so cool. Had no clue the summation could be used like that. And of course the red is as simple as that.
Thank you!!
02/23/2023 at 10:01 PM #210341Hi again
I’ve tested it on several instruments and I think it comes back with an exit after 3 green bars and one red in a row. Do you have any ideas for 3 green bars mixed with red bars (and then one red after that). There can be red bars mixed in between the 3 green ones.
All the best.
02/24/2023 at 8:15 AM #21035102/24/2023 at 9:36 AM #210355As many as it takes. Let’s say 15.
02/24/2023 at 8:47 PM #210449Ok, I’ve made the 15 a parameter Nredmax you can change if you want to. You just have to define your entry conditions before trying it. To be tested.
1234567891011121314151617181920Nredmax=15Nsequencemax=Nredmax+4// 3 greens + red at the end + Nredmax in between the 3 greensgreen= close>openred= close<openif not longonmarket and yourentryconditions then // define your entry conditionsbuy 1 contract at marketendifif longonmarket and not longonmarket[1] thenbarstart=barindexendifif summation[2](longonmarket)=2 and green[1] and red thenbartotal=barindex-barstart+1vendre = (bartotal<=Nsequencemax and summation[bartotal](green)>=3) or (bartotal>Nsequencemax and summation[Nsequencemax](green)>=3)if vendre thensell at marketendifendif1 user thanked author for this post.
02/25/2023 at 10:44 AM #210463Thanks for taking the time to do this!
-
AuthorPosts
Find exclusive trading pro-tools on