• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLong Order is created 1 bar after plot of the same logic??

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

    EnterLong Order is created 1 bar after plot of the same logic??

    Hi

    I am creating a simple strategy for testing, based on a MACD cross, entering long when the fast period crosses above the slow period & vice versa

    I am also plotting a triangle up or down based on the same logic in the OnBarUpdate method, however the EnterLong order is placed at the next bar open, after the plot is displayed. I want the EnterLong order to be placed bar open price, where the triangle is plotted.

    Please see the code I'm using below, where you can see the plots defined & also the strategy logic

    Code:
    				AddPlot(new Stroke(Brushes.Crimson, 10), PlotStyle.TriangleDown, "Short");
    				AddPlot(new Stroke(Brushes.Lime, 10), PlotStyle.TriangleUp, "Long");
    			}
    			else if (State == State.Configure)
    			{
                    SetProfitTarget(CalculationMode.Ticks, 450);
                    SetStopLoss(CalculationMode.Ticks, 300);
    			}
                else if (State == State.DataLoaded)
                {
                    MACD1 = MACD(FastPeriod, SlowPeriod, Smooth);
                    AddChartIndicator(MACD1);
                }
            }
    
    		protected override void OnBarUpdate()
    		{
                //Add your custom strategy logic here.
    
                if (CurrentBars[0] < BarsRequiredToTrade)
                    return;
    
                // Long Entry
                
                /*if (CrossAbove(MACD1.Default, MACD1.Avg, 1))
                {
                    EnterLong();
                    Long[0] = Low[0] - TickSize * 100;
                }*/
    
                if (MACD1.Default[1] < MACD1.Avg[1] & MACD1.Default[0] >= MACD1.Avg[0])
                {
                    EnterLong();
                    Long[0] = Low[0] - TickSize * 100;
                }
                
                // Short Entry
                if (CrossBelow(MACD1.Default, MACD1.Avg, 1))
                {
                    EnterShort();
                    Short[0] = High[0] + TickSize * 100;
                }
            }
    I've also added a screen shot where you can see the chart from the Strategy Analyser.

    I'm sure it must be some kind of config on how I'm calculating or something.

    I've tried using the CrossAbove function but also using a simple calculation to make sure there wasn't any difference, you can see that in the commented code.

    I'd be grateful if you could let me know how to achieve this thanks

    Gav
    Attached Files

    #2
    Hi

    I've actually managed to work through this in terms of the order & why the order is placed on the bar that it is, what I don't understand now though, is why the plot is placed one bar behind

    If you could explain that would be great

    Comment


      #3
      Hello Gav_G,

      Thank you for your note.

      Assuming you’re running your strategy with calculate set to OnBarClose, then when the bar which is being evaluated closes, if the condition is true, will fire an order on the next bar.

      See Calculate Section of our helpguide,
      https://ninjatrader.com/support/help...?calculate.htm

      If you are running your strategy with Calculate set to OnEachTick, then on each tick of data you’re conditions will be evaluated for true or false. This setting would fire your order on the current bar in real time. If you are testing with calculate set to OnEachTick, historically, you would need to pull in a secondary data series for the strategy to act historically as it would in real time.

      See the following explanation,
      https://ninjatrader.com/support/foru...ad.php?t=64156

      You may be interested in the following sample for pulling in a secondary tick series,
      https://ninjatrader.com/support/foru...ad.php?t=19387

      Please let us know if you need further assistance.
      Alan P.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Simon Investimens, Today, 03:26 AM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Marco  
      Started by fx.practic, Today, 05:15 AM
      0 responses
      4 views
      0 likes
      Last Post fx.practic  
      Started by guidoisot, Today, 05:03 AM
      0 responses
      3 views
      0 likes
      Last Post guidoisot  
      Started by EnveousColnago, Yesterday, 06:58 AM
      1 response
      13 views
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Started by lindsayf, Today, 01:13 AM
      0 responses
      12 views
      0 likes
      Last Post lindsayf  
      Working...
      X