• 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

Change from Calculate.OnPriceChange to .OnBarClose makes script freeze

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

    Change from Calculate.OnPriceChange to .OnBarClose makes script freeze

    Can´t figure out what makes my script freeze and the chart stops updating without giving an error message.

    The script uses two Bars series and starts with Calculate.OnBarClose then changes to .OnPriceChange when the order is placed. I notice that the problem happens when I revert back to .OnBarClose when the order is closed with the .OnExectionUpdate method



    Here is my code:




    #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 03-14 loaded by chart
    else if (State == State.Configure)
    {
    AddDataSeries("ES 06-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 == 1 && ToDay(Time[0]) < 20140314) //ES 06-14
    return;

    ////////// Submits order on a specific bar in the asigned Bars series and sets Calculate method to OnPriceChange
    if(BarsInProgress == 0 && ToDay(Time[0]) == 20140312 && ToTime(Time[0]) == ToTime(14,28,00) )
    {
    SetProfitTarget(CalculationMode.Ticks,6);
    SetStopLoss(CalculationMode.Ticks,9);
    EntryOrder = EnterShortLimit(0,true, 1, Close[0],"Entry");
    Calculate = Calculate.OnPriceChange;
    }
    }


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

    if(execution.Order.Name == "Entry")
    {
    Print(ToDay(Time[0]) + @" " + ToTime(Time[0]) + @" " + execution.Order.OrderState + @" in full By Bars: " + BarsInProgress);
    }


    ///////// Reverts back to .OnBarClose on either target or stoploss
    if(execution.Order.Name == "Profit target")
    {
    Calculate = Calculate.OnBarClose;
    Print(@"W in Bars: " + BarsInProgress);
    }

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

    }

    }

    #2
    Hello Orden33,

    While it is not explicitly stated in the help guide, the Calculate property should not be changed after the State becomes State.DataLoaded. This should only be set in OnStateChange when the State property is either State.SetDefaults, or State.Configure.

    I am sending a request to our product management to update the help guide so that this is mentioned.

    Please change the logic so that the Calculate value is not changed after the State becomes State.DataLoaded. (This means the Calculate setting cannot be changed in OnBarUpdate or other data driven methods).
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by psquare, Today, 03:11 PM
    4 responses
    16 views
    0 likes
    Last Post psquare
    by psquare
     
    Started by ballboy11, Today, 03:20 PM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by tonynt, Today, 02:18 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_JoshG  
    Started by denalek2419, Today, 01:46 PM
    3 responses
    12 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by REI140205, Today, 12:58 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Jim  
    Working...
    X