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

Enter on moving average touch or second cross if other conditions are true

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

    Enter on moving average touch or second cross if other conditions are true

    I am looking to find a way to expand my current code that I have to add some extra variables to test

    Goal 1: Have a variety of bullish conditions that would be true and then they would stay true until the moving average crossed the other direction. Essentially, I would then want to enter a trade in that same direction as the original signal. Let's say I have fast length ma cross above slow length; I would not want to enter here. I would want to wait for the price or the fast length moving average to get very close to the slow length but not close below it. I would want to hope for a touch and bounce during the candle and close away from the slow length moving average. Then I would enter here and could close with any basic settings I already have in my system.

    Goal 2: For simplicity purposes I will use this logic. If I am ignoring the first cross of a bullish ma cross but hoping for a second bullish ma cross before the macd crosses below zero or is leading the macd average (so diff is still positive). I would then enter long. I essentially am hoping for a failed cross but betting on the next one to be better if the macd didn't cross below. If the macd did happen to cross below it would reset the logic and then look to do the same for a short trade. Not sure how difficult this could be for actual coding purposes.

    Any ideas or resources of how to achieve this would be appreciated.

    #2
    Hello durdcash,

    Thanks for your post.

    We are looking into your inquiry at this time and will reach back out to you as soon as we have investigated this matter.

    Thanks for your patience; I look forward to assisting further.​
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi durdcash, thanks for your questions.

      Q1. You will need to use C# booleans to act as "flags" for a later time. E.g. create a boolean variable at the class level, set this boolean to true once a condition becomes true, then return or continue running OnBarUpdate. In later OnBarUpdate calls, check if this boolean flag is true or false to trigger other IF statement conditions.

      private bool MyFlag;

      OnBarUpdate:

      if(MyFlag && <second required conditions>)
      {
      //MyFlag is true on a later OnBarUpdate call.
      }

      if(!MyFlag && <first required conditions>)//MyFlag is false
      {
      MyFlag = true;
      }

      Q2: This is still going to require C# boolean logic to be used to control the flow of your program. Please test out booleans and use Print() to track the frequency/timestamp of OnBarUpdate and the value of your boolean flags to determine a signal. I linked one example made in the strategy builder that sets a condition trigger for a later time:

      Hi, To improve a strategy, I would like the condition to enter a trade to be triggered only after a second crossing happens. Meaning, for instance we have a sthocastics crossing, but the strategy would only trigger when a crossing between 2 emas happen. Would the looking back N bars work? Can it be done within the builder
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        Thanks! I will work on creating the variables and see if I am able to make it work with my other pieces of code.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by AaronKoRn, Today, 09:49 PM
        0 responses
        6 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Today, 08:42 PM
        0 responses
        9 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Today, 07:51 PM
        0 responses
        10 views
        0 likes
        Last Post strategist007  
        Started by StockTrader88, 03-06-2021, 08:58 AM
        44 responses
        3,976 views
        3 likes
        Last Post jhudas88  
        Started by rbeckmann05, Today, 06:48 PM
        0 responses
        9 views
        0 likes
        Last Post rbeckmann05  
        Working...
        X