2024-04-25 16:46:28 +00:00
|
|
|
#region Using declarations
|
|
|
|
using NinjaTrader.Cbi;
|
|
|
|
using NinjaTrader.NinjaScript.Indicators;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
//This namespace holds Strategies in this folder and is required. Do not change it.
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
|
|
{
|
|
|
|
public class KnowSureThingBot : Strategy
|
|
|
|
{
|
|
|
|
KnowSureThing KST;
|
|
|
|
|
|
|
|
protected override void OnStateChange()
|
|
|
|
{
|
|
|
|
if (State == State.SetDefaults)
|
|
|
|
{
|
|
|
|
Description = @"";
|
|
|
|
Name = "Know Sure Thing Bot";
|
|
|
|
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.DataLoaded)
|
|
|
|
{
|
|
|
|
KST = KnowSureThing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnBarUpdate()
|
|
|
|
{
|
|
|
|
if (CurrentBar < BarsRequiredToTrade)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (BarsInProgress == 1)
|
|
|
|
return;
|
|
|
|
|
2024-04-27 13:58:39 +00:00
|
|
|
if (Position.MarketPosition == MarketPosition.Long && KST[0] < KST.MovingAverage[0])
|
|
|
|
{
|
|
|
|
ExitLong();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Position.MarketPosition == MarketPosition.Short && KST[0] > KST.MovingAverage[0])
|
|
|
|
{
|
|
|
|
ExitShort();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KST[0] > KST.MovingAverage[0] && KST[1] < KST.MovingAverage[1] && KST[0] <= -2.0)
|
2024-04-25 16:46:28 +00:00
|
|
|
{
|
|
|
|
SetProfitTarget(CalculationMode.Ticks, 12.0);
|
|
|
|
EnterLong();
|
|
|
|
}
|
|
|
|
|
2024-04-27 13:58:39 +00:00
|
|
|
if (KST[0] < KST.MovingAverage[0] && KST[1] > KST.MovingAverage[1] && KST[0] >= 2.0)
|
2024-04-25 16:46:28 +00:00
|
|
|
{
|
|
|
|
SetProfitTarget(CalculationMode.Ticks, 12.0);
|
|
|
|
EnterShort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|