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.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Two questions.
Collapse
X
-
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.Tags: None
-
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
-
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:
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.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();
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
630 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
566 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment