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

Value Constant When Condition Met

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

    Value Constant When Condition Met

    Hi, I'm trying to build an indicator that captures the value of an indicator when certain condition is met, and keep that Value until the condition is again met.
    I tried to find an expression for that but could not find it.

    To make it clear, let's use again the example of the Range indicator.

    I want to plot a straight Line if Range is greater than 100 . This line would be in the same indicator panel as the Range indicator at the Value of the Range that is > 100. So if the Range is 120 , it would show a line with the 120 value. If the next bar the Range is less than 100 it would still plot 120. If instead, the next bar Range is 110, it would Plot a Line at the 110 Value.

    So I need to capture that Value When my condition is met and have it constant for the next bars until My condition is again met.

    I attached the piture of the indicator in my other platform explaining it better

    I read in the forum something about Creating a new DataSeries. Tried some code, but no success.
    Can someone show me the way? Please

    Thanks Again
    Attached Files
    Last edited by marreta; 10-16-2014, 07:24 PM.

    #2
    Originally posted by marreta View Post
    Hi, I'm trying to build an indicator that captures the value of an indicator when certain condition is met, and keep that Value until the condition is again met.
    I tried to find an expression for that but could not find it.

    To make it clear, let's use again the example of the Range indicator.

    I want to plot a straight Line if Range is greater than 100 . This line would be in the same indicator panel as the Range indicator at the Value of the Range that is > 100. So if the Range is 120 , it would show a line with the 120 value and it would be ploted in the next bar if the next bar Range is less than 100. Instead if the next bar The Range is now 110 it would Plot a Line at the 110 Value.


    So I need to capture that Value When my condition is met and have it constant for the next bars until My condition is again met.
    I read in the forum something about Creating a new DataSeries. Tried some code, but no success.

    Can someone show me the way?

    I attached the piture of the indicator explaining it better

    Thanks Again
    Post the code that you have so far in your OnBarUpdate() handler, so that someone can correct it for you.

    Comment


      #3
      marreta, I agree with koganam, would be helpful to see what you already did in your code.

      To keep track if a value you could just store in a variable, it would update as your condition is retriggered. Consider for example this simple snippet idea -

      Code:
      if (Range()[0] > 100)
      	rangeStore = Range()[0];
      						
      Plot0.Set(rangeStore);
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Hi Guys, sorry for not posting the code.

        Ok Bertrand, I tried your suggestion and got an error message, below is the picture of the code attached Picture 3

        Then I tried a little different, it works but not the way I want, It only plots bars when Range >0, but when Range < 100 it doesn't plot anything. I want to have the last Value that was > 100 to be plotted even if Range was < 100.
        Atached pic 4 of the code

        and pic 5 is the chart showing that code , and in Blue I Draw what I need to accomplish.

        Thanks
        Attached Files
        Last edited by marreta; 10-17-2014, 06:56 PM.

        Comment


          #5
          Originally posted by marreta View Post
          Hi Guys, sorry for not posting the code.

          Ok Bertrand, I tried your suggestion and got an error message, below is the picture of the code attached Picture 3

          Then I tried a little different, it works but not the way I want, It only plots bars when Range >0, but when Range < 100 it doesn't plot anything. I want to have the last Value that was > 100 to be plotted even if Range was < 100.
          Atached pic 4 of the code

          and pic 5 is the chart showing that code , and in Blue I Draw what I need to accomplish.

          Thanks
          From what code, you have shown, if there is no other code, I would expect to see some other errors.

          However, the code that you are looking for for your OnBarUpdate() is:
          Code:
           
           if  (CurrentBar < 1) return;
           if (Range()[0] > 100) Value.Set(Range()[0])
           else Value.Set(Value[1]);

          Comment


            #6
            Hi kogana, I'm sorry about the code, I made a mistake when posting it, I will pay more attention next time, And post the cs files for better analysis.

            Thank you very much for your help, that was what I was looking for.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by carnitron, Today, 08:42 PM
            0 responses
            6 views
            0 likes
            Last Post carnitron  
            Started by strategist007, Today, 07:51 PM
            0 responses
            8 views
            0 likes
            Last Post strategist007  
            Started by StockTrader88, 03-06-2021, 08:58 AM
            44 responses
            3,974 views
            3 likes
            Last Post jhudas88  
            Started by rbeckmann05, Today, 06:48 PM
            0 responses
            9 views
            0 likes
            Last Post rbeckmann05  
            Started by rhyminkevin, Today, 04:58 PM
            4 responses
            58 views
            0 likes
            Last Post dp8282
            by dp8282
             
            Working...
            X