• 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 xsgex, Yesterday, 09:46 PM
      0 responses
      2 views
      0 likes
      Last Post xsgex
      by xsgex
       
      Started by Steve L, Yesterday, 09:36 PM
      0 responses
      1 view
      0 likes
      Last Post Steve L
      by Steve L
       
      Started by krugman25, Yesterday, 09:34 PM
      0 responses
      4 views
      0 likes
      Last Post krugman25  
      Started by indy73, Yesterday, 04:42 PM
      0 responses
      15 views
      0 likes
      Last Post indy73
      by indy73
       
      Started by Italianforex, Yesterday, 06:20 AM
      2 responses
      13 views
      0 likes
      Last Post gplatis
      by gplatis
       
      Working...
      X