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 cmoran13, Yesterday, 01:02 PM
          0 responses
          29 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          21 views
          0 likes
          Last Post PaulMohn  
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          160 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          95 views
          1 like
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          148 views
          2 likes
          Last Post CaptainJack  
          Working...
          X