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

Help with Ehlers Predictive Moving Strategy - Compilation errors and more

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

    Help with Ehlers Predictive Moving Strategy - Compilation errors and more


    Hello I an NEW. So please be kind. I really am not good at programming (or know the difference between a bodily orifice and a hole in the ground)

    I used the strategy builder to kind of build the base then tried to mess with the code. I am using the Ehlers Predictive Moving Strategy to try and place scalping trades

    I get the following errors
    The best overloaded method match for 'NinjaTrader.NinjaScript.NinjaScriptBase.CrossBelo w(double, NinjaTrader.NinjaScript.ISeries<double>, int)' has some invalid arguments CS1502 106
    Argument 2: cannot convert from 'double' to 'NinjaTrader.NinjaScript.ISeries<double>' CS1503 106
    The best overloaded method match for 'NinjaTrader.NinjaScript.NinjaScriptBase.CrossAbov e(double, NinjaTrader.NinjaScript.ISeries<double>, int)' has some invalid arguments CS1502 120
    Argument 2: cannot convert from 'double' to 'NinjaTrader.NinjaScript.ISeries<double>' CS1503 120

    What I am trying to do is when the Predict Line crosses the Trigger Line then place a trade depending on cross above or cross below. I have bolded the offending lines.

    The code is below

    region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class RenkoEhlersPredictiveMovingStrategyModified : Strategy
    {
    private int DaysProfit;
    private Series<double> Trigger;
    private Series<double> Predict;

    //private WMA WMA1;
    private Series<double> wma1;
    private Series<double> wma2;
    private int MINBAR = 13;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Ehlers Predictive Moving strategy goes long when the signal truns green and goes short when the signal turns red";
    Name = "RenkoEhlersPredictiveMovingStrategyModified";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    StartofTrading = DateTime.Parse("08:30", System.Globalization.CultureInfo.InvariantCulture) ;
    EndofTrading = DateTime.Parse("15:30", System.Globalization.CultureInfo.InvariantCulture) ;
    MaxDailyProfit = 1500;
    MaxDailyLoss = 500;
    NumberOfContracts = 1;
    DaysProfit = 0;
    //Trigger = 1;
    //Predict = 1;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    wma1 = new Series<double>(this);
    wma2 = new Series<double>(this);
    Trigger = new Series<double>(this);
    Predict = new Series<double>(this);
    //WMA1 = WMA(Close, 14);
    }
    }

    protected override void OnBarUpdate()
    {

    wma1[0] = (7 * Median[0] + 6 * Median[1] + 5 * Median[2] + 4 * Median[3] + 3 * Median[4] + 2 * Median[5] + Median[6]) / 28;
    wma2[0] = (7 * wma1[0] + 6 * wma1[1] + 5 * wma1[2] + 4 * wma1[3] + 3 * wma1[4] + 2 * wma1[5] + wma1[6]) / 28;

    Trigger[0] = 2 * wma1[0] - wma2[0];
    Predict[0] = (4 * Trigger[0] + 3 * Trigger[1] + 2 * Trigger[2] + Trigger[3]) / 10;

    //LastPredict = Predict[1];
    //LastTrigger = Trigger[0];

    if (CurrentBar <= MINBAR) return;

    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if ((CrossBelow(Predict[1], Trigger[0], 1))
    // Trading times
    && ((Times[0][0].TimeOfDay >= StartofTrading.TimeOfDay)
    && (Times[0][0].TimeOfDay <= EndofTrading.TimeOfDay))
    //ProfitLoss
    && ((DaysProfit <= MaxDailyProfit)
    && (DaysProfit >= MaxDailyLoss))
    )
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"");
    ExitShort(Convert.ToInt32(NumberOfContracts), "", @"");
    }

    // Set 2
    if ((CrossAbove(Predict[1], Trigger[0], 1))
    // Trading times
    && ((Times[0][0].TimeOfDay >= StartofTrading.TimeOfDay)
    && (Times[0][0].TimeOfDay <= EndofTrading.TimeOfDay))
    // ProfitLoss
    && ((DaysProfit <= MaxDailyProfit)
    && (DaysProfit >= MaxDailyLoss))
    )
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
    }

    Print(Convert.ToString(DaysProfit));
    }

    region Properties
    [NinjaScriptProperty]
    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
    [Display(Name="StartofTrading", Description="Time the trading starts", Order=1, GroupName="Parameters")]
    public DateTime StartofTrading
    { get; set; }

    [NinjaScriptProperty]
    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
    [Display(Name="EndofTrading", Description="End of Trading for Strategy", Order=2, GroupName="Parameters")]
    public DateTime EndofTrading
    { get; set; }

    [NinjaScriptProperty]
    [Range(0, int.MaxValue)]
    [Display(Name="MaxDailyProfit", Order=3, GroupName="Parameters")]
    public int MaxDailyProfit
    { get; set; }

    [NinjaScriptProperty]
    [Range(0, int.MaxValue)]
    [Display(Name="MaxDailyLoss", Order=4, GroupName="Parameters")]
    public int MaxDailyLoss
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="NumberOfContracts", Description="Number Of Contracts", Order=5, GroupName="Parameters")]
    public int NumberOfContracts
    { get; set; }
    #endregion

    }
    }



    #2
    Hello johnfernandes63,

    Thank you for your post and welcome to the support forums!

    We are glad to assist programmers of all skill levels, even those who are looking to get started with NinjaScript and aren't sure where to start. That being said, to maintain a mutual level of respect and kindness please refrain from language that may depict graphic imagery or words/phrases that may be unsettling to others.

    The error messages you are receiving are saying that the value used for the parameters in CrossAbove and CrossBelow may not be converted from a double to an ISeries<double> value. What that means is the values you are currently using, Predict[1] and Trigger[0], are doubles instead of a Series<double>. This should be resolved by referring to the series as a whole, which would involve regular parenthesis ( ), rather than a barsAgo index with the square brackets [ ]. It may help to review the Help Guide sections for CrossAbove and CrossBelow, which also include code snippets demonstrating the use of these methods. Those pages may be found at the following links:

    https://ninjatrader.com/support/help...crossabove.htm
    https://ninjatrader.com/support/help...crossbelow.htm

    Additionally, since you mentioned you are new I would like to provide the following link to a post where my colleague put together many useful resources for those getting started with NinjaScript:


    It sounds like you are already taking advantage of using the Strategy Builder and then building from the code generated there. That can be a really helpful tool to demonstrate different concepts in NinjaScript and C#.

    Please let us know if we may be of further assistance.
    Last edited by NinjaTrader_Emily; 11-21-2022, 03:31 PM. Reason: Added a link to additional NinjaScript/C# resources
    Emily C.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,789 views
    0 likes
    Last Post aligator  
    Started by Jimmyk, 01-26-2018, 05:19 AM
    6 responses
    837 views
    0 likes
    Last Post emuns
    by emuns
     
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    6 responses
    3,293 views
    1 like
    Last Post jgualdronc  
    Started by Touch-Ups, Today, 10:36 AM
    0 responses
    13 views
    0 likes
    Last Post Touch-Ups  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    11 responses
    63 views
    0 likes
    Last Post halgo_boulder  
    Working...
    X