I only have three errors left to correct. One CS0246 and two CS0103
I looked at the help pages, but I still don't understand. I use "if", it's spelled correctly
#region Using declarations
using System;
using NinjaTrader.NinjaScript;
using NinjaTrader.Data;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript.Strategies;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class StrategyHighLowBreakout : Strategy
{
private double highBetween9And945 = double.MinValue;
private double lowBetween9And945 = double.MaxValue;
private bool isPeriodCompleted = false;
private EMA ema35;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Stratégie de breakout basée sur les plus hauts et plus bas entre 9h et 9h45 avec EMA 35";
Name = "HighLowBreakoutStrategy";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 35;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 1); // Données en minutes
}
else if (State == State.DataLoaded)
{
ema35 = EMA(35);
}
}
protected override void OnBarUpdate()
{
// Ne pas calculer avant d'avoir assez de données
if (CurrentBar < BarsRequiredToTrade)
return;
// Étape 1 : Enregistrer les plus hauts et plus bas entre 9h et 9h45
if (Times[0][0].TimeOfDay >= new TimeSpan(9, 0, 0) && Times[0][0].TimeOfDay <= new TimeSpan(9, 45, 0))
{
highBetween9And945 = Math.Max(highBetween9And945, High[0]);
lowBetween9And945 = Math.Min(lowBetween9And945, Low[0]);
}
else if (Times[0][0].TimeOfDay > new TimeSpan(9, 45, 0) && !isPeriodCompleted)
{
isPeriodCompleted = true;
}
// Étape 2 : Vérifier les conditions pour les trades longs ou courts
if (isPeriodCompleted)
{
// Long (achat)
if (Close[0] > ema35[0] && High[0] > highBetween9And945)
{
EnterLong("LongBreakout");
}
// Short (vente)
if (Close[0] < ema35[0] && Low[0] < lowBetween9And945)
{
EnterShort("ShortBreakout");
}
}
// Étape 3 : Stop Loss et gestion des risques
if (State == State.Realtime || State == State.Historical)
{
if (Position.MarketPosition == MarketPosition.Long)
{
double stopLossLong = Math.Max(Low[1], Low[2]);
stopLossLong = Math.Min(stopLossLong, Close[0] - 100 / Instrument.MasterInstrument.PointValue);
SetStopLoss("LongBreakout", CalculationMode.Price, stopLossLong, false);
}
if (Position.MarketPosition == MarketPosition.Short)
{
double stopLossShort = Math.Min(High[1], High[2]);
stopLossShort = Math.Max(stopLossShort, Close[0] + 100 / Instrument.MasterInstrument.PointValue);
SetStopLoss("ShortBreakout", CalculationMode.Price, stopLossShort, false);
}
}
}
}}

Comment