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

EnterShortLimit() executing on the wrong BarsInProgress

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

    EnterShortLimit() executing on the wrong BarsInProgress

    Hello,

    I´m trying to understand why an order is executing on the wrong Bars series.

    In the code below I´m show how I have set for two orders to execute each on a very specific bar. One of these orders should happen within the context of the primary bars series and the second order should happen within the context of the secondary bars series, yet, both execute within the primary series.

    Here is my code:





    public class AddSeriesTest : Strategy
    {

    #region Variables
    private Order EntryOrder = null;
    #endregion

    protected override void OnStateChange(){
    if (State == State.SetDefaults)
    {
    Description = @"";
    Name = "AddSeriesTest";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 0;
    IsInstantiatedOnEachOptimizationIteration = true;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;

    }

    ////////////////// Adds secondary series, primary series is ES 09-14 loaded by chart
    else if (State == State.Configure)
    {
    AddDataSeries("ES 12-14", Data.BarsPeriodType.Minute, 2, Data.MarketDataType.Last);
    }
    }

    protected override void OnBarUpdate(){


    ////////////////// Checks which Bars is calling the bar update based on the day
    if( BarsInProgress == 0 && ToDay(Time[0]) > 20140910)
    return;

    if( BarsInProgress == 1 && ToDay(Time[0]) < 20140911)
    return;

    Print(@"bar# " + CurrentBar + @"in Bars " + BarsInProgress);



    /////////////////// Submits order if on a specific bar in the asigned Bars
    if(BarsInProgress == 0 && ToDay(Time[0]) == 20140910 && ToTime(Time[0]) == ToTime(11,58,00) )
    {
    SetProfitTarget(CalculationMode.Ticks,6);
    SetStopLoss(CalculationMode.Ticks,9);
    EntryOrder = EnterShortLimit(0,true, 1, Close[0],"Entry");
    }



    if(BarsInProgress == 1 && ToDay(Time[0]) == 20140911 && ToTime(Time[0]) == ToTime(10,10,00) )
    {
    SetProfitTarget(CalculationMode.Ticks,6);
    SetStopLoss(CalculationMode.Ticks,9);
    EntryOrder = EnterShortLimit(0,true, 1, Close[0],"Entry");
    }


    }


    protected override void OnExecutionUpdate (Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time){

    if(execution.Order.Name == "Entry")
    {
    Print(execution.Order.OrderState + @" in full By Bars: " + BarsInProgress);
    }

    if(execution.Order.Name == "Profit target")
    {
    EntryOrder = null;
    Print(@"W in Bars: " + BarsInProgress);

    }

    if(execution.Order.Name == "Stop loss")
    {
    EntryOrder = null;
    Print(@"L in Bars: "+ BarsInProgress);
    }
    }

    }



    #2
    Hello Orden33,

    Thank you for the post.

    In this case I see you have used the overload set where you specify the BarsInProgress for EnterShortLimit. You have used BIP 0 for both EnterShortLimit calls. I believe in this case you intended to have 0 and 1, is this correct?

    Code:
    if(BarsInProgress == 1 && ToDay(Time[0]) == 20140911 && ToTime(Time[0]) == ToTime(10,10,00) )
    { 
    SetProfitTarget(CalculationMode.Ticks,6);
    SetStopLoss(CalculationMode.Ticks,9); 
    
    
    EntryOrder = EnterShortLimit([B]0[/B],true, 1, Close[0],"Entry"); 
    
    //should instead be changed to:
    
    EntryOrder = EnterShortLimit([B]1[/B],true, 1, Close[0],"Entry"); 
    
    
    }
    Can you confirm if this is the problem?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse, thanks for your very prompt reply,

      That´s exactly right. I had not noticed that the entry method I was using took in the Bars index.

      I appreciate your help. Take care

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by DJ888, 04-16-2024, 06:09 PM
      4 responses
      12 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by terofs, Today, 04:18 PM
      0 responses
      9 views
      0 likes
      Last Post terofs
      by terofs
       
      Started by nandhumca, Today, 03:41 PM
      0 responses
      6 views
      0 likes
      Last Post nandhumca  
      Started by The_Sec, Today, 03:37 PM
      0 responses
      3 views
      0 likes
      Last Post The_Sec
      by The_Sec
       
      Started by GwFutures1988, Today, 02:48 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Working...
      X