• 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

Plotting the difference between two Conditions met over time

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

    Plotting the difference between two Conditions met over time

    Hello,

    Can someone help me to find a way to creat a script that can:

    Plot the value of the difference between

    1) a Condition met and 2) the last time that Condition was also met in the past?

    Here is a very simplistic example of what I would like to do.

    Condition set

    If Close [0] < Open [0]
    && Close [1] > Open[1]
    && Close [2] > Open[2]

    Then

    Plot the value of the difference between

    Close[0]

    And

    Close[i]

    ... Where Close[i] is

    The Value of the Close when that same condition was met last in the past. One or even several Bars Ago.

    Close [i] < Open [i]
    && Close [i1] > Open[i1]
    && Close [i2] > Open[i2]


    Thanks in advance

    H

    #2
    Hi HJSInvesting,

    Thank you for your post.

    You would want to use a FOR loop to run this calculation.

    [CODE]
    for ( int i = 0; i < CurrentBar; i++)
    {

    if(my condition statement)
    {
    //do something here...
    //after your actions are done break the loop to stop it
    break;
    }
    }
    [CODE]
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by HJSInvesting View Post
      Hello,

      Can someone help me to find a way to creat a script that can:

      Plot the value of the difference between

      1) a Condition met and 2) the last time that Condition was also met in the past?

      Here is a very simplistic example of what I would like to do.

      Condition set

      If Close [0] < Open [0]
      && Close [1] > Open[1]
      && Close [2] > Open[2]

      Then

      Plot the value of the difference between

      Close[0]

      And

      Close[i]

      ... Where Close[i] is

      The Value of the Close when that same condition was met last in the past. One or even several Bars Ago.

      Close [i] < Open [i]
      && Close [i1] > Open[i1]
      && Close [i2] > Open[i2]


      Thanks in advance

      H
      Two efficient ways I can think of offhand. There are other less efficient methods that I can think of.
      1. You can use MRO().
      2. You can use 2 tracking variables, and update the first one every time you get the condition, and after you make the calculation.

      Comment


        #4
        Thank you K,

        I see how MRO() could help. I was reviewing the Syntax and I will try a few things with it.

        Having said that, I see the first challenge. Under Condition, how could I enter three Conditions in the Syntax?

        Following my original example:

        If Close [0] < Open [0]
        && Close [1] > Open[1]
        && Close [2] > Open[2]

        These three conditions should be evaluated as "True" within the MRO() to get the desired Outcome ...

        Would this be valid? ... = MRO(delegate {return Close[0] < Open[0] && Close [1] > Open[1] && Close [2] > Open[2];}, 1, 20)

        Thanks again in advance

        Comment


          #5
          Originally posted by HJSInvesting View Post
          Thank you K,

          I see how MRO() could help. I was reviewing the Syntax and I will try a few things with it.

          Having said that, I see the first challenge. Under Condition, how could I enter three Conditions in the Syntax?

          Following my original example:

          If Close [0] < Open [0]
          && Close [1] > Open[1]
          && Close [2] > Open[2]

          These three conditions should be evaluated as "True" within the MRO() to get the desired Outcome ...

          Would this be valid? ... = MRO(delegate {return Close[0] < Open[0] && Close [1] > Open[1] && Close [2] > Open[2];}, 1, 20)

          Thanks again in advance
          That looks correct, though for readability, I would evaluate the condition as a separate line, then use it. I may even use a private property to evaluate it.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by dshalom9, Today, 08:36 AM
          9 responses
          13 views
          0 likes
          Last Post NinjaTrader_PatrickG  
          Started by stock_wizard_49, 07-11-2020, 06:57 PM
          1 response
          16 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by asmmbillah, Yesterday, 03:03 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by AspenHiker, Today, 08:37 AM
          0 responses
          7 views
          0 likes
          Last Post AspenHiker  
          Started by StarTrader, 07-11-2020, 11:27 AM
          2 responses
          19 views
          0 likes
          Last Post StarTrader  
          Working...
          X