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

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 CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        5 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,266 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X