Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      574 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      332 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      553 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X