I am moving over from TD Ameritrade and am having quite a fit with Ninjatrader's interface. Anyway, I have been trying to build a simple strategy I want to backtest (and possibly algo trade) but for the life of me I can't get it to run. I think I finally built it, but after I "Finish"ed the strategy in the Strategy Editor I remember I put the CCIzeroline = 0 User Input as having a minimum value of 1.
Now I am getting that error complaining it isn't between 1 and two hundred thousand or million something. I tried to redo it in the Strategy Editor (which wouldn't allow it and kept saying I needed to close out all version of the strategy before editing).
Then I deleted it from my only chart, closed the chart, tried everything I could and the Strategy Editor would open it, but still not let me edit the CCIzeroline User Input. I have no idea why, so since that seemed broken I switched over to opening the code (which disallows using the Strategy Editor anymore, which is kind of stupid).
I have copied and pasted the code to a text file. Currently it is for stocks and I am using my TD Ameritrade data feed. The strategy is simple right now, nowhere close to the complexity I have completed overall, I just want to test it. The synopsis of what it SHOULD do is:
CCI(5)
SMA(8,(High+Low)/2)
ATR(5,Wilders)
If *both* CCI crosses above the zeroline and the price closes above the SMA(8), set a stoplimit Buy to Open $0.02 above the bar's High. If *either* CCI crosses below the zeroline or price closes below SMA(8), sell. ATR should be above 3, which is kind of an error.
My strategy is supposed to be Stoplimit Buy to Open @ High + 0.02 for stocks, or 0.25 for futures. The ATR should be above 3 for futures trading on the 1-minute chart, but will be different for stocks (which I did forget).
I can post my code, but I am first wondering how to edit this to work.
Ultimately for stocks I am wanting to pyramid my entries and do a lot of other things, but I am just trying to get started at this point. I do have some C and C++, Python, and Java experience, but I am just starting out in C#. If I can get a handle on the basics it will go much more quickly, but until I can actually get INTO this and have a first working program I can mess around in (so I can tweak things and see cause and effect) it will be a bear to learn. I just need to get my first program working and bells and whistles can come later.
Long copy and past to follow of my current code. Unfortunately this stupid forum won't permit indentations of tabs OR four spaces, so I am sorry it isn't presenting correctly:
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class GoldenThrone : Strategy
{
private CCI CCI1;
private ATR ATR1;
private SMA SMA1;
private SMA SMA2;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Will add later";
Name = "GoldenThrone";
Calculate = Calculate.OnPriceChange;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlatSynchronizeAccount;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.ByStrategyPosition;
BarsRequiredToTrade = 9;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
CCIperiod = 5;
SMAperiod = 8;
ATRperiod = 5;
CCIzeroline_value = 0;
ATRminimum_value = 3;
Quantity = 100;
Stop_buy_offset = 0.02;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
CCI1 = CCI(Close, Convert.ToInt32(CCIperiod));
ATR1 = ATR(Close, Convert.ToInt32(ATRperiod));
SMA1 = SMA(Median, Convert.ToInt32(SMAperiod));
SMA2 = SMA(Median, Convert.ToInt32(SMAperiod));
CCI1.Plots[0].Brush = Brushes.DarkOrchid;
ATR1.Plots[0].Brush = Brushes.DarkCyan;
AddChartIndicator(CCI1);
AddChartIndicator(ATR1);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if ((CrossAbove(CCI1, CCIzeroline_value, 1))
&& (ATR1[0] >= ATRminimum_value)
&& (CrossAbove(Close, SMA1, 1)))
{
EnterLongStopLimit(Convert.ToInt32(Quantity), (High[0] + (Stop_buy_offset)) , (High[0] + (Stop_buy_offset)) , @"Buy_to_Open");
}
// Set 2
if ((CrossBelow(CCI1, CCIzeroline_value, 1))
|| (CrossBelow(Close, SMA2, 1)))
{
ExitLong(Convert.ToInt32(Quantity), @"Sell_to_Close", @"Buy_to_Open");
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="CCIperiod", Description="CCI period (default: 5)", Order=1, GroupName="Parameters")]
public int CCIperiod
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="SMAperiod", Description="SMA period (default: 8)", Order=2, GroupName="Parameters")]
public int SMAperiod
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="ATRperiod", Description="ATR period (default: 5)", Order=3, GroupName="Parameters")]
public int ATRperiod
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="CCIzeroline_value", Description="The value of the zeroline is... ZERO!", Order=4, GroupName="Parameters")]
public int CCIzeroline_value
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="ATRminimum_value", Description="ATR minimum value is... 3!", Order=5, GroupName="Parameters")]
public int ATRminimum_value
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Quantity", Description="Quantity to buy", Order=6, GroupName="Parameters")]
public int Quantity
{ get; set; }
[NinjaScriptProperty]
[Range(0, double.MaxValue)]
[Display(Name="Stop_buy_offset", Description="How far above the bar high to put our stoplimit (Default: 0.02 for stocks, 0.25 for futures)", Order=7, GroupName="Parameters")]
public double Stop_buy_offset
{ get; set; }
#endregion
}
}

Comment