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

Variable not changing/keeping default value

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

    Variable not changing/keeping default value

    Hi, I’m using 2 indicators, bollinger bands and a normalized volatility indicator.

    I want the deviation of the bands to changed depending on the value of the NVI.

    To do this, I’ve created a double variable named “bandwidth” with a default value of 1. Then, created a new set:

    NVI<0.2
    set “bandwidth” = 1.3

    and then another set:

    NVI>0.2
    set “bandwidth” = 1.8

    lastly, I set the appropriate parameter within the BBands to the new variable.

    <<< The Issue >>>

    For some reason, the variable stays on the default value of 1 instead of being set to the values as described above.

    In the past, I’ve had no problem doing this with numeric values, so I’m at a loss. Any help would be much appreciated!

    #2
    Hello Akotic,

    Based on the given details it sounds like your conditions are not becoming true. If the default value is used that means the variable is never set when the script is running. I would suggest checking the two conditions that you made which are setting the variable to make sure those are happening.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for the response!

      I have confirmed that those conditions are in fact true hence why I’m confused. Despite the conditions being true, the default value isn’t being changed

      Comment


        #4
        Hello Akotic,

        In this case it would help if you attached the strategy so that we can better understand what overall is being done. From the details you gave the only item that sticks out would be that the two conditions are not true.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,

          Sorry for the delay, below I have attached the simple strategy that illustrates this issue.​

          Comment


            #6
            Hello Akotic,

            I had to remove the file you attached because it contained a compiled assembly. To attach the strategy you would need to attach the source code so that we can see it. When you export it make sure the Compiled option is unchecked so the source is included. https://ninjatrader.com/support/help...tAsSourceFiles
            JesseNinjaTrader Customer Service

            Comment


              #7
              My apologies,

              Attached should be the correct file now
              Attached Files

              Comment


                #8
                It happens to me exactly the same. The value of the variable assigned as period to the stdv of the bollinger bands maintains its default value when the condition on which it depends is activated...

                Comment


                  #9
                  Hello Carlos19,

                  It looks like you are using the variable for the indicators period however that won't work the way that you have done that. In the strategy builder indicator periods can only be set once so what you are trying to do here won't work in the builder. You could manually code the strategy if you wanted to dynamically change the indicators period.

                  The BandWidth variable is being reset by your condition but that is only used in State.DataLoaded, that state only happens one time when the script first starts before OnBarUpdate starts processing the Sets you made. The indicator you used will use the default value always because of that.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hi Jesse,

                    Why didn't you say that in your first response? You said that the only way is that my condition must not be true. I made it clear what parameter was chosen as the variable

                    Comment


                      #11
                      Hello Akotic,

                      As mentioned in post 2, based only on your description it sounds like the conditions were not true, that was just a guess based on what description you gave. In the future if you just upload the code you are using that will help to expedite answers to questions you have for that unique code.

                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        You're saying that the periods of indicators cannot be set as variables that change (are dynamic). My original post made it clear that I was setting an indicator period as a variable.

                        So if this is the case, then what parameters in the strategy builder can be set as dynamic variables if indicator parameters can't?

                        Comment


                          #13
                          Hello Akotic,

                          Unfortunately that detail was not clear when I read your original post, without seeing the code that was not clear. As you are working on a script its details may be exactly clear to you because you made it, from an external standpoint it would not be clear without actually seeing the code.

                          Indicators cannot be used dynamically in the builder you would have to manually code it so that you can create new instances of indicators from OnBarUpdate instead of OnStateChange. You would just call the indicator from OnBarUpdate and supply the variable you used, here is an example of the code to use from OnBarUpdate for an indicator: https://ninjatrader.com/support/help...tsub=bollinger
                          JesseNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by birdog, Today, 06:56 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post birdog
                          by birdog
                           
                          Started by TallTim, Yesterday, 06:13 AM
                          3 responses
                          48 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by Entwaze, Today, 06:41 AM
                          0 responses
                          10 views
                          0 likes
                          Last Post Entwaze
                          by Entwaze
                           
                          Started by waltFX, Today, 06:09 AM
                          0 responses
                          13 views
                          0 likes
                          Last Post waltFX
                          by waltFX
                           
                          Started by caacapital, Today, 05:34 AM
                          0 responses
                          21 views
                          0 likes
                          Last Post caacapital  
                          Working...
                          X