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 benmarkal, Yesterday, 12:52 PM
      3 responses
      23 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by helpwanted, Today, 03:06 AM
      1 response
      19 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      11 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      244 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      388 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X