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 DojiStrategy : Strategy
{
private double OpenLoc;
private double CloseLoc;
private double Pct;
private double OpenCheck;
private double CloseCheck;
private double WickCheck;
private double GreenCandle;
private double LowCheck;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "DojiStrategy";
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 = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
PctNearTop = 30;
PT = 1000;
SL = 1000;
}
else if (State == State.Configure)
{
SetProfitTarget(CalculationMode.Currency, PT);
SetStopLoss(CalculationMode.Currency, SL);
}
}
protected override void OnBarUpdate()
{
if(CurrentBar < BarsRequiredToTrade)
return;
OpenLoc = (Open[0]-Low[0])/(High[0]-Low[0]);
CloseLoc = (Close[0]-Low[0])/(High[0]-Low[0]);
Pct = (100-PctNearTop)/100;
if(OpenLoc>Pct)
{
OpenCheck = 1;
}
else
{
OpenCheck = 0;
}
if(CloseCheck>Pct)
{
CloseCheck = 1;
}
else
{
CloseCheck = 0;
}
if((High[0]-Close[0])<(Open[0]-Low[0]))
{
WickCheck = 1;
}
else
{
WickCheck = 0;
}
if(Close[0]>Open[0])
{
GreenCandle = 1;
}
else
{
GreenCandle = 0;
}
if(Low[0]<Low[1])
{
LowCheck = 1;
}
else
{
LowCheck = 0;
}
Print(Time[0].ToString() + " OpenLoc: " + OpenLoc);
Print(Time[0].ToString() + " CloseLoc: " + CloseLoc);
Print(Time[0].ToString() + " Pct: " + Pct);
Print(Time[0].ToString() + " OpenCheck: " + OpenCheck);
Print(Time[0].ToString() + " CloseCheck: " + CloseCheck);
Print(Time[0].ToString() + " WickCheck: " + CloseCheck);
Print(Time[0].ToString() + " GreenCandle: " + CloseCheck);
Print(Time[0].ToString() + " LowCheck: " + CloseCheck);
Print(Time[0].ToString() + " Open[0]: " + Open[0]);
Print(Time[0].ToString() + " Close[0]: " + Close[0]);
if(OpenCheck == 1 && CloseCheck == 1 && WickCheck == 1 && GreenCandle == 1 && LowCheck == 1)
EnterLong();
}
region Properties
[NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Percentage Near Top", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
public double PctNearTop
{ get; set; }
[NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Profit Target", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
public int PT
{ get; set; }
[NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Stop Loss", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
public int SL
{ get; set; }
#endregion
}
}
Comment