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

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 ETFVoyageur, Today, 04:00 PM
        0 responses
        7 views
        0 likes
        Last Post ETFVoyageur  
        Started by AaronKTradingForum, Today, 03:44 PM
        1 response
        8 views
        0 likes
        Last Post AaronKTradingForum  
        Started by Felix Reichert, 04-26-2024, 02:12 PM
        11 responses
        77 views
        0 likes
        Last Post Felix Reichert  
        Started by junkone, 04-28-2024, 02:19 PM
        7 responses
        83 views
        1 like
        Last Post junkone
        by junkone
         
        Started by pechtri, 06-22-2023, 02:31 AM
        11 responses
        138 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Working...
        X