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

Compiling error - "Cannot simplicity convert type..."

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

    Compiling error - "Cannot simplicity convert type..."

    I have two user input properties: _smooth to smoothen moving average and MovingAverageTypeLOV enum as the different moving average types a user can select.

    I want to add logic that if _smooth = 1, then there will NO smoothing regardless of the moving average type the user selects and _avg = Input. Input comes from the Indicator's Input Series - Price Type parameter.

    This is the code that I have in State == State.DataLoaded

    Code:
    else if (State == State.DataLoaded)
    
                {
    
    
                    //Initialize class level variable including custom Series<>
    
                    _trend = new Series<bool>(this);
    
                    _avg = new Series<double>(this);
    
    
    
                    if(_smooth == 1)
    
                    {
    
                        _avg = Input;
    
                    }
    
                    else
    
                    {
    
                        switch (_maType)
    
                        {
    
                            case MovingAverageTypeLOV.SMA:
    
                                _avg = SMA(Input, _smooth).Value;
    
                                break;
    
        //                        case MovingAverageType.SMMA:                // Not available at time of Beta 5
    
        //                            _avg = SMMA(Input, _smooth).Value;
    
        //                            break;
    
                            case MovingAverageTypeLOV.TMA:
    
                                _avg = TMA(Input, _smooth).Value;
    
                                break;
    
                            case MovingAverageTypeLOV.WMA:
    
                                _avg = WMA(Input, _smooth).Value;
    
                                break;
    
                            case MovingAverageTypeLOV.VWMA:
    
                                _avg = VWMA(Input, _smooth).Value;
    
                                break;
    
                            case MovingAverageTypeLOV.TEMA:
    
                                _avg = TEMA(Input, _smooth).Value;
    
                                break;
    
                            case MovingAverageTypeLOV.HMA:
    
                                _avg = HMA(Input, _smooth).Value;
    
                                break;
    
                            case MovingAverageTypeLOV.VMA:
    
                                _avg = VMA(Input, _smooth, _smooth).Value;
    
                                break;
    
                            default:
    
                                _avg = EMA(Input, _smooth).Value;
    
                                break;
    
                        }
    
                    }
    The error that I am getting is "Cannot simplicity convert type 'NinjaTrader.ninjaScript.ISeries<double>' to 'NinjaTrader.ninjaScript.Series<double>'. An explicit conversion exists (are you missing a cast?)".

    I know that this error is do to this line:

    Code:
    _avg = Input;
    It is got to be something simple that I am not seeing. Please help.

    Thanks.
    JG

    #2
    Hello [email protected],

    Thanks for your post.

    The error would be expected due to the separate type objects.

    You would want to assign in OnBarUpdate() with

    if (smooth == 1)
    {
    _avg[0] = Input[0];
    }


    You can keep your other assignments in State.DataLoaded, just change the conditional to account for smooth > 1

    Note: A new series will be limited to a look back a maximum of 256 from the current bar. If you need a larger lookback you can define the series with MaximumBarsLookBack.Infinite.

    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kevinenergy, 02-17-2023, 12:42 PM
    115 responses
    2,699 views
    1 like
    Last Post kevinenergy  
    Started by prdecast, Today, 06:07 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by Christopher_R, Today, 12:29 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by chartchart, 05-19-2021, 04:14 PM
    3 responses
    577 views
    1 like
    Last Post NinjaTrader_Gaby  
    Started by bsbisme, Yesterday, 02:08 PM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X