Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cannot implicitly convert type 'NinjaTrader.NinjaScript.Indicators.EMA' to 'double'

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

    Cannot implicitly convert type 'NinjaTrader.NinjaScript.Indicators.EMA' to 'double'

    I am creating a moving average of ATR to be plotted alongside. I am not sure what is wrong with this call as i compile error.

    Values[1][0]=EMA(Values[0],MAPeriod);

    // entire code snippet

    CustomATR.cs Cannot implicitly convert type 'NinjaTrader.NinjaScript.Indicators.EMA' to 'double' CS0029 80 18


    Code:
    {
    
    AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meATR);
    AddPlot(Brushes.Yellow, "ATR MA");
    }
    }
    
    protected override void OnBarUpdate()
    {
    double high0 = High[0];
    double low0 = Low[0];
    
    if (CurrentBar == 0)
    Value[0] = high0 - low0;
    else
    {
    double close1 = Close[1];
    double trueRange = Math.Max(Math.Abs(low0 - close1), Math.Max(high0 - low0, Math.Abs(high0 - close1)));
    Values[0][0] = ((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period);
    }
    if(CurrentBar>MAPeriod)
    {
    Values[1][0]=EMA(Values[0],MAPeriod);
    }
    
    }
    
    Properties
    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
    public int Period
    { get; set; }
    
    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "MA Period", GroupName = "NinjaScriptParameters", Order = 1)]
    public int MAPeriod
    { get; set; }

    #2
    Hello junkone,

    EMA(Values[0],MAPeriod) is a series.

    EMA(Values[0],MAPeriod)[0] is a double.

    Which do you need?

    Do you need a specific bar value?

    Provide a barsAgo index.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    154 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    306 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    244 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    345 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    176 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Working...
    X