ninjatrader/strategies/internal-bar-strength/InternalBarStrengthBot.cs

56 lines
1.6 KiB
C#

#region Using declarations
using NinjaTrader.Cbi;
using NinjaTrader.NinjaScript.Indicators;
using System.ComponentModel.DataAnnotations;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class InternalBarStrengthBot : Strategy
{
private InternalBarStrength ibs;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "Internal Bar Strength Bot";
Description = @"Long only bot which bases trades on internal bar strength";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryThreshold = 0.2;
ExitThreshold = 0.8;
}
else if (State == State.DataLoaded)
{
ibs = InternalBarStrength();
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
if (ibs[0] < EntryThreshold)
EnterLong();
else if (ibs[0] > ExitThreshold && Position.MarketPosition == MarketPosition.Long)
ExitLong();
}
public override string DisplayName
{
get { return Name; }
}
[NinjaScriptProperty]
[Display(Name = "Entry Threshold", GroupName = "Internal Bar Strength Bot", Order = 1)]
public double EntryThreshold { get; set; }
[NinjaScriptProperty]
[Display(Name = "Exit Threshold", GroupName = "Internal Bar Strength Bot", Order = 2)]
public double ExitThreshold { get; set; }
}
}