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.
    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:	139
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.


        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Aviram Y, Today, 05:29 AM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by algospoke, 04-17-2024, 06:40 PM
        3 responses
        26 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by bmartz, 03-12-2024, 06:12 AM
        3 responses
        30 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X