#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 ATO : Strategy
{
private int HighestBarsAgo;
private int LowestBarsAgo;
private double HighestPrice;
private double LowestPrice;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "ATO";
Calculate = Calculate.OnBarClose;
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 = 7;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
LookBackPeriod = 15;
HighestBarsAgo = 1;
LowestBarsAgo = 1;
HighestPrice = 1;
LowestPrice = 1;
//ProfitTargetTicks = 12;
}
else if (State == State.Configure)
{
SetTrailStop(CalculationMode.Ticks, 20);
//SetParabolicStop("Enter ATO Long", CalculationMode.Ticks, 20, false, 0.03, 0.3, 0.01);
// SetParabolicStop("Enter ATO Short", CalculationMode.Ticks, 20, false, 0.03, 0.3, 0.01);
//SetParabolicStop(CalculationMode.Ticks, 20);
//SetStopLoss(CalculationMode.Ticks, StopLossTicks);
//SetProfitTarget(CalculationMode.Ticks, 10);
//SetStopLoss(CalculationMode.Ticks, 20);
}
}
protected override void OnBarUpdate()
{
//Add your custom strategy logic here.
//Add your custom strategy logic here.
if (BarsInProgress != 0)
return;
// Resets the stop loss to the original value when all positions are closed
// set initial highest/lowest price to first bar of session so we have a baseline
if(Bars.IsFirstBarOfSession)
{
HighestPrice = High[0];
LowestPrice = Low[0];
}
if (CurrentBars[0] < LookBackPeriod)
return;
if (ToTime(Time[0]) >= 62000 && ToTime(Time[0]) <= 65000)
{
HighestPrice = MAX(High, 7)[0];
Print("The current MAX value is " + HighestPrice.ToString());
LowestPrice = MIN(Low, 7)[0];
Print("The current MIN value is " + LowestPrice.ToString());
}
// Set 2
//if (BarsSinceEntryExecution(0, @"ATO Enter Long", 1) == 1)
//BarsSinceExitExecution() == -1)
if (ToTime(Time[0]) >= 65001 && ToTime(Time[0]) <= 82500 && Close[0] > HighestPrice && BarsSinceEntryExecution(0, @"Enter ATO Long", 1) != 1)
{
EnterLongLimit(HighestPrice, "Enter ATO Long");
Print("ATO Long " + HighestPrice.ToString());
}
if (ToTime(Time[0]) >= 65001 && ToTime(Time[0]) <= 82500 && Close[0] < LowestPrice && BarsSinceEntryExecution(0, @"Enter ATO Short", 1) != 1)
{
EnterShortLimit(LowestPrice, "Enter ATO Short");
Print("ATO Short " + LowestPrice.ToString());
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="LookBackPeriod", Order=1, GroupName="Parameters")]
public int LookBackPeriod
{ get; set; }
#endregion
}
}
Comment