Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Zone High/Low setting issue (near bar close)

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

    Zone High/Low setting issue (near bar close)

    Hello everyone,

    I'm encountering an issue with my custom NinjaTrader strategy with ninjascript (originially with strategy builder, then I unlocked the code), and I'm hoping someone here might be able to shed some light on it. The strategy is designed to calculate and track the high and low of a specific time zone (a 30m zone from 9:30 AM EST to 9:59 AM EST and then use those values during a breakout strategy that must have a breakout within the next 10 minutes of the zone (10:00am - 10:10am).

    The problem arises right at the end of the zone timeframe (9:59 AM). For some reason, towards the very last bar of the zone, the ZoneHigh and ZoneLow values seem to revert to the Close of the same bar instead of remaining consistent. Here’s a snippet of the ninjascript output (ZoneHigh should be 5941.75, and ZoneLow should be 5924.5 as seen on some of the lines in output):

    Code:
    ZoneHigh is 5926.25at 11/15/2024 6:58:59 AM
    ZoneLow is 5926.25at 11/15/2024 6:58:59 AM
    ZoneHigh is 5926.25at 11/15/2024 6:58:59 AM
    ZoneLow is 5926.25at 11/15/2024 6:58:59 AM
    ZoneHigh is 5941.75at 11/15/2024 6:59:00 AM
    ZoneLow is 5924.5at 11/15/2024 6:59:00 AM
    ZoneHigh is 5941.75at 11/15/2024 6:59:00 AM
    ZoneLow is 5924.5at 11/15/2024 6:59:00 AM
    ZoneHigh is 5941.75at 11/15/2024 6:59:00 AM
    ZoneLow is 5924.5at 11/15/2024 6:59:00 AM
    ZoneHigh is 5941.75at 11/15/2024 6:59:00 AM
    ZoneLow is 5924.5at 11/15/2024 6:59:00 AM
    ZoneHigh is 5926.25at 11/15/2024 6:58:59 AM
    ZoneLow is 5926.25at 11/15/2024 6:58:59 AM
    As you can see, the values jump back and forth in time, which doesn’t make sense. It seems like the logic is calculating correctly for most of the period but then suddenly "goes back in time" to pick up values from the close of the current bar or resets incorrectly.

    I’ve been trying to debug this for many hours but can’t seem to figure out why the ZoneHigh and ZoneLow are not consistent at the end of the period. Here is my code:

    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class Dero30mStrat : Strategy
        {
            private double ZoneHigh;
            private double ZoneLow;
            private bool ZoneComplete;
            private bool TradeEntered;
            private int Period;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Strategy here.";
                    Name                                        = "Dero30mStrat";
                    Calculate                                    = Calculate.OnEachTick;
                    EntriesPerDirection                            = 1;
                    EntryHandling                                = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = true;
                    ExitOnSessionCloseSeconds                    = 30;
                    IsFillLimitOnTouch                            = false;
                    MaximumBarsLookBack                            = MaximumBarsLookBack.Infinite;
                    OrderFillResolution                            = OrderFillResolution.Standard;
                    Slippage                                    = 0;
                    StartBehavior                                = StartBehavior.WaitUntilFlat;
                    TimeInForce                                    = TimeInForce.Gtc;
                    TraceOrders                                    = false;
                    RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling                            = StopTargetHandling.ByStrategyPosition;
                    BarsRequiredToTrade                            = 20;
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
                    IsInstantiatedOnEachOptimizationIteration    = true;
                    ZoneStartTime                        = DateTime.Parse("06:30", System.Globalization.CultureInfo.InvariantCulture);
                    ZoneEndTime                        = DateTime.Parse("6:59", System.Globalization.CultureInfo.InvariantCulture);
                    BreakoutStartTime                        = DateTime.Parse("7:00", System.Globalization.CultureInfo.InvariantCulture);
                    BreakoutEndTime                        = DateTime.Parse("7:10", System.Globalization.CultureInfo.InvariantCulture);
                    TicksAboveHigh                    = 1;
                    TicksBelowLow                    = 1;
                    ProfitTargetTicks                    = 14;
                    StopLossTicks                    = 14;
                    ZoneHigh                    = 0;
                    ZoneLow                    = 0;
                    ZoneComplete                    = false;
                    TradeEntered                    = false;
                    Period                    = 30;
                }
                else if (State == State.Configure)
                {
                    AddDataSeries("ES 12-24", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
                    AddDataSeries("ES 12-24", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
                    SetProfitTarget("", CalculationMode.Ticks, ProfitTargetTicks);
                    SetStopLoss("", CalculationMode.Ticks, StopLossTicks, false);
                }
                
            }
    
            protected override void OnBarUpdate()
            {
            
                if (CurrentBar < Period)
                    return;
                
                if (Bars.IsFirstBarOfSession)
                {
                    ZoneHigh = High[0];
                    ZoneLow = Low[0];
    //                ZoneComplete = false;
                    Print("ZoneHigh At Start is " + ZoneHigh + "at " + Time[0]);
                    Print("ZoneHigh At Start is " + ZoneLow + "at " + Time[0]);
                    Print("Bar number " + CurrentBar + " was the first bar processed of the session at " + Time[0]);
                }
                
                // Set 1
                // Set Zone High and Low within the specified time range
                if ((Times[0][0].TimeOfDay >= ZoneStartTime.TimeOfDay)
                     && (Times[0][0].TimeOfDay <= ZoneEndTime.TimeOfDay))
                {
                    ZoneHigh = High[HighestBar(High, Period)];
                    ZoneLow = Low[LowestBar(Low, Period)];
                    Print("ZoneHigh is " + ZoneHigh + " at " + Time[0]);
                    Print("ZoneLow is " + ZoneLow + " at " + Time[0]);
                }
                
                 // Set 2
                // Mark the zone as complete after ZoneEndTime
    //            if (Times[0][0].TimeOfDay >= ZoneEndTime.TimeOfDay)
    //            {
    //                ZoneComplete = true;
    //            }
                
                 // Set 3
                // Entry Conditions
                if (
                     // Time is between breakoutstart and end time
                    ((Times[0][0].TimeOfDay >= BreakoutStartTime.TimeOfDay)
                     && (Times[0][0].TimeOfDay <= BreakoutEndTime.TimeOfDay))
                     // price goes above zone
                     && (CrossAbove(Close, ZoneHigh, 1))
    //                 && (ZoneComplete == true)
                     && (TradeEntered == false)
                     && (BarsInProgress == 1))
                {
                    EnterLong(1, Convert.ToInt32(DefaultQuantity), @"Long");
                    TradeEntered = true;
                }
                
                 // Set 4
                else if (
                     // Time is between breakoutstart and end time
                    ((Times[0][0].TimeOfDay >= BreakoutStartTime.TimeOfDay)
                     && (Times[0][0].TimeOfDay <= BreakoutEndTime.TimeOfDay))
                     // price goes below zone
                     && (CrossBelow(Close, ZoneLow, 1))
    //                 && (ZoneComplete == true)
                     && (TradeEntered == false)
                     && (BarsInProgress == 1))
                {
                    EnterShort(1, Convert.ToInt32(DefaultQuantity), @"Short");
                    TradeEntered = true;
                }
                
                 // Set 5
                // Reset trade entry flag after BreakoutEndTime to allow trades on next day
                if (Times[0][0].TimeOfDay > BreakoutEndTime.TimeOfDay)
                {
                    TradeEntered = false;
                }
                
            }
    
            #region Properties
            [NinjaScriptProperty]
            [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
            [Display(Name="ZoneStartTime", Order=1, GroupName="Parameters")]
            public DateTime ZoneStartTime
            { get; set; }
    
            [NinjaScriptProperty]
            [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
            [Display(Name="ZoneEndTime", Order=2, GroupName="Parameters")]
            public DateTime ZoneEndTime
            { get; set; }
    
            [NinjaScriptProperty]
            [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
            [Display(Name="BreakoutStartTime", Order=3, GroupName="Parameters")]
            public DateTime BreakoutStartTime
            { get; set; }
    
            [NinjaScriptProperty]
            [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
            [Display(Name="BreakoutEndTime", Order=4, GroupName="Parameters")]
            public DateTime BreakoutEndTime
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, int.MaxValue)]
            [Display(Name="TicksAboveHigh", Order=5, GroupName="Parameters")]
            public int TicksAboveHigh
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, int.MaxValue)]
            [Display(Name="TicksBelowLow", Order=6, GroupName="Parameters")]
            public int TicksBelowLow
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, int.MaxValue)]
            [Display(Name="ProfitTargetTicks", Order=7, GroupName="Parameters")]
            public int ProfitTargetTicks
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, int.MaxValue)]
            [Display(Name="StopLossTicks", Order=8, GroupName="Parameters")]
            public int StopLossTicks
            { get; set; }
            #endregion
    
        }
    }​

    ​​​Has anyone run into a similar issue, or could someone suggest what might be causing this behavior? Any help would be greatly appreciated!

    #2
    Hello

    In the code you provided you are using multiple series so it is likely a result of that. Which of the 3 series being used are the prints intended to happen for?

    Comment


      #3
      I'm not 100% sure, but from my understanding I think I'll want it for the tick series because the way I want the strategy to work is to make it so when price at any point crosses the high/low of the zone (not waiting for any candle close on a time chart like 1m), it enters a position immediately. I added 1 minute series because I thought I needed 1 minute data to calculate the high and low of the zone.

      Alright, I just did some testing, I added a condition for the BarsInProgress so that in the block of code where its calculating the zone, it uses BarsInProgress == 0 which is 1 minute data, and in the block of code where it enters and exits it uses BarsInProgress == 1 which is the tickdata. This literally fixed my issue!! thank you so much for the help. I spent so long trying to fix this, can't believe it was just a simple solution.

      One more thing, now I'm getting another issue. On the candle that takes the trade, the entry is as expected, but exit executions are not accurate. I believe this has to do with how it calculates whether the trade hit TP or SL. Check the images I attached. The images with "realtime" are when I took the trade live with an ATM strategy setup the same way the script entry and exits should be set up. The other one and the one with "script" are the backtest. Entries are fine, but the way the exit of the trade is calculated is incorrect. What could be the issue here?
      Click image for larger version

Name:	image.png
Views:	103
Size:	21.6 KB
ID:	1325203Click image for larger version

Name:	image.png
Views:	68
Size:	26.3 KB
ID:	1325204

      Click image for larger version

Name:	image.png
Views:	72
Size:	5.4 KB
ID:	1325205Click image for larger version

Name:	image.png
Views:	65
Size:	10.7 KB
ID:	1325206​​​​​​

      Comment


        #4
        Hello Aropreneur,

        When using the Set methods for targets those will be associated with the primary series, I believe in this case you will need to submit the orders using the Exit methods instead so you can specify a BarsInProgress when submitting those orders.

        Comment


          #5
          Hey Jesse, thanks for the quick response.

          I think you're right, I initially tried with set methods and it still gave same result.

          I read your message and tried to implement the exit methods, but my strategy is now closing right at the end of market close. I can't seem to figure it out. Here is my added code using the exit methods to exit my strategy. What should I fix? How am I supposed to implement it so it works properly?

          Code:
          if (Position.MarketPosition == MarketPosition.Long)
          {
          ExitLongStopLimit(1, true, Convert.ToInt32(DefaultQuantity), Position.AveragePrice + (ProfitTargetTicks * TickSize), Position.AveragePrice - (StopLossTicks * TickSize), @"Exit", @"Long");
          }
          
          if (Position.MarketPosition == MarketPosition.Short)
          {
          ExitShortStopLimit(1, true, Convert.ToInt32(DefaultQuantity), Position.AveragePrice - (ProfitTargetTicks * TickSize), Position.AveragePrice + (StopLossTicks * TickSize), @"Exit", @"Short");
          }


          Edit: I've been trying multiple methods, but for some reason when I print the entry price by doing Print(Position.AveragePrice); to ninjascript output, I get price = 0. That's probably why the strategy is not executing the exit method where it should since I can't indicate the actual price of entry. Maybe that's what I need to fix?
          Last edited by Aropreneur; 11-20-2024, 10:11 PM.

          Comment


            #6
            Hello Aropreneur,

            If the strategy is closing at the session close that likely means the price used for the order is not being met so it remains unfilled. You could print the prices that are being calculated to check where its being placed.

            Where do you currently have this code in your script, is that in OnBarUpdate?

            Comment


              #7
              Yes, it's placed in the OnBarUpdate() towards the end of the code, here is the full code:

              Code:
              namespace NinjaTrader.NinjaScript.Strategies
              {
                  public class Dero30mStrat : Strategy
                  {
                      private double ZoneHigh;
                      private double ZoneLow;
                      private bool ZoneComplete;
                      private bool TradeEntered;
                      private int Period;
              
                      protected override void OnStateChange()
                      {
                          if (State == State.SetDefaults)
                          {
                              Description                                    = @"Enter the description for your new custom Strategy here.";
                              Name                                        = "Dero30mStrat";
                              Calculate                                    = Calculate.OnEachTick;
                              EntriesPerDirection                            = 1;
                              EntryHandling                                = EntryHandling.AllEntries;
                              IsExitOnSessionCloseStrategy                = true;
                              ExitOnSessionCloseSeconds                    = 30;
                              IsFillLimitOnTouch                            = false;
                              MaximumBarsLookBack                            = MaximumBarsLookBack.Infinite;
                              OrderFillResolution                            = OrderFillResolution.Standard;
                              Slippage                                    = 0;
                              StartBehavior                                = StartBehavior.WaitUntilFlat;
                              TimeInForce                                    = TimeInForce.Gtc;
                              TraceOrders                                    = false;
                              RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                              StopTargetHandling                            = StopTargetHandling.ByStrategyPosition;
                              BarsRequiredToTrade                            = 20;
                              // Disable this property for performance gains in Strategy Analyzer optimizations
                              // See the Help Guide for additional information
                              IsInstantiatedOnEachOptimizationIteration    = true;
                              ZoneStartTime                        = DateTime.Parse("06:30", System.Globalization.CultureInfo.InvariantCulture);
                              ZoneEndTime                        = DateTime.Parse("6:59", System.Globalization.CultureInfo.InvariantCulture);
                              BreakoutStartTime                        = DateTime.Parse("7:00", System.Globalization.CultureInfo.InvariantCulture);
                              BreakoutEndTime                        = DateTime.Parse("7:10", System.Globalization.CultureInfo.InvariantCulture);
                              TicksAboveHigh                    = 1;
                              TicksBelowLow                    = 1;
                              ProfitTargetTicks                    = 14;
                              StopLossTicks                    = 14;
                              ZoneHigh                    = 0;
                              ZoneLow                    = 0;
                              ZoneComplete                    = false;
                              TradeEntered                    = false;
                              Period                    = 30;            
                              
                          }
                          else if (State == State.Configure)
                          {
                              //AddDataSeries("ES 12-24", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
                              AddDataSeries("ES 12-24", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
              //                SetProfitTarget("", CalculationMode.Ticks, ProfitTargetTicks);
              //                SetStopLoss("", CalculationMode.Ticks, StopLossTicks, false);
              
                              
                          }
                          
                      }
              
                      protected override void OnBarUpdate()
                      {
                      
                          if (CurrentBar < Period)
                              return;
                          
                          if (Bars.IsFirstBarOfSession && BarsInProgress == 0)
                          {
                              ZoneHigh = High[0];
                              ZoneLow = Low[0];
                              Print("ZoneHigh At Start is " + ZoneHigh + "at " + Time[0]);
                              Print("ZoneHigh At Start is " + ZoneLow + "at " + Time[0]);
                              Print("Bar number " + CurrentBar + " was the first bar processed of the session at " + Time[0]);
                          }
                          
                          // Set 1
                          // Set Zone High and Low within the specified time range
                          if ((Times[0][0].TimeOfDay >= ZoneStartTime.TimeOfDay)
                               && (Times[0][0].TimeOfDay <= ZoneEndTime.TimeOfDay)
                               && (BarsInProgress == 0))
                          {
                              ZoneHigh = High[HighestBar(High, Period)];
                              ZoneLow = Low[LowestBar(Low, Period)];
                              Print("ZoneHigh is " + ZoneHigh + " at " + Time[0]);
                              Print("ZoneLow is " + ZoneLow + " at " + Time[0]);
                          }
                          
                           // Set 3
                          // Entry Conditions
                          if (
                               // Time is between breakoutstart and end time
                              ((Times[0][0].TimeOfDay >= BreakoutStartTime.TimeOfDay)
                               && (Times[0][0].TimeOfDay <= BreakoutEndTime.TimeOfDay))
                               // price goes above zone
                               && (CrossAbove(Close, ZoneHigh, 1))
                               && (TradeEntered == false)
                               && (BarsInProgress == 1))
                          {
                              EnterLong(1, Convert.ToInt32(DefaultQuantity), @"Long");
                              Print("Entry at " + Position.AveragePrice);
                              Print("TP at " + (Position.AveragePrice - (ProfitTargetTicks * TickSize)));
              //                Print(price.ToString("N2"));
              //                SetStopLoss("", CalculationMode.Ticks, StopLossTicks, false);
              //                SetProfitTarget("", CalculationMode.Ticks, ProfitTargetTicks);
                              TradeEntered = true;
                          }
                          
                           // Set 4
                          else if (
                               // Time is between breakoutstart and end time
                              ((Times[0][0].TimeOfDay >= BreakoutStartTime.TimeOfDay)
                               && (Times[0][0].TimeOfDay <= BreakoutEndTime.TimeOfDay))
                               // price goes below zone
                               && (CrossBelow(Close, ZoneLow, 1))
                               && (TradeEntered == false)
                               && (BarsInProgress == 1))
                          {
                              EnterShort(1, Convert.ToInt32(DefaultQuantity), @"Short");
                              Print("Entry at " + Position.AveragePrice);
                              Print("TP at " + Position.AveragePrice + (ProfitTargetTicks * TickSize));
              //                Print(price.ToString("N2"));
              //                SetStopLoss("", CalculationMode.Ticks, StopLossTicks, false);
              //                SetProfitTarget("", CalculationMode.Ticks, ProfitTargetTicks);
                              TradeEntered = true;
                          }
              
                          ExitLongStopLimit(1, true, Convert.ToInt32(DefaultQuantity), Position.AveragePrice + (ProfitTargetTicks * TickSize), Position.AveragePrice - (StopLossTicks * TickSize), @"Exit", @"Long");
                          
                          
                          ExitShortStopLimit(1, true, Convert.ToInt32(DefaultQuantity), Position.AveragePrice - (ProfitTargetTicks * TickSize), Position.AveragePrice + (StopLossTicks * TickSize), @"Exit", @"Short");
                          
                           // Set 5
                          // Reset trade entry flag after BreakoutEndTime to allow trades on next day
                          if (Times[0][0].TimeOfDay > BreakoutEndTime.TimeOfDay)
                          {
                              TradeEntered = false;
                          }
                          
                      }
              
                      #region Properties
                      [NinjaScriptProperty]
                      [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
                      [Display(Name="ZoneStartTime", Order=1, GroupName="Parameters")]
                      public DateTime ZoneStartTime
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
                      [Display(Name="ZoneEndTime", Order=2, GroupName="Parameters")]
                      public DateTime ZoneEndTime
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
                      [Display(Name="BreakoutStartTime", Order=3, GroupName="Parameters")]
                      public DateTime BreakoutStartTime
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
                      [Display(Name="BreakoutEndTime", Order=4, GroupName="Parameters")]
                      public DateTime BreakoutEndTime
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="TicksAboveHigh", Order=5, GroupName="Parameters")]
                      public int TicksAboveHigh
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="TicksBelowLow", Order=6, GroupName="Parameters")]
                      public int TicksBelowLow
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="ProfitTargetTicks", Order=7, GroupName="Parameters")]
                      public int ProfitTargetTicks
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="StopLossTicks", Order=8, GroupName="Parameters")]
                      public int StopLossTicks
                      { get; set; }
                      #endregion
              
                  }
              }​
              Also, reading up on other forums, someone mentioned that they had the same problem as me and that they tried this:

              Code:
              protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
              {
              Print(price.ToString("N2"));
              }
              and it worked for them. Is this the thing I need to use? If so how do I implement it properly to give me my entry price so I can accurately calculate my profit target and stop loss orders?

              Also, when I print (line 126, 127):

              Code:
              Print("Entry at " + Position.AveragePrice);
              Print("TP at " + (Position.AveragePrice - (ProfitTargetTicks * TickSize)));


              to ninjatrader output, I get this:

              Code:
              Entry at 0
              TP at 03.5

              So I believe the issue is I need to get the right price of entry for the calculation to work? Because I'm thinking the 3.5 is correct since my profit target is at 3.5 points (14 ticks is what I put as ProfitTargetTicks); But I can't figure out how to get the right entry price.
              Last edited by Aropreneur; 11-21-2024, 12:22 PM.

              Comment


                #8
                Hello Aropreneur,

                In the code you provided the exit methods are not contained in a position condition so they can be called when there is no position and the average price is 0.

                The position also does not change immediately on the following line of code, you have to wait for the position to change which can take some time so it likely will happen on a different OnBarUpdate event than when you call the entry.

                Comment


                  #9
                  Okay, I understand that part. So when I include the code from the previous message I sent which was:

                  Code:
                  if (Position.MarketPosition == MarketPosition.Long)
                              {
                                  ExitLongStopLimit(1, true, Convert.ToInt32(DefaultQuantity), Position.AveragePrice + (ProfitTargetTicks * TickSize), Position.AveragePrice - (StopLossTicks * TickSize), @"Exit", @"Long");
                                  Print("Entry at " + Position.AveragePrice);
                              }
                              
                              if (Position.MarketPosition == MarketPosition.Short)
                              {
                                  ExitShortStopLimit(1, true, Convert.ToInt32(DefaultQuantity), Position.AveragePrice - (ProfitTargetTicks * TickSize), Position.AveragePrice + (StopLossTicks * TickSize), @"Exit", @"Short");
                                  Print("Entry at " + Position.AveragePrice);
                              }​​​
                  Inside of the OnBarUpdate, it still exits position at the end of session, but in the ninjascript output, it prints the accurate entry value for each trade. So is my calculation wrong? I can't seem to understand why the calculation is incorrect or why it's closing at end of session. I've tried adding a condition to make sure it's using tick series and I tried it with 1-minute series too but neither made difference. I'm stuck.

                  Comment


                    #10
                    Hello Aropreneur,

                    You need to print the price you are using in addition to the close price to see if it ever reaches that value. If you reach the end of the session and see exit on session close that means the targets were not hit.

                    Comment


                      #11

                      The values print so fast I can barely keep up on the ninjascript output (I think this is because of the tick series), but I also had another question about this possibly being the reason that it doesn't exit properly. Do I have to use standard order fill resolution, or am I supposed to use "high", because I've been using standard mode. Could that be the reason why it's not exiting properly? If so, how would I implement more granular resolution because I've been trying to implement it and can't figure it out.
                      Thanks!

                      Edit: Okay, I've got it to process the strategy with high order fill resolution (Tick 1), but it still does the exact same thing that the strategy did with standard order fill res.

                      Last edited by Aropreneur; 11-25-2024, 08:44 PM.

                      Comment


                        #12
                        Hello Aropreneur,

                        The fill resolution is only for historical fills, if the script is working that way in realtime that is not related. Based on your comment it seems that is not related.

                        I couldn't say why it may not be exiting because I don't know how your exit condition worked in that use case. The only way to address that would be to output what the script is doing at that time and the variables that are used in your conditions. Knowing what values the script is seeing when you think it should have exited will let you explore why the condition was not true to exit at that time.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by NullPointStrategies, Yesterday, 05:17 AM
                        0 responses
                        54 views
                        0 likes
                        Last Post NullPointStrategies  
                        Started by argusthome, 03-08-2026, 10:06 AM
                        0 responses
                        130 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        72 views
                        0 likes
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        44 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Started by TheRealMorford, 03-05-2026, 06:15 PM
                        0 responses
                        49 views
                        0 likes
                        Last Post TheRealMorford  
                        Working...
                        X