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

Strategy based on Fast Stochastics

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

    Strategy based on Fast Stochastics

    Hello,

    Because I am not familiar with C#, I would prefer to devellop the following strategy for future trading with the wizzard and wonder whether this is possible.

    Conditions for Fast Stochastic to fulfill all for entry Long:
    Value of %K > %D
    %K is ascending
    %D is ascending
    (%K and %D) < 25
    AND
    8:30 < Actual time < 21:45
    (Market hours are from 8:00 - 22:00, but I don't want to go in the market at the opening and 15 minutes before closing of the market)

    (For short positions I will have to do the contrairy)

    At 21:55 I want to close any postion (short or long)

    If it is not possible to create with the wizzard I will appreciate a script for this (still basic) strategy.

    I am looking forward for any help.

    #2
    Yes this is possible using the wizard.

    You will have to get familiar with the wizard of course. Following is a link to a Tutorial in building a strategy in the wizard.

    RayNinjaTrader Customer Service

    Comment


      #3
      Strategy based on Fast Stochastics --- code

      here is your code...all the best...god bless

      #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.Strategy;
      #endregion

      namespace NinjaTrader.Strategy
      {
      ///<summary>
      /// Conditions for Fast Stochastic to fulfill all for entry Long: Value of %K > %D, %K is ascending, %D is ascending,(%K and %D) < 25
      ///</summary>
      [Description("Conditions for Fast Stochastic to fulfill all for entry Long: Value of %K > %D, %K is ascending, %D is ascending,(%K and %D) < 25")]
      [Gui.Design.DisplayName("Strategy based on Fast Stochastics")]
      publicclass StrategybasedonFastStochastics : Strategy
      {
      #region Variables
      // Wizard generated variables
      privateint myInput0 = 1; // Default setting for MyInput0

      #endregion
      ///<summary>

      ///</summary>
      protectedoverridevoid Initialize()
      {
      Add(StochasticsFast(3, 14));
      SetProfitTarget("", CalculationMode.Ticks, 4);
      SetStopLoss("", CalculationMode.Ticks, 4, false);
      CalculateOnBarClose = true;
      }
      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      // Condition set 1
      if (StochasticsFast(3, 14).K[0] > StochasticsFast(3, 14).D[0]
      && StochasticsFast(3, 14).D[0] < 25
      && StochasticsFast(3, 14).K[0] < 25
      && StochasticsFast(3, 14).D[0] > StochasticsFast(3, 14).D[1]
      && StochasticsFast(3, 14).D[2] > StochasticsFast(3, 14).D[3]
      && StochasticsFast(3, 14).K[0] > StochasticsFast(3, 14).K[1]
      && StochasticsFast(3, 14).K[2] > StochasticsFast(3, 14).K[3])
      {
      EnterLong(DefaultQuantity, "");
      }
      }
      #region Properties
      [Description("")]
      [Category("Parameters")]
      publicint MyInput0
      {
      get { return myInput0; }
      set { myInput0 = Math.Max(1, value); }
      }
      #endregion
      }
      }

      Comment


        #4
        I tweaked it a little and thought you might find it interesting.

        Several parameters were added to the strategy so it could be run through the optimizer to see what kind of potential it might have, and although I was able to make it look profitable (see screen shot), it would have to be tested on more than a 6-week time period before I'd want to throw any money at it. But I think you'll agree it's going in the right direction.

        Enjoy!

        Code:
        #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.Strategy;
        #endregion
        
        // Found on NinjaTrader Forum 29-Oct-2007
        // Ran Optimizer on it and found that it likes these parameters:  
        //        PeriodD=16, PeriodK=17, ProfitTarget=16, StoLongThreshold=15, StopLoss=12
        //        when used with a 50-tick period from 10-Sep-2007 to 26-Oct-2007 on the ES 12-07 contract.
        //
        // I have only backtested and NOT live tested this.  Caution: performance may vary.
        //
        // KBJ
        
        
        namespace NinjaTrader.Strategy
        {
            ///<summary>
            /// Conditions for Fast Stochastic to fulfill all for entry Long: Value of %K > %D, %K is ascending, %D is ascending,(%K and %D) < 25
            ///</summary>
            [Description("Conditions for Fast Stochastic to fulfill all for entry Long: Value of %K > %D, %K is ascending, %D is ascending,(%K and %D) < 25")]
            [Gui.Design.DisplayName("Strategy based on Fast Stochastics")]
            public class FastStochasticsStrategy : Strategy
            {
                #region Variables
                // Wizard generated variables
                private int periodD = 3;                // Default setting for PeriodD
                private int periodK = 14;                // Default setting for PeriodK
                private int profitTarget = 4;            // Default setting for ProfitTarget
                private int stopLoss = 4;                 // Default setting for StopLoss
                private int stoLongThreshold = 25;        // Default setting for StoLongThreshold
                #endregion
                ///<summary>
                
                ///</summary>
                protected override void Initialize()
                {
                    Add(StochasticsFast(PeriodD, PeriodK));
                    SetProfitTarget("", CalculationMode.Ticks, ProfitTarget);
                    SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
                    CalculateOnBarClose = true;
                }
                ///<summary>
                /// Called on each bar update event (incoming tick)
                ///</summary>
                protected override void OnBarUpdate()
                {
                    // Condition set 1
                    if (   StochasticsFast(PeriodD, PeriodK).K[0] > StochasticsFast(PeriodD, PeriodK).D[0]
                        && StochasticsFast(PeriodD, PeriodK).D[0] < StoLongThreshold
                        && StochasticsFast(PeriodD, PeriodK).K[0] < StoLongThreshold
                        && StochasticsFast(PeriodD, PeriodK).D[0] > StochasticsFast(PeriodD, PeriodK).D[1]
                        && StochasticsFast(PeriodD, PeriodK).D[1] > StochasticsFast(PeriodD, PeriodK).D[2]
                        && StochasticsFast(PeriodD, PeriodK).K[0] > StochasticsFast(PeriodD, PeriodK).K[1]
                        && StochasticsFast(PeriodD, PeriodK).K[1] > StochasticsFast(PeriodD, PeriodK).K[2]
                       )
                    {
                        EnterLong(DefaultQuantity, "");
                    }
                }
            
                #region Properties
                [Description("Period used for calculating the %D of the StochasticsFast indicator.")]
                [Category("Parameters")]
                public int PeriodD
                {
                    get { return periodD; }
                    set { periodD = Math.Max(1, value); }
                }
        
                [Description("Period used for calculating the %K of the StochasticsFast indicator.")]
                [Category("Parameters")]
                public int PeriodK
                {
                    get { return periodK; }
                    set { periodK = Math.Max(1, value); }
                }
        
                [Description("Where to take a profit in number of ticks of profit to take.")]
                [Category("Parameters")]
                public int ProfitTarget
                {
                    get { return profitTarget; }
                    set { profitTarget = Math.Max(1, value); }
                }
        
                [Description("Where to set the stop loss in number of ticks of loss to tolerate.")]
                [Category("Parameters")]
                public int StopLoss
                {
                    get { return stopLoss; }
                    set { stopLoss = Math.Max(1, value); }
                }
        
                [Description("Look for FastStochastics %K & %D indicators both being below this value before initiating a trade.")]
                [Category("Parameters")]
                public int StoLongThreshold
                {
                    get { return stoLongThreshold; }
                    set { stoLongThreshold = Math.Max(1, value); }
                }
        
                #endregion
            }
        }
        Attached Files

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by AdamDJ8, 05-07-2024, 09:18 PM
        2 responses
        15 views
        0 likes
        Last Post -=Edge=-  
        Started by StockTrader88, 03-06-2021, 08:58 AM
        46 responses
        4,099 views
        3 likes
        Last Post tradgrad  
        Started by usasugardefender, Today, 01:42 AM
        0 responses
        1 view
        0 likes
        Last Post usasugardefender  
        Started by haas88, 03-21-2024, 02:22 AM
        15 responses
        182 views
        0 likes
        Last Post haas88
        by haas88
         
        Started by brianfnoel, Today, 01:24 AM
        0 responses
        6 views
        0 likes
        Last Post brianfnoel  
        Working...
        X