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

Two questions.

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

    Two questions.

    In the November issue of Stocks and Commodities there is a Forex trading system called the Trend Determining (TD) Method. I was wondering if anyone could program that into Ninja Trader.

    Also, does anyone know how to copy the Colby Stochastics strategy into an existing strategy? Like if you have a moving average cross-over system and then you want to plug Colby's system in to give it something else to consider.

    #2
    Hi Drakmyre,

    If you can post the code here, I will give a shot when I find time...

    Thanks!
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand,

      Here you go!

      //
      // Copyright (C) 2007, NinjaTrader LLC <www.ninjatrader.com>.
      // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
      //
      #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

      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      /// <summary>
      /// Robert W. Colby's Stochastics with Long-Term EMA Filter strategy
      /// </summary>
      [Description("Stochastics with Long-Term EMA Filter strategy from the December 2006 issue of S+C")]
      public class StochasticsColby : Strategy
      {
      #region Variables
      private int opt1 = 7;
      private int opt2 = 3;
      private int opt3 = 20;
      private int opt4 = 271;
      private DataSeries entry;
      #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()
      {
      entry = new DataSeries(this);
      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      entry.Set((Close[0] - MIN(Low, Opt1)[0]) / (MAX(High, Opt1)[0] - MIN(Low, Opt1)[0]));

      if (SMA(entry, Opt2)[0] < (0.5 - 0.01 * Opt3) && Close[0] > EMA(Opt4)[0])
      EnterLong();
      else if (SMA(entry, Opt2)[0] > (0.5 + 0.01 * Opt3) && Close[0] < EMA(Opt4)[0])
      EnterShort();

      if (Position.MarketPosition == MarketPosition.Long)
      {
      if (SMA(entry, Opt2)[0] > (0.5 + 0.01 * Opt3) || Close[0] < EMA(Opt4)[0])
      ExitLong();
      }
      else if (Position.MarketPosition == MarketPosition.Short)
      {
      if (SMA(entry, Opt2)[0] < (0.5 - 0.01 * Opt3) || Close[0] > EMA(Opt4)[0])
      ExitShort();
      }
      }

      #region Properties
      /// <summary>
      /// </summary>
      [Description("%K of Stochastics")]
      [Category("Parameters")]
      public int Opt1
      {
      get { return opt1; }
      set { opt1 = Math.Max(1, value); }
      }

      /// <summary>
      /// </summary>
      [Description("Stochastics Smoothing")]
      [Category("Parameters")]
      public int Opt2
      {
      get { return opt2; }
      set { opt2 = Math.Max(1, value); }
      }

      /// <summary>
      /// </summary>
      [Description("Numbers of bars used for calculations")]
      [Category("Parameters")]
      public int Opt3
      {
      get { return opt3; }
      set { opt3 = Math.Max(1, value); }
      }

      /// <summary>
      /// </summary>
      [Description("Numbers of periods for the EMA")]
      [Category("Parameters")]
      public int Opt4
      {
      get { return opt4; }
      set { opt4 = Math.Max(1, value); }
      }
      #endregion
      }
      }

      Comment


        #4
        Thanks for posting the code Drakmyre!

        There are two ways to do this -

        1. Add you other entry/exit conditions to this code portion below:

        Code:
        if (SMA(entry, Opt2)[0] < (0.5 - 0.01 * Opt3) && Close[0] > EMA(Opt4)[0])
        EnterLong();
        else if (SMA(entry, Opt2)[0] > (0.5 + 0.01 * Opt3) && Close[0] < EMA(Opt4)[0])
        EnterShort();
        2. Extract the Stochastic code from your posted code, build a custom indicator and then move to the Strategy wizard to build your condition for execution.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Bertrand,

          Got it! I had to do it one at a time though and not just copy all of them at once.

          Do you know anything about the TD method?
          Last edited by Drakmyre; 11-16-2008, 02:08 AM.

          Comment


            #6
            Hi Drakmyre,

            Great you got it figured out.

            Unfortunately I don't have more info about the TD Method. Maybe you can contact the TASC author for details.
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            5 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X