ninjatrader/strategies/trin/TRINBot.cs

92 lines
2.7 KiB
C#
Raw Normal View History

2024-09-21 13:32:21 +00:00
#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
namespace NinjaTrader.NinjaScript.Strategies
{
public class TRINBot : Strategy
{
private RSI rsi;
private SMA sma;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"";
Name = "TRIN 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;
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
AddDataSeries("^TRIN", BarsPeriodType.Day, 1);
}
else if (State == State.DataLoaded)
{
rsi = RSI(2, 1);
sma = SMA(200);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[1] < 2)
return;
if (CurrentBar < 200)
return;
if (Close[0] > sma[0] && rsi[0] < 50)
{
if (Closes[1][0] > 1.0 && Closes[1][1] > 1.0 && Closes[1][2] > 1.0)
EnterLong();
}
else if (rsi[0] > 65)
ExitLong();
}
public override string DisplayName
{
get { return Name; }
}
}
}