#region Using declarations
...
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class goldreturn : Strategy
{
private Bollinger bb;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "goldreturn";
Calculate = Calculate.OnPriceChange;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
rsi = RSI(14, 1);
adx = ADX(14);
// bbu = Bollinger(20,2).Upper();
bbl = Bollinger(20,2).Lower;
bb = Bollinger(20,2);
// Add RSI and ADX indicators to the chart for display
// This only displays the indicators for the primary Bars object (main instrument) on the chart
AddChartIndicator(bb);
}
}
protected override void OnBarUpdate()
{
//Add your custom strategy logic here.
if (Input[0] > Bollinger(2,20).Upper[0] + 0.5 ) {
EnterShort(10,"shortgold");
}
if (Input[0] < Bollinger(2,20).Upper[0])
ExitShort("shortgold");
if (Input[0] < Bollinger(2,20).Lower[0] - 0.5 ) {
EnterLong(10,"longgold");
}
if (Input[0] > Bollinger(2,20).Lower[0])
ExitLong("longgold");
}
}
Comment