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:	38
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 MarionCron, Today, 11:43 PM
        0 responses
        1 view
        0 likes
        Last Post MarionCron  
        Started by kaywai, Today, 11:20 PM
        0 responses
        1 view
        0 likes
        Last Post kaywai
        by kaywai
         
        Started by JodieThur, Today, 11:11 PM
        0 responses
        2 views
        0 likes
        Last Post JodieThur  
        Started by cryfgg, Today, 06:01 PM
        0 responses
        18 views
        0 likes
        Last Post cryfgg
        by cryfgg
         
        Started by Tremblinghandtrader, Today, 04:56 PM
        0 responses
        33 views
        0 likes
        Last Post Tremblinghandtrader  
        Working...
        X