Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Usnig both OnEachTick + Bar Close

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

    Usnig both OnEachTick + Bar Close

    Hi,

    The strategy im working on has to enter a trade if the following is met

    Previous 2 bar are positive (Open < Close)
    +
    The price has fallen 3 points from the CURRENT bar's open.

    Currently I have the Calculate as
    Code:
    Calculate.OnEachTick
    Not sure how to go about the code itself, but i have this so far

    Code:
    if (IsFirstTickOfBar)
    {
    if (Open[1] < Close[1])
    && (Open[2] < Close[2])
    }
    && ((Low[0] + 3) < Open[0])
    
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"buy");
    BarBrush = Brushes.DodgerBlue;
    }
    Doesnt work due to
    Code:
    (Low[0] + 3) < Open[0])
    being mixed with a tick calculation and a bar calculation? And there an error with the &&, how should I go about combining the 1st part of the code with the 2nd?
    Thanks!
    Last edited by Ousher; 08-20-2020, 03:17 PM.

    #2
    Hello Ousher,

    Thank you for your post.

    The code would need to be the following:

    Code:
    if (IsFirstTickOfBar && Open[1] < Close[1] && Open[2] < Close[2] && Open[0] >= (Low[0] + 3))
    {
    // Take your desired action.
    }
    Some resources that you may find useful can be found in our Help Guide at the following link: https://ninjatrader.com/support/help..._reference.htm

    Please let me know if you have any questions.

    Comment


      #3
      Hello Ousher,

      To follow up on my last post; the IsFirstTickOfBar is likely to make the "Open[0] >= (Low[0] + 3)" invalid as the first tick of the bar is the open and the low and the high and the close.

      So you could do the following:
      Code:
      // define a new variable for a bool outside the OnBarUpdate() method.
      private bool MyBool = false;
      
      private override void OnBarUpdate()
      {[INDENT]if (IsFirstTickOfBar)
      {[/INDENT][INDENT=2]MyBool = false;
      if (Open[1] < Close[1] && Open[2] < Close[2])
      {[/INDENT][INDENT=3]MyBool = true;[/INDENT][INDENT=2]}[/INDENT][INDENT]}[/INDENT][INDENT]if (MyBool && Open[0] >= (Low[0] + 3))
      {[/INDENT][INDENT=2]// Take your desired action;[/INDENT][INDENT]}[/INDENT]
        }

      Comment


        #4
        Awesome. Thanks Patrick!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        43 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        20 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        30 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        48 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        38 views
        0 likes
        Last Post CarlTrading  
        Working...
        X