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 Brevo, Today, 01:45 AM
        0 responses
        6 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        3 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        241 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Started by oviejo, Today, 12:28 AM
        0 responses
        6 views
        0 likes
        Last Post oviejo
        by oviejo
         
        Working...
        X