• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to figure out how many times is one bar greater than another bar

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to figure out how many times is one bar greater than another bar

    Dear Team,
    Currently to compare the long of two bars,I only know to use open 0 - close 0 greater or less than open1 - close1.

    But what should I do,if I want to know exactly how many times is one bar greater or less than another in strategy builder?

    Please give me an example!

    Best regards!

    #2
    Hello williamzz,

    Thanks for your post.

    While we typically do not provide complete strategies, I thought the community would benefit from a complete example that demonstrates a counter in the strategy builder. I've created an example strategy you can download install test and reference for your own work. Math in general in the strategy builder is not easily done.

    I will describe in general details what happens.

    There is a custom series called myCounter of the Int type. A series will add an place holder for each bar and this is how we can keep a running counter on a bar by bar basis.
    There is a variable called Constant that is also an integer type and it is set to a value of 1 and used as a constant value.

    In the first set, on the first bar (bar 0), the series myCounter is set to the value of 0 (zero) (to provide a known value to start with).
    in the 2nd set, there are no conditions and in the action section, the previous bar value of the myCounter series is set into the current bar value of myCounter, this is how we keep the count moving forward.
    In the 3rd set I have a condition set of EMA 30 crossing above SMA 70. when that condition is true, the current value of MyCounter will be set to the previous bar value of myCounter plus the variable Constant (which is always 1). I also added a draw.TextFixed on the chart so you can see the count value.
    In the 4th set I have no conditions and have a print statement that will print on every bar the values of time/date, the current value of myCounter and the current bar count. This is diagnostic only but is good debugging example for you.

    Apply the strategy to a chart of 1 minute bars and when enabled it will show the number of cross above conditions encountered.

    The strategy will only work when it is run with Calculate.OnBarClose.

    Here are the general directions for downloading an installing a script:

    To import NinjaScripts you will need the original .zip file.

    To Import
    1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
    2. From the Control Center window select the menu Tools>Import>Ninjascript add-on..
    3. Select the downloaded .zip file
    4. NinjaTrader will then confirm if the import has been successful.

    Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

    here is the strategy builder strategy:

    StrategyBuilderCounterExample.zip
    Attached Files
    Last edited by NinjaTrader_PaulH; 08-29-2019, 02:28 PM.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you so much for your reply!

      So let me keep my question simple:

      How to express (close0-open0)/(high1-low1) in strategy builder?
      Last edited by williamzz; 09-03-2019, 12:25 PM. Reason: make it more clear

      Comment


        #4
        Hello williamzz,

        Thanks for your reply.

        You didn't mention what you were doing with that value, but for this you can create two (double type) data series. one to hold the Close[0] - Open[0] and the other to hold the High[1] - Low[1] and then finally use a single double variable to hold the results of the one data series divided by the other data series. Here is a screenshot of what that looks like, where:
        CloseOpen is the data series that will hold the results of Close[0] - Open[0]
        HighLow is the data series that will hold High[1] - Low[1]
        Diff is the double type that will hold the division result from CloseOpen / HighLow.


        Click image for larger version

Name:	williamzz-1.PNG
Views:	78
Size:	9.9 KB
ID:	1069634
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          This is really helpful!!!Best regards!

          Comment


            #6
            Hi,
            Can you let me know,where to create the two (double type) data serie,in 'additional data' or 'inputs' or "variable "?

            When I tried to create them in 'additional data',but after that I can't find them in 'conditions and actions'.

            When I tried to create them as inputs or variable.I have no idea how to express Diff=( CloseOpen / HighLow) in strategy builder,I can finish the first two steps in your example,but can't find how to express Diff=( CloseOpen / HighLow) in strategy builde.

            when I chose diff in uer input in the left,and then I chose equal in the middle ,but I can only chose CloseOpen[0] or HighLow[0] as a inputs or variable in the right,I can't find any operator with them.

            Can you please let me know how you make Diff=( CloseOpen / HighLow) in strategy builder?

            Please just let me know where to create CloseOpen and HighLow,and where to create Diff,and how to make Diff=( CloseOpen / HighLow).


            Thank you so much!
            Last edited by williamzz; 09-07-2019, 01:31 PM.

            Comment


              #7
              Hello williamzz,

              Thanks for your post.

              I've created a short video on creating the custom series and locating it in the condition and actions section

              https://Paul-ninjaTrader.tinytake.co...Ml8xMTQzNzc5MQ

              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Benjaminf, Today, 02:21 PM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Kate  
              Started by grayfrog, 05-24-2020, 09:29 PM
              5 responses
              31 views
              0 likes
              Last Post NinjaTrader_RyanS  
              Started by chrismcdermut, Today, 01:46 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Kate  
              Started by dpolyakov, Today, 01:13 PM
              3 responses
              14 views
              0 likes
              Last Post dpolyakov  
              Started by tjendra, Today, 12:15 PM
              3 responses
              9 views
              0 likes
              Last Post tjendra
              by tjendra
               
              Working...
              X