• 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

EnterShortLimit() executing on the wrong BarsInProgress

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

    EnterShortLimit() executing on the wrong BarsInProgress

    Hello,

    Im trying to understand why an order is executing on the wrong Bars series.

    In the code below Im 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(0,true, 1, Close[0],"Entry"); 
    
    //should instead be changed to:
    
    EntryOrder = EnterShortLimit(1,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,

      Thats 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 FMtrader, 03-15-2019, 02:30 AM
      6 responses
      32 views
      0 likes
      Last Post James108  
      Started by timko, Today, 08:18 AM
      0 responses
      2 views
      0 likes
      Last Post timko
      by timko
       
      Started by victorsmith, Today, 06:00 AM
      0 responses
      4 views
      0 likes
      Last Post victorsmith  
      Started by sohailashraf, Yesterday, 10:18 PM
      0 responses
      6 views
      0 likes
      Last Post sohailashraf  
      Started by jjnc2006, Yesterday, 07:36 PM
      0 responses
      16 views
      0 likes
      Last Post jjnc2006  
      Working...
      X