Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to ignore first signal

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

    how to ignore first signal

    Hi,

    I am trying to achieve sth like this:

    When position is Long - ignore first crossbelow of two SMA's and exit on second crossbelow.
    I wrote a strategy (code below) but it exits on first crossbelow every time. Logic looks good for me however it doesnt work. Any suggestion how to make it work would be very welcome.

    Regards

    if (Position.MarketPosition == MarketPosition.Flat)
    { second =
    false;}

    if (Position.MarketPosition == MarketPosition.Long
    && CrossBelow(SMA(
    3), SMA(14), 1)
    && second ==
    false)

    {second =
    true;}

    if (Position.MarketPosition == MarketPosition.Long
    && CrossBelow(SMA(
    3), SMA(14), 1)
    && second ==
    true)

    {ExitLong(
    "","");}


    if (High[0] > High[1])
    {
    EnterLong(
    1, "Long");
    }

    #2
    What do you mean by not working? What are you seeing right now? Are you running with CalculateBarOnClose = false? If you are it is very possible to have two simultaneous ticks trigger the exit even though this was only the first bar crossing.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Well, let me put it this way - strategy works, but do not work as I want to, I mean it exits on first signal instead second one.
      I use CalculateBarOnClose = true.
      Thanks for quick answer... as always.

      Comment


        #4
        Well here's the deal. You need to put them as if-else if statements not if-if statements. Right now it evaluates the first if-statement and then goes right on ahead and evaluates the second one immediately. That is why it is still exiting on your "first" crossover.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Great! "Else if" was a solution.
          Thank You!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          568 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          330 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
          548 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          548 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X