63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
#region Using declarations
|
|
using NinjaTrader.Cbi;
|
|
using NinjaTrader.NinjaScript.Indicators;
|
|
using System;
|
|
#endregion
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public class RSIDivergenceBot : Strategy
|
|
{
|
|
private RSI rsi;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Description = @"Simple strategy based on RSI divergence";
|
|
Name = "RSI Divergence Bot";
|
|
Calculate = Calculate.OnBarClose;
|
|
EntriesPerDirection = 1;
|
|
EntryHandling = EntryHandling.AllEntries;
|
|
IsExitOnSessionCloseStrategy = false;
|
|
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;
|
|
IsInstantiatedOnEachOptimizationIteration = true;
|
|
}
|
|
else if (State == State.DataLoaded)
|
|
{
|
|
rsi = RSI(14, 3);
|
|
}
|
|
}
|
|
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (CurrentBar < BarsRequiredToTrade)
|
|
return;
|
|
|
|
if (rsi[0] > rsi[5] && Close[0] < Close[5])
|
|
{
|
|
int quantity = (int)Math.Floor(100000 / Close[0]);
|
|
EnterLong(quantity);
|
|
}
|
|
|
|
if (Position.MarketPosition == MarketPosition.Long && rsi[0] > 70.0)
|
|
ExitLong();
|
|
}
|
|
|
|
public override string DisplayName
|
|
{
|
|
get { return Name; }
|
|
}
|
|
}
|
|
}
|