Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 burtoninlondon, Today, 12:38 AM
          0 responses
          5 views
          0 likes
          Last Post burtoninlondon  
          Started by AaronKoRn, Yesterday, 09:49 PM
          0 responses
          12 views
          0 likes
          Last Post AaronKoRn  
          Started by carnitron, Yesterday, 08:42 PM
          0 responses
          11 views
          0 likes
          Last Post carnitron  
          Started by strategist007, Yesterday, 07:51 PM
          0 responses
          13 views
          0 likes
          Last Post strategist007  
          Started by StockTrader88, 03-06-2021, 08:58 AM
          44 responses
          3,982 views
          3 likes
          Last Post jhudas88  
          Working...
          X