Thursday, August 20, 2009

Supertrend strategy

Ninjatrader code, you need those indicators imported first.
------------------------------

#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
{
///
/// Enter the description of your strategy here
///

[Description("Enter the description of your strategy here")]
public class testSuperTrend : Strategy
{
#region Variables

#endregion

///
/// This method is used to configure the strategy and is called once before any strategy method is called.
///

protected override void Initialize()
{
CalculateOnBarClose = true;


Add(DynamicSR(21));
Add(SuperTrend(10, 3));
Add(CCI_Histogram(14)) ;
Add(ElliotOscillator(5, 35));
}

///
/// Called on each bar update event (incoming tick)
///

protected override void OnBarUpdate()
{
//go long
if
(Close[0] > DynamicSR(21).Resistance[0] && Close[0] > SuperTrend(10, 3).UpTrend[0]
&& CCI_Histogram(14).CCIoversold[0] > 0 && ElliotOscillator(5, 34).Uptrend[0] > 0)
{
EnterLong(DefaultQuantity, "");
}

//stop if closes under dynamic S
if (Position.MarketPosition == MarketPosition.Long && Close[0] < marketposition ="=""> DynamicSR(21).Resistance[0])
{
ExitShort();
}

}

#region Properties

#endregion
}
}

No comments:

Post a Comment