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 PaulMohn, Today, 03:49 AM
          0 responses
          2 views
          0 likes
          Last Post PaulMohn  
          Started by inanazsocial, Today, 01:15 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by rocketman7, Today, 02:12 AM
          0 responses
          10 views
          0 likes
          Last Post rocketman7  
          Started by dustydbayer, Today, 01:59 AM
          0 responses
          2 views
          0 likes
          Last Post dustydbayer  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          5 responses
          23 views
          0 likes
          Last Post trilliantrader  
          Working...
          X