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

Close trade on bar close using calculate on bar

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

    Close trade on bar close using calculate on bar

    hi,

    i have been struggling for a lot of hours to set the condition to close my position upon bar close using the calculate on bar methode.

    i realized that my exit condition looks at the preivous candle and executes based on that which i dont want, i want to only consider the bar which im currently in / is about to close.

    to be pricise i want the conditions to be "if the previous candle open is higher/equal then the low" and " if the previous candle close is lower/equal then high".
    For longs i add "if previous close is higher then open" to make sure its green and for shorts "if previous close is lower then open" to make sure its red.
    Basically if the candle has double wicks and fits to my direction im trading to.

    However i also add a Input of arithmetic value of +0.25 to the low of the previous candle to make sure that the low is greated then 0.25 away from the open for my long postions.
    I do this for the high as well adding -0.25 to it to ensure the high is higher then 0.25 form the open for my short postiions.

    so the condition was supposed to be as this, if the previous candle has double wicks and (if im in long) the low is further away then 0.25 from the open and its a green candle then exit long.
    or if the previous candle has double wicks (if im short) and the high is higher then 0.25 and its a red candle then exit short.

    I hope that was understandable.

    The issue i have now is that the previous candle before my entry is ALWAYS such a candle which means my exit condition executes right then my entry happens.

    I need to somehow ignore the last candle upon entry but start considering it once the current candle closes.

    I tried to use the "barssinceentry" condition to state that at least one bar has to pass to be able to execute but it doensnt work it either is set up to sell immidiatly or after 2 bars close (current one and the following).

    Any help whatsoever is appreciated and might give me a idea to resolve this.

    with that being said thx in advance for anyone trying to help out.

    cheers

    #2
    Hello bak95,

    Thanks for your post.

    When using Calculate.OnBarClose the strategy will only process OnBarUpdate() logic at the close of each bar.

    Calculate: https://ninjatrader.com/support/help.../calculate.htm

    This means that if one bar closes and you call EnterLong() the strategy will place an order. Then, if the next bar closes and you call ExitLong(), the strategy will submit an exit order for the long position.

    To determine if the current candle that closes is an up bar (green), you could create a condition that checks if the Close[0] is greater than the Open[0]. To detect if the current candle that closes is a down bar (red), you could create a condition that checks if the Close[0] is less than the Open[0].

    To detect if the previous bar is an up bar, you could create a condition that checks if the Close[1] is greater than the Open[1]. To detect if the previous bar is a down bar, you could create a condition that checks if the Close[1] is less than the Open[0].

    Detecting if the current bar that closes has an upper wick on an up bar, you could create a condition that checks if the High[0] is greater than the Close[0] and in the same condition check if the Close[0] is greater than the Open[0].

    Detecting if the current bar that closes has a lower wick on an up bar, you could create a condition that checks if the Low[0] is less than the Open[0] and in the same condition check if the Close[0] is greater than the Open[0].

    To have a script wait for 1 bar to pass since the Entry order was placed, BarsSinceEntryExecution() could be used.

    BarsSinceEntryExecution(): https://ninjatrader.com/support/help...yexecution.htm
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Haiasi, 04-25-2024, 06:53 PM
    2 responses
    16 views
    0 likes
    Last Post Massinisa  
    Started by Creamers, Today, 05:32 AM
    0 responses
    4 views
    0 likes
    Last Post Creamers  
    Started by Segwin, 05-07-2018, 02:15 PM
    12 responses
    1,786 views
    0 likes
    Last Post Leafcutter  
    Started by poplagelu, Today, 05:00 AM
    0 responses
    3 views
    0 likes
    Last Post poplagelu  
    Started by fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,407 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Working...
    X