Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

reset values when study indicator changes

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

    reset values when study indicator changes

    programing a strategy using a custom study that trades 24 hours/day, I need to reset values when a study is updated.

    protected override void OnBarUpdate()
    If I add the reset value, it will only reset the value once in this section.

    I am able to reset values when orders are executed by using this:
    protected override void OnExecution(IExecution execution)

    How can I have variables reset when my study changes values?

    #2
    Hi oldseller1848, unfortunately there's no readymade method for 'when a study changes' - I believe you could check if the calculated values now if different from the last calculated one and then you could reset variables as needed.

    Comment


      #3
      Can you post an example of code I can try to use?

      Comment


        #4
        You just need to check your study's value and determine if it has changed or not from its previous state.

        [1] indexes usually mean previous bar's value. [0] means current bar's value. If [1] != [0] then something has changed.

        Code:
        if (SMA(20)[1] != SMA(20)[0])
        {
             // Do something;
        }
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I need the values to reset immediately after the Study values change. After the values are reset, I need to have this strategy ready to put on more trades if the strategy changes the goShort = True later in the code. This code adjusts the value only once, then it appears not to execute. Is there a different execution method I should use?

          Code:
           protected override void OnBarUpdate()
                  {
                      // Reset Data
                      if (fibJPYv5.GoShort[0] != goShortLast1)
                      {
                          goShortLast1 = fibJPYv5.GoShort[0];
                          goShort = false;
                          goShort1 = false;
                          goShort2 = false;
                      }
                     // GoShort
                     if(goShort == true && fibJPYv5.GoShort[0] <= GetCurrentBid())
                     {
                          //Do more work
                     }
                  }
          This isn't the entire code... I have 3 levels to go short at, depending where the price is with my signal.
          Last edited by oldseller1848; 11-06-2009, 06:18 AM.

          Comment


            #6
            You could do this with the code sample Josh provided, just be sure to let the strategy run to update on each tick (CalculateOnBarClose = false).

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            573 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            576 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X