Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CS1003 0246 No position !

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    CS1003 0246 No position !

    Hello, I might finally be able to code after all these years...
    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


    Code:
    #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);
    }
            }
        }
    }}​
    Attached Files

    #2
    .Solved. It was necessary to add "using"

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Nate G, 03-17-2025, 02:53 PM
    3 responses
    32 views
    0 likes
    Last Post brucerobinson  
    Started by RosySmit, Today, 01:35 AM
    0 responses
    6 views
    0 likes
    Last Post RosySmit  
    Started by gmacjapan, Today, 01:27 AM
    0 responses
    4 views
    0 likes
    Last Post gmacjapan  
    Started by WHICKED, 06-27-2023, 12:07 PM
    95 responses
    1,148 views
    1 like
    Last Post diegocml  
    Started by gmacjapan, Yesterday, 11:47 PM
    0 responses
    8 views
    0 likes
    Last Post gmacjapan  
    Working...
    X