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

Exit on same bar

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

    Exit on same bar

    I have written a simple strategy the buys or sells on a pullback to the EMA, providing price has not reached the EMA within the last 15 bars, using EnterLongLimit or EnterShortLimit and am using a 15 minute chart. The problem that I am having is that if the entry bar is large enough then the strategy exits on the same bar even though price movement does not warrant an exit.

    protected
    overridevoid Initialize()
    {
    SetProfitTarget(
    "", CalculationMode.Ticks, target);
    SetStopLoss(
    "", CalculationMode.Ticks, stopLoss, false);
    CalculateOnBarClose = false;
    }

    protectedoverridevoid OnBarUpdate()
    {
    EMAValue = (EMA(MAPeriod)[
    0]);
    Condition1 = (ToTime(Time[
    0]) >= 0400 && ToTime(Time[0]) <= 1200);
    if(High[0] > EMA(MAPeriod)[0]) shortCount = 0;
    if (High[0] < EMA(MAPeriod)[0])shortCount++;
    if((shortCount >= other))
    {
    EnterShortLimit(EMA(MAPeriod)[
    0], "EMAShort");
    }

    }
    protectedoverridevoid OnOrderUpdate(IOrder order)
    {

    if (order.OrderState == OrderState.Filled)
    {
    longCount =
    0;
    shortCount =
    0;
    }
    }
    Left chart incorrect, right chart correct
    Attached Files

    #2
    Somehow the condition that the entry indicator gives changes to a non trading position, thats why it is closing the position try to change that it cant pull out the position

    Comment


      #3
      Exit on same bar as entry

      Thanks for the quick reply, however I do not think that this is the case. I have a stop of 20 pips and a target of 20 pips. The problem only occurs if the bar is greater than 20 pips, then it will exit on the same bar as the entry. As you can see from the 2 charts, the right hand chart's entry bar is less than 20 pips, so it has to follow through the trade as normal, whereas the left hand chart's entry bar is greater than 20 pips, so it thinks that the target has been hit on this bar and exits (this is possible, but only if the market comes down to the entry and then reverses more than 20 pips on the same bar, however this is not always the case). In the left hand chart, if you go to a smaller timeframe, at no point after entry does the market reverse 20 pips within the 15 minute timeframe.

      Comment


        #4
        HI traderT,

        One option would be to use a BarsSinceEntry() condition.
        More info at - http://www.ninjatrader-support.com/H...BarsSinceEntry

        You may also consider adding another series to your strategy for the purpose of exiting on time interval
        More info at - http://www.ninjatrader.com/support/f...ead.php?t=5787
        TimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mathias79, Today, 03:44 PM
        0 responses
        9 views
        0 likes
        Last Post Mathias79  
        Started by Austiner87, Today, 03:42 PM
        0 responses
        8 views
        0 likes
        Last Post Austiner87  
        Started by lorem, 04-25-2024, 09:18 AM
        19 responses
        82 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by joselube001, 05-10-2024, 12:17 PM
        6 responses
        29 views
        0 likes
        Last Post joselube001  
        Started by bigc0220, 09-18-2018, 09:16 AM
        6 responses
        2,587 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X