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 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 pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    148 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    5 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    5 views
    0 likes
    Last Post tkaboris  
    Started by GussJ, 03-04-2020, 03:11 PM
    16 responses
    3,283 views
    0 likes
    Last Post Leafcutter  
    Working...
    X