Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Same strategy, different ninjascript, different results

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

    Same strategy, different ninjascript, different results

    My friend created a strategy for me and then I made a simple version out of it but the results are different. Can you please tell me why the results are different. This is his strategy:

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class Nikita : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int movAvgLength = 200; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    Add(SMA(Close, movAvgLength));

    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    SMA MovAvg = SMA(movAvgLength);
    RSI rsi = RSI(2, 1);

    if(Close[0] > MovAvg[0] && rsi[0] <= 10)
    {
    EnterLong(DefaultQuantity, "Long");
    }

    if(Close[0] < MovAvg[0] && rsi[0] >= 90)
    {
    EnterShort(DefaultQuantity, "Short");
    }

    if (rsi[0] > 50)
    ExitLong();
    else if (rsi[0] < 50)
    ExitShort();

    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int MovAvgLength
    {
    get { return movAvgLength; }
    set { movAvgLength = Math.Max(1, value); }
    }
    #endregion
    }





    This is how I coded it:

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// RSI(2) w/ MA.
    /// </summary>
    [Description("RSI(2) w/ MA. ")]
    public class RSI2MA : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    //Enter long
    if(CrossAbove(Close, SMA(200), 1) && RSI(2, 0)[0] <= 10);
    {
    EnterLong(DefaultQuantity, "Long");
    }
    //Enter short
    if(CrossBelow(Close, SMA(200), 1) && RSI(2, 0)[0] >= 90);
    {
    EnterShort(DefaultQuantity, "Short");
    }

    //Exit long
    if(RSI(2, 0)[0] > 50);
    {
    ExitLong("Exit Long", "");
    }
    //Exit short
    if(RSI(2, 0)[0] < 50);
    {
    ExitShort("Exit Short ", "");
    }
    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    Hello NGorodzhiy,

    Thank you for your post.

    The only difference I see is that the smooth is 1 in the other strategy where it is 0 on yours.

    Comment


      #3
      It is not that because I have changed the smooth period to 1 in my period and the results are still drastically different.

      Comment


        #4
        Can you provide some examples for comparison? If you can, please provide screenshots.

        Comment


          #5
          Here it is: http://imgur.com/a/8zbPm

          The first one is using my friend's ninjascript, second results are using my ninjascript.
          Same instrument(SPY) and same length.

          Comment


            #6
            Can you attach the two files to your response for the strategies? And please attach screenshots of the settings used for the backtest.

            Comment


              #7
              Radin is using my friend's ninjascript,
              Nikita is using my ninjascript.
              Attached Files

              Comment


                #8
                The files seem to be too large in dimensions, I will upload them again.

                Comment


                  #9
                  Radin is using my friend's ninjascript,
                  Nikita is using my ninjascript.
                  Attached Files

                  Comment


                    #10
                    Your friend's code:
                    Code:
                    protected override void OnBarUpdate()
                    {
                    SMA MovAvg = SMA(movAvgLength);
                    RSI rsi = RSI(2, 1);
                    
                    if(Close[0] > MovAvg[0] && rsi[0] <= 10)
                    {
                    EnterLong(DefaultQuantity, "Long");
                    }
                    
                    if(Close[0] < MovAvg[0] && rsi[0] >= 90)
                    {
                    EnterShort(DefaultQuantity, "Short");
                    }
                    
                    if (rsi[0] > 50)
                    ExitLong();
                    else if (rsi[0] < 50)
                    ExitShort();
                    
                    }
                    is not at all similar to your code:
                    Code:
                    protected override void OnBarUpdate()
                    {
                    //Enter long 
                    if(CrossAbove(Close, SMA(200), 1) && RSI(2, 0)[0] <= 10);
                    {
                    EnterLong(DefaultQuantity, "Long");
                    }
                    //Enter short 
                    if(CrossBelow(Close, SMA(200), 1) && RSI(2, 0)[0] >= 90);
                    {
                    EnterShort(DefaultQuantity, "Short");
                    }
                    A "close above" is a very different condition from a "CrossAbove".

                    Comment


                      #11
                      What exactly do I have to change to match my friend's code?

                      Comment


                        #12
                        Originally posted by NGorodzhiy View Post
                        What exactly do I have to change to match my friend's code?
                        Copy it. Don't change anything.

                        Comment


                          #13
                          But I want to know what exactly I need to change, because if not I will never learn. Please help. Thanks.

                          Comment


                            #14
                            Originally posted by NGorodzhiy View Post
                            What exactly do I have to change to match my friend's code?
                            Use "Close" where he uses "Close". Why did you change it to "CrossOver"?

                            Comment


                              #15
                              I do. CrossAbove and CrossBelow is his version of ">" and "<".

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              147 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,282 views
                              0 likes
                              Last Post Leafcutter  
                              Working...
                              X