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 funk10101, Today, 12:02 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by GLFX005, Today, 03:23 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by nandhumca, Yesterday, 03:41 PM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by The_Sec, Yesterday, 03:37 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by vecnopus, Today, 06:15 AM
    0 responses
    1 view
    0 likes
    Last Post vecnopus  
    Working...
    X