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

Tagging a crossover

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

    Tagging a crossover

    Hello
    I'm attempting to set a bool flag on an instance of a crossover. Here is the code:
    if (CrossAbove(DinapoliStochastic(6, 6, 14).LineK, DinapoliStochastic(6, 6, 14).LineD, 10)
    && DinapoliStochastic(6, 6, 14).LineD[0] > 20
    && DinapoliStochastic(6, 6, 14).LineD[0] < 50)
    {
    DrawSquare("DSLong" + CurrentBar, true, 0, High[0] + 2, Color.DarkGoldenrod);
    DSMiddleLong = true;
    What I'm finding is the Dot/Flag is getting set not just on the crossover instance, but all the time the LineK > LineD. So the crossover may have occurred < 20 or > 50 but if the lines pass above 20 or below 50 I'll still get the dot and my flag is setting at times that I don't want it. Any suggestions on how I could just get the moment of the crossover and not the continuation?
    Thanks

    #2
    Hello CaptainAmericaXX,

    Your crossover lookback is set to 10, so it checks for crossovers anytime within the last 10 bars. This is likely the main reason why you are seeing it trigger on non-crossover bars.

    The flag is set one way until you change it. If you want to reset it when the condition is false, add the following lines immediately after that code block.
    else
    DSMiddleLong = false;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ah, yes. Stupid mistake. Thanks again Ryan.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Barry Milan, Yesterday, 10:35 PM
      5 responses
      18 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by DanielSanMartin, Yesterday, 02:37 PM
      2 responses
      13 views
      0 likes
      Last Post DanielSanMartin  
      Started by DJ888, 04-16-2024, 06:09 PM
      4 responses
      13 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by terofs, Today, 04:18 PM
      0 responses
      12 views
      0 likes
      Last Post terofs
      by terofs
       
      Started by nandhumca, Today, 03:41 PM
      0 responses
      8 views
      0 likes
      Last Post nandhumca  
      Working...
      X