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

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.
    BertrandNinjaTrader Customer Service

    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).
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DawnTreader, 05-08-2024, 05:58 PM
            22 responses
            81 views
            0 likes
            Last Post DawnTreader  
            Started by Mathias79, Today, 03:44 PM
            0 responses
            17 views
            0 likes
            Last Post Mathias79  
            Started by Austiner87, Today, 03:42 PM
            0 responses
            11 views
            0 likes
            Last Post Austiner87  
            Started by lorem, 04-25-2024, 09:18 AM
            19 responses
            83 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by joselube001, 05-10-2024, 12:17 PM
            6 responses
            29 views
            0 likes
            Last Post joselube001  
            Working...
            X