2024-06-23 12:33:30 +00:00
|
|
|
#region Using declarations
|
|
|
|
using NinjaTrader.Cbi;
|
|
|
|
using NinjaTrader.NinjaScript.Indicators;
|
2024-10-24 12:21:43 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-06-23 12:33:30 +00:00
|
|
|
#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";
|
2024-10-21 14:00:18 +00:00
|
|
|
Description = @"Long only bot which bases trades on internal bar strength";
|
2024-06-23 12:33:30 +00:00
|
|
|
Calculate = Calculate.OnBarClose;
|
|
|
|
EntriesPerDirection = 1;
|
2024-10-24 12:21:43 +00:00
|
|
|
|
|
|
|
EntryThreshold = 0.2;
|
|
|
|
ExitThreshold = 0.8;
|
2024-06-23 12:33:30 +00:00
|
|
|
}
|
|
|
|
else if (State == State.DataLoaded)
|
|
|
|
{
|
|
|
|
ibs = InternalBarStrength();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnBarUpdate()
|
|
|
|
{
|
|
|
|
if (CurrentBar < BarsRequiredToTrade)
|
|
|
|
return;
|
|
|
|
|
2024-10-24 12:21:43 +00:00
|
|
|
if (ibs[0] < EntryThreshold)
|
2024-06-23 12:33:30 +00:00
|
|
|
EnterLong();
|
2024-10-24 12:21:43 +00:00
|
|
|
else if (ibs[0] > ExitThreshold && Position.MarketPosition == MarketPosition.Long)
|
2024-06-23 12:33:30 +00:00
|
|
|
ExitLong();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string DisplayName
|
|
|
|
{
|
|
|
|
get { return Name; }
|
|
|
|
}
|
2024-10-24 12:21:43 +00:00
|
|
|
|
|
|
|
[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; }
|
2024-06-23 12:33:30 +00:00
|
|
|
}
|
|
|
|
}
|