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 charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          51 views
          0 likes
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          142 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          160 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 05-10-2026, 08:12 PM
          0 responses
          96 views
          0 likes
          Last Post CarlTrading  
          Started by Hwop38, 05-04-2026, 07:02 PM
          0 responses
          275 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Working...
          X