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
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!
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
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:
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();
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 Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
5 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
436 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
7 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
||
Started by rocketman7, Today, 09:41 AM
|
5 responses
19 views
0 likes
|
Last Post Today, 03:33 PM |
Comment