Announcement

Collapse
No announcement yet.

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.​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    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

      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 NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        55 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        132 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X