fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    Count Positive and Negative Bars

    Questions & Answers
    2
    5
    646
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      holygrailfx last edited by

      What is the easiest method to count the number of bars that ended up positive and negative over the last 25 bars?

      1 Reply Last reply Reply Quote 0
      • fxDreema
        fxDreema last edited by

        Always the best method to do calculations over tha past candles is by using custom indicators, this is what they are supposed to do - claculations. Also, normally indicators does not recalculate things that were already calculated and this is natural to them, but not natural for expert advisors and scripts.

        In the EA this can be done with a regular loop - you start from the first candle, iterate through the old candles and increase some variables within the loop. The easiest will be to code it actually, something like that:

        
        int positive = 0;
        int negative = 0;
        
        for (int i=1; i<=25; i++)
        {
         if (Close* > Open*) {positive++;} else {negative++;}
        }
        
        1 Reply Last reply Reply Quote 0
        • H
          holygrailfx last edited by

          OK thanks

          So I write my source code and stick it in a custom block and have it execute every tick or bar, correct?
          see picture

          But how would I then be able to use the value for negative and positive for further manipulations?

          Sorry but I am still having a hard time creating custom code blocks...and how to connect and use them afterwards

          1 Reply Last reply Reply Quote 0
          • fxDreema
            fxDreema last edited by

            I can't give you beautiful solution for this. "positive" and "negative" can be global Variables and then their "int" will not be needed, but you need to remember that this block also needs those global variables to be defined with their correct names. Again, the best is really to have some indicator, you can search for something or ask someone to make one. This is very easy calculation and I can even say that you can do it on your own. Plus, the indicator does not recalulate things every time and can show something meaningful.

            1 Reply Last reply Reply Quote 0
            • H
              holygrailfx last edited by

              Okay thanks for the reply
              I have been thinking during my holiday and will make an indicator to solve this issue

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post

              Online Users

              J
              G
              S
              Z
              E
              H
              J
              S
              S

              22
              Online

              146.8k
              Users

              22.4k
              Topics

              122.6k
              Posts

              Powered by NodeBB Forums | Contributors