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

Cannot plot MAEnvelopes with M1 calculations on 1-tick chart in Strategy Analyzer

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

    Cannot plot MAEnvelopes with M1 calculations on 1-tick chart in Strategy Analyzer

    Hi All,

    i struggle since few days to get MAEnvelopes (with M1 calculations) plotted on the Strategy Analyzer 1-tick chart (within a Strategy)
    I manage to plot it with 1-tick calc, but not with M1 on 1-tick. Below is the code
    Code:
    private MAEnvelopes MA_Env;
    
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "Blabla";
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    IsExitOnSessionCloseStrategy = false;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 2000;
    IsInstantiatedOnEachOptimizationIteration    = true;
    
    }
    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Tick, 1);
    AddDataSeries(BarsPeriodType.Minute, 1);
    }
    else if (State == State.DataLoaded)
    {
    
    MA_Env= MAEnvelopes(BarsArray[2], 0.05,Convert.ToInt32( 3), Convert.ToInt32(30));
    AddChartIndicator(MA_Env);
    
    
    SetStopLoss(@"", CalculationMode.Pips, Stoploss, false);
    SetProfitTarget("", CalculationMode.Pips, Takeprofit);
    }
    }
    protected override void OnBarUpdate()
    {
    .....

    btw i also created custom MAEnvelopes and added following to it, but still didnt help:

    Code:
    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Minute, 1);
    
    }


    What i am doing wrong?
    Help will be highly appreciated

    Thanks
    BR
    Toti
    Last edited by toti1981; 07-31-2021, 02:45 PM.

    #2
    Hello toti1981,

    Welcome to the NinjaTrader forums!

    Are you trying to plot a higher time frame plot on a smaller time frame chart?

    Below is a link to an example.
    https://ninjatrader.com/support/foru...196#post820196
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      thanks for the link. I did use it and it worked, but plots are not recalculated on each tick even if i placed it on 1.tick. See chart below: left Strategy Analyzer chart vs right normal chart.
      What i am doing wrong?


      I used following code:

      Code:
      ....
      AddPlot(Brushes.Teal, "Plot1");
      AddPlot(Brushes.Orange, "Plot2");
      }
      else if (State == State.Configure)
      {
      AddDataSeries(BarsPeriodType.Minute, 1);
      
      }
      else if (State == State.DataLoaded)
      {
      MA_EnvTeal = MAEnvelopes(Closes[1], 0.05,3, 30);
      MA_EnvOrange = MAEnvelopes(Closes[1], 0.05,3, 90);
      
      
      ....
      
      protected override void OnBarUpdate()
      {
      
      if (BarsInProgress == 0 && CurrentBars[0] > 0)
      {
      Values[0][0] = MA_EnvTeal.Middle[0];
      Values[2][0] = MA_EnvTeal.Upper[0];
      Values[4][0] = MA_EnvTeal.Lower[0];
      // extend the larger time frame for each primary bar so there are consecutive bars set so we can see it on the chart
      if (!Values[1].IsValidDataPoint(0))
      Values[1][0] = Values[1][1];
      }
      if (BarsInProgress == 1 && CurrentBars[1] > 0)
      {
      Values[1][0] = MA_EnvOrange.Middle[0];
      Print(Values[1][0]);
      Values[3][0] = MA_EnvOrange.Upper[0];
      Print(Values[3][0]);
      Values[5][0] = MA_EnvOrange.Lower[0];
      Print(Values[5][0]);
      
      }


      Click image for larger version

Name:	1234.PNG
Views:	48
Size:	64.8 KB
ID:	1166517

      Comment


        #4
        Hello toti1981,

        Are you referring to the Calculate setting?

        In historical data this always OnBarClose unless TickReplay is enabled and the data source supports historical tick data.

        Below are links to the help guide on TickReplay.
        https://ninjatrader.com/support/help...ick_replay.htm
        https://ninjatrader.com/support/help...ick_replay.htm
        https://ninjatrader.com/support/help.../calculate.htm
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by 7robert, Today, 11:50 AM
        0 responses
        5 views
        0 likes
        Last Post 7robert
        by 7robert
         
        Started by ezrollin, Today, 10:40 AM
        8 responses
        11 views
        0 likes
        Last Post ezrollin  
        Started by sidlercom80, Today, 10:20 AM
        2 responses
        6 views
        0 likes
        Last Post sidlercom80  
        Started by TraderElegante, Today, 09:53 AM
        2 responses
        18 views
        0 likes
        Last Post TraderElegante  
        Started by Kreyenhagen, Today, 09:03 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Working...
        X