Add strategy based on the SuperSmoother indicator
This commit is contained in:
parent
b0eb691e72
commit
812f19e6b6
77
strategies/SuperBot.cs
Normal file
77
strategies/SuperBot.cs
Normal file
@ -0,0 +1,77 @@
|
||||
#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 SuperBot : Strategy
|
||||
{
|
||||
private SuperSmoother superSmoother;
|
||||
|
||||
protected override void OnStateChange()
|
||||
{
|
||||
if (State == State.SetDefaults)
|
||||
{
|
||||
Description = @"Bot based on John F. Ehlers' SuperSmoother";
|
||||
Name = "SuperBot";
|
||||
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;
|
||||
}
|
||||
else if (State == State.Configure)
|
||||
{
|
||||
superSmoother = SuperSmoother(10);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnBarUpdate()
|
||||
{
|
||||
if (CurrentBar < BarsRequiredToTrade)
|
||||
return;
|
||||
|
||||
if(CrossAbove(Close, superSmoother.Value[0], 1) || (Open[0] > superSmoother.Value[0] && Close[0] > Open[0]))
|
||||
{
|
||||
if (Position.MarketPosition != MarketPosition.Long)
|
||||
EnterLong();
|
||||
}
|
||||
else if (CrossBelow(Close, superSmoother.Value[0], 1) || (Open[0] < superSmoother.Value[0] && Close[0] < Open[0]))
|
||||
{
|
||||
if (Position.MarketPosition != MarketPosition.Short)
|
||||
EnterShort();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user