Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Not able to enter Long on a green bar

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

    Not able to enter Long on a green bar

    Hello,
    I'm trying to make a script were the Entry signal is when:
    After CCI has crosses below -200, the next available GREEN bar (Close > Open) enters the Long signal
    Here is the code:

    // ENTRY
    if (Position.MarketPosition == MarketPosition.Flat)

    {


    for (int x=1; x <=5 ;x++)
    {
    if (CrossBelow(CCI(14), -200, x))
    {
    if (Close[0] > Open[0])
    EnterLong(100000,"Long");
    }
    }


    }

    Thanks for the help

    #2
    Hello igna1984,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    The for loop will only run on the current bar so the if(Close[0] > Open[0]) would be checked only on the current bar. In addition if any of the look back periods return true and the bar is up then an entry will be submitted, so if you do not set EntriesPerDirection to 1 you could see multiple entries.

    If you wanted to check for the CrossBelow() and then on the next bar check the if(Close[0] > Open[0]) condition you would need to take the condition out of the for loop.
    You could have a bool that is true if the CrossBelow() condition was true and then check the if(Close[0] > Open[0]) condition and the bool together:
    Code:
    private bool crsblw = false;
    
    for (int x=1; x <=5 ;x++)
    { 
    if (CrossBelow(CCI(14), -200, x))
    {
    crsblw = true;
    }
    }
    
    if (Close[0] > Open[0] && crsblw)
    {
    EnterLong(100000,"Long");
    }
    With the code above you would need another condition to set the bool to false or just set the bool to false when if (Close[0] > Open[0] && crsblw) is true:
    Code:
    if (Close[0] > Open[0] && crsblw)
    {
    EnterLong(100000,"Long");
    crsblw = false;
    }
    Please let me know if you have any questions.

    Comment


      #3
      Thanks Patrick,
      Your are right that way i think is better and it's more clear. but It's not working. this is what i got

      protected override void OnBarUpdate()
      {
      if (Position.MarketPosition == MarketPosition.Flat)
      {
      for (int x=1; x <=5 ;x++)
      {
      if (CrossBelow(CCI(14), -200, x))
      {
      crsblw = true;
      }
      }

      if (Close[0] > Open[0] && crsblw)
      {
      EnterLong(100000,"Long");
      crsblw = false;
      }
      }
      }
      my very first entry is on a RED candlestick and that's exactly what i don't wont
      Last edited by igna1984; 05-22-2013, 03:18 PM.

      Comment


        #4
        Hello igna1984,

        Thank you for your response.

        Can you send me your strategy so I may test this item on my end?

        If you would like you can send the strategy to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 850048' in the subject line and a reference to this thread: http://www.ninjatrader.com/support/f...ad.php?t=57992

        I look forward to your response.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        580 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        335 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        102 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X