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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    627 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    359 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    562 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X