Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting 5 minute EMAs on 1 minute chart not working

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

    Plotting 5 minute EMAs on 1 minute chart not working

    Hi there,

    I am trying to accomplish something very simple in NinjaScript. I'm simply trying to calculate two 5 minute EMAs and have them plotted on a 1 minute chart. For some reason, only the 1minute versions of the indicators are showing. The strategy only runs on a 1 minute chart, but I need the 5 minute ema values plotted.

    Any idea what I'm doing wrong?




    //This namespace holds Strategies in this folder and is required. Do not change it.

    namespace NinjaTrader.NinjaScript.Strategies

    {

    public class OverlayedIndicatorStategy : Strategy

    {



    private EMA emaFast;

    private EMA emaSlow;


    enum TradeDirection {

    NONE, LONG, SHORT

    }



    protected override void OnStateChange()

    {

    if (State == State.SetDefaults)

    {

    Description = @"Overlayed Indicator Test Strategy";

    Name = "Overlayed Indicators Test";

    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 = 20;

    Fast = 72;

    Slow = 89;


    // Disable this property for performance gains in Strategy Analyzer optimizations

    // See the Help Guide for additional information

    IsInstantiatedOnEachOptimizationIteration = true;

    }



    else if (State == State.Configure)

    {

    AddDataSeries(null, BarsPeriodType.Tick, 1);

    AddDataSeries(null, BarsPeriodType.Minute, 5);


    // Make sure EMAs are calculated based on 5 minute data
    emaFast = EMA(BarsArray[2], Fast);
    emaSlow = EMA(BarsArray[2], Slow);

    }



    else if (State == State.DataLoaded)

    {



    emaFast.Plots[0].Brush = Brushes.White;

    emaFast.Plots[0].PlotStyle = PlotStyle.TriangleUp;


    emaSlow.Plots[0].Brush = Brushes.White;

    emaSlow.Plots[0].PlotStyle = PlotStyle.TriangleDown;


    AddChartIndicator(emaFast);

    AddChartIndicator(emaSlow);


    }

    }



    protected override void OnBarUpdate()

    {







    if (CurrentBars[0] < BarsRequiredToTrade)

    /return;


    // 5 minute bar logic
    if(BarsInProgress == 2){

    Draw.Region(this, "emaCloud", 0, CurrentBar, emaFast, emaSlow, Brushes.Transparent, Brushes.Purple, 75, 0);

    }



    // 1 minute bar logic
    if(BarsInProgress == 0){


    bool isNewDay = BarsArray[0].IsFirstBarOfSession;




    if (isNewDay){

    Print("NEW DAY: " + Time[0]);

    numTradesTaken = 0;

    }





    }

    }

    }


    }



    jaybedreamin
    NinjaTrader Ecosystem Vendor - Zion Trading Algos

    #2
    Hello jaybedreamin,

    From the help guide:
    "An indicator being added via AddChartIndicator() cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code (please make sure though the hosting strategy has the same AddDataSeries() call included as well)​"


    This means the indicator needs to add the series and plot the values on the primary series.

    Every bar needs a plot value set to see the plot. If there is no value to set on the lower time frame, set the value to the previous bars value.

    Below is a link to an example of plotting a higher time frame on a lower time frame.
    https://ninjatrader.com/support/foru...196#post820196
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    51 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    127 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X