Counting green candles

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #209997 quote
    JenniferStrateg
    Participant
    New

    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 🙂

    #209998 quote
    JC_Bywan
    Moderator
    Master

    Sthg like that…

    myred = Close<Open
    my3green = summation[3](Close>Open)=3
    mysequence = my3green[1] and myred
    
    if longonmarket and mysequence then
      sell at market
    endif
    Midlanddave and KumoNoJuzza thanked this post
    #210005 quote
    JenniferStrateg
    Participant
    New

    Hi 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!!

    #210341 quote
    JenniferStrateg
    Participant
    New

    Hi 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.

    #210351 quote
    JC_Bywan
    Moderator
    Master

    How many reds allowed between 1st and 2nd green, and between 2nd and 3rd green?

    #210355 quote
    JenniferStrateg
    Participant
    New

    As many as it takes. Let’s say 15.

    #210449 quote
    JC_Bywan
    Moderator
    Master

    Ok, 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.

    Nredmax=15
    
    Nsequencemax=Nredmax+4// 3 greens + red at the end + Nredmax in between the 3 greens
    green= close>open
    red= close<open
    
    if not longonmarket  and  yourentryconditions  then // define your entry conditions
      buy 1 contract at market
    endif
    
    if longonmarket and not longonmarket[1] then
      barstart=barindex
    endif
    if summation[2](longonmarket)=2 and green[1] and red then
      bartotal=barindex-barstart+1
      vendre = (bartotal<=Nsequencemax and summation[bartotal](green)>=3) or (bartotal>Nsequencemax and summation[Nsequencemax](green)>=3)
      if vendre then
        sell at market
      endif
    endif
    Midlanddave thanked this post
    #210463 quote
    JenniferStrateg
    Participant
    New

    Thanks for taking the time to do this!

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

Counting green candles


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by JenniferStrateg
2 years, 12 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/20/2023
Status: Active
Attachments: No files
Logo Logo
Loading...