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

Getting a Strategy to Not Trade Again Until Price Has Touched EMA

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

    Getting a Strategy to Not Trade Again Until Price Has Touched EMA

    Hi I am new to developing strategies on the platform and can't figure out how to get my system to not take another trade until price has fallen back to the EMA. Using the Wait X Bars Since Execution function is okay but is not the sharp tool I'm looking for.

    So for example my system fades an upward move. I would like it to not trade again until price has fallen back down and touched a simple EMA. It needs to be some function that says if system has traded, wait until price touches EMA to be open to trade again.

    Any help is appreciated, thanks!

    #2
    Hello prescottbph,

    Thanks for your post and welcome to the NinjaTrader forums!

    Ninjascript provides a number of methods and properties but the underlying code is C# so you are able to take full advantage of a programming language to code as needed.

    It sounds like you want to create and use a bool variable, one that you initialize as true and is part of your conditions to enter the order. Once the order is placed you set it to false to prevent further orders until the "reset" condition has occurred (IE: "not trade again until price has fallen back down and touched a simple EMA.")

    In the region variable you would declare the variable (any name you wish)
    private bool myBool = true; // initialize as true

    In the OnBarUpdate() section:

    if (Your conditions to enter && myBool)
    {
    // enter order
    myBool = false; // prevent re-order until reset
    }

    if (Low[0] >= EMA(10)[0])
    {
    myBool = true; // reset for next order
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply Paul! Is there anyway for me to add that bool through the strategy builder wizard? I'm not great with the NinjaScript editor and can't seem to figure out how to place that inside the actual code. Thanks again for your help!

      Comment


        #4
        Hello prescottbph,

        Thanks for your reply.

        Yes, please see the helpguide here on the section of the strategy builders "Understanding inputs and variables screen": http://ninjatrader.com/support/helpG...er_screens.htm
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello prescottbph,

          I have to correct myself, I forgot that you are using (or posting) in NinjaTrader 7 which would be the strategy wizard and not the builder, so my link in the previous post is not correct for you.

          In the NT7 strategy wizard you are a bit limited to 10 variables that you can use, they are named Variable0 through Variable9 and they can be set as needed. To use as a bool you can use a value of 1 for true and 0 for false. These are found in the "user variables folder. So in the previous example provided you would (for the "action") set the Variable to 1 or 0 and for the condition check that the variable is 1 or 0.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            So using the wizard, after I set myBool in the variables field, how do I tell it to not reset until bool is true?

            I'm guessing I set one of the trade conditions to equal myBool = True

            But then how do I set up my Bool to be working and deciding all the time whether to reset to true or false based on the EMA? Thanks and sorry I can't seem to figure it out its been driving me crazy, thanks

            Comment


              #7
              Hello prescottbph,

              Thanks for your reply.

              I've created a short video to demonstrate the use of Variable0 (found in "User Variables") as a bool type operation. https://Paul-ninjaTrader.tinytake.co...k0MV82MTAzNzgz
              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by CortexZenUSA, Today, 12:53 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by CortexZenUSA, Today, 12:46 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by usazencortex, Today, 12:43 AM
              0 responses
              5 views
              0 likes
              Last Post usazencortex  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              168 responses
              2,266 views
              0 likes
              Last Post sidlercom80  
              Started by Barry Milan, Yesterday, 10:35 PM
              3 responses
              13 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X