Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Remember A Value

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

    Remember A Value

    Hello,

    I would like to remember the High value of a bar once the condition is met, and then forget that value once a counter condition is met.
    Is there a way to remember price values in the script language?

    Example:

    if (Condition is met)
    {
    stored value = High[1]
    }

    if (GetCurrentAsk(0) == stored value)
    {
    EnterLong()
    }

    if (Counter condition is met)
    {
    forget stored value
    }


    I'm looking forward to any replies and thank you for your time.

    #2
    Hello otislauwaert,

    Thanks for your post.

    In the Strategy Wizard, you can assign values to User Variables. (Misc > User Variables > Variable0) These variable can be assigned a value in a Condition Set under actions and can be recent in another Condition Set for when you want to reset this value. You may then click View code to see the generated NinjaScript syntax.

    Publicly available information on using User Defined Inputs and User Variables in the Strategy Wizard can be found here - https://ninjatrader.com/support/help...on_builder.htm

    You can also create your own class level variables to store information. There are some basic programming concepts detailed in our NinjaTrader 7 help guide and I will provide a link below. If you are looking for more robust educational C# materials I would recommend looking at resources external to NinjaTrader.

    Basic Programming concepts - https://ninjatrader.com/support/help...sic_syntax.htm

    Please let us know if we can be of further assistance.
    Last edited by NinjaTrader_Jim; 11-28-2018, 08:42 AM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you Jim. The documentation you have provided has been very helpful.

      Comment


        #4
        Hello Jim,

        I am running two identical strategies that remember a High/Low value and save it as a double (as discussed earlier on in the thread).
        When one of the strategies remembers a value on ES called SavedExitBar1 ... will the other strategy running on NQ overwrite the SavedExitBar1 on the first strategy that is running on ES?
        Since they are two identical strategies saving values under the same names.

        Comment


          #5
          Hello otislauwaert,

          Strategy variables will belong to that instance of a strategy. If you have two instances of a strategy enabled, they will have separate variables and will not have knowledge of the other instance's variables.

          Let us know if you have any additional questions.
          JimNinjaTrader Customer Service

          Comment


            #6
            Hello Jim,

            I'm using the DrawText() in my script and it places the draw objects correctly, but each time it places a new draw object it removes the old ones.
            How can I prevent it from removing the old draw objects so that they all stay on the chart?


            Comment


              #7
              Hello otislauwaert,

              Using the same tag will update that drawing object. If you want to create unique drawing objects, unique tags must be used. Adding CurrentBar to the tag can make unique drawing objects. This can't be done in the Strategy Wizard and would require unlocking the code.

              If you would like to learn more about how you can copy a Strategy Wizard strategy so you can make your own code edits to the copy, I recommend watching the NinjaScript Editor 401 tutorial.

              NinjaScript Editor 401 - https://www.youtube.com/watch?v=K8v_2ONBbqI

              We look forward to being of further assistance.
              Last edited by NinjaTrader_Jim; 11-28-2018, 11:38 AM.
              JimNinjaTrader Customer Service

              Comment


                #8
                Hello Jim,

                The string creator does not exist in Ninjatrader 7.
                I want to achieve that my one line of code ( DrawText("1", "1", 0, GetCurrentAsk(0) + 7 * TickSize, Color.Red); ) is creating a unique tag for every time it is called.

                Comment


                  #9
                  Hello otislauwaert,

                  You may have read the post before I edited it to include resources relevant for NinjaTrader 7. You can create an unlocked copy of the strategy and then add +CurrentBar to the DrawText line.

                  For example: DrawText("1"+CurrentBar.ToString(), "1", 0, GetCurrentAsk(0) + 7 * TickSize, Color.Red);

                  Let us know if there is anything else we can do to help.
                  JimNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by wjadevries, Today, 03:35 PM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Started by Mykro, Today, 03:59 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Mykro
                  by Mykro
                   
                  Started by venkateshdvk, Today, 01:34 PM
                  1 response
                  21 views
                  0 likes
                  Last Post NinjaTrader_Kate  
                  Started by westofpluto, Today, 01:54 PM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by zacharydw00, Today, 02:11 PM
                  4 responses
                  15 views
                  0 likes
                  Last Post zacharydw00  
                  Working...
                  X