Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Restrict strategy to only one order per trend

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

    Restrict strategy to only one order per trend

    The CASUNoRep NinjaTrader strategy identifies an uptrend by checking if the close prices of the last three bars are progressively higher. When this condition is met, it calculates a limit price based on the current high minus a 40-tick offset and places a limit order to enter a long position with 2 contracts, It uses a custom series to track the latest custom high and update the limit price accordingly.
    Two more conditions are
    01 takes only one order per trend, ie one long order when the trend changes from bearish to bullish each time.

    So to make that condition work i came up with a mechanism:

    A variable that checks whether the order is placed or not "
    private bool OrderPlaced;
    "
    A condition that checks if the trend is bearish: and if the trend is bearish then it resets the variable to false so that the strategy can place the order again.
    // Set 1
    if ((Low[0] < Low[1])
    && (Low[1] < Low[2]))
    {
    OrderPlaced = false;
    }
    Now that is working great, so where's the problem, let me explain:
    Look i place limit orders and each time price moves up the limit order will also move up, please check set 2, 3, 4, and 5 for that. If yo see the orderplaced flag is set to true right after the EnterLongLimit, ao when a new high is detected and the strategy replaces the previous limit order by a new higher limit order, it finds the orderplaced flag true and it cancels the order.
    // Set 5
    if ((Close[0] > Close[1])
    && (Close[1] > Close[2])
    && (LimitPrice > 0)
    && (OrderPlaced == false))
    {
    EnterLongLimit(2, LimitPrice, "");
    OrderPlaced = true;
    }
    So to avoid that situation i creatd another set and moved the orderpaced flag there:
    // Set 6
    if (Position.MarketPosition == MarketPosition.Long)
    {
    OrderPlaced = true;
    }
    But that condition never works it just places recurrent order as soon as the previous one is fulfilled either profit or loss.

    So what i want to achieve is to set the order place flag to true once the order is filled not after the limit order is placed. Please help me!

    Below is the complete script of the strategy builder.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class CASUNoRep : Strategy
    {
    private double LimitPrice;
    private bool OrderPlaced;
    private bool IsBearish;


    private Series<double> CustomHighSeries;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter Long After Price Drops";
    Name = "Chart116UpTrendNoRep";
    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;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    LimitPrice = 0;
    OrderPlaced = false;
    IsBearish = false;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    CustomHighSeries = new Series<double>(this);
    SetProfitTarget(CalculationMode.Ticks, 20);
    SetStopLoss(CalculationMode.Ticks, 60);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 2)
    return;

    // Set 1
    if ((Low[0] < Low[1])
    && (Low[1] < Low[2]))
    {
    OrderPlaced = false;
    }

    // Set 2
    if (CurrentBars[0] > 0)
    {
    CustomHighSeries[0] = CustomHighSeries[1];
    }

    // Set 3
    if (CurrentBars[0] == 1)
    {
    CustomHighSeries[0] = High[0];
    }

    // Set 4
    if ((Close[0] > Close[1])
    && (Close[1] > Close[2]))
    {
    CustomHighSeries[0] = High[0];
    LimitPrice = (CustomHighSeries[0] + (-40 * TickSize)) ;
    }

    // Set 5
    if ((Close[0] > Close[1])
    && (Close[1] > Close[2])
    && (LimitPrice > 0)
    && (OrderPlaced == false))
    {
    EnterLongLimit(2, LimitPrice, "");
    OrderPlaced = true;
    }

    }
    }
    }
    I have also attached screenshots of the strategy builder for reference




    Click image for larger version

Name:	3.png
Views:	121
Size:	29.1 KB
ID:	1328534 Click image for larger version

Name:	4.png
Views:	165
Size:	29.9 KB
ID:	1328532 Click image for larger version

Name:	5.png
Views:	121
Size:	29.5 KB
ID:	1328533 Click image for larger version

Name:	6.png
Views:	122
Size:	33.2 KB
ID:	1328536 Click image for larger version

Name:	7.png
Views:	122
Size:	32.2 KB
ID:	1328535

    #2
    Hello maaxk,

    Add debugging prints to understand the behavior.

    Below is a link to a support article on adding debugging prints to understand behavior. Please watch the 'Debugging with the Strategy Builder' video.


    Setting the bool to true when the position is long sounds like the right approach.

    However, it would be on the next bar update after the position has changed.

    Print the bar time and a label in the condition set that is setting the bool to true.
    Print the bar time and a label in the condition set that is setting the bool to false.

    Enable TraceOrders.

    This will let you know when the conditions are evaluating as true.

    Save the output and attach this to your next post.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thanks for the update, its really helpful and you are right
      Setting the orderPlaced flag true should be on the next bar update after the position has changed.
      and that is what i am trying to figure out since 3 days but i am missing the logic so i have done as you asked me to print the output and here are the snnapshots:

      Click image for larger version

Name:	10.png
Views:	122
Size:	31.5 KB
ID:	1328562 Click image for larger version

Name:	11.png
Views:	116
Size:	70.5 KB
ID:	1328563

      Thanks & regards
      Maaz Khan

      Comment


        #4
        Hello maaxk,

        The output is not showing the date and time (Time > Date series).

        Are you certain there is not another print added that is not including a string for the date and time?

        Adding a label to identify which set a print is for is helpful if there are multiple prints. For example you could add a string for 'Set 1' in set 1 to know this condition evaluated as true and at what date and time.

        Is the print before or after the bool value is being assigned?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          The print is for after the value is assigned.

          Here's another screenshot:
          Click image for larger version  Name:	image.png Views:	0 Size:	52.5 KB ID:	1328566
          This is when the value is se to true:

          Click image for larger version

Name:	image.png
Views:	115
Size:	48.7 KB
ID:	1328567

          Thanks & Regards
          Maaz Khan
          Last edited by maaxk; 12-19-2024, 11:46 AM.

          Comment


            #6
            Hello Maaz,

            To confirm, in the 'Do the following' section the variable assignment is above the print call, is this correct?

            Is there only this one print called in all of the conditions?

            Which condition set is this print called from?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              Yes the variable assignment is above the print call and yes there is only one print call called.

              Thanks & Regards

              Comment


                #8
                Hello maaxk,

                This sounds like an impossibility.

                If there is only one print, and the bool assigned a value above the print, the print should always have the same value.

                If the bool is being assigned true, and then the bool is printed, it should always be true, and would never be false.
                If the bool is being assigned false, and then the bool is printed, it should always be false, and would never be true.

                I feel that either you have multiple prints, or that you are printing the bool value before assigning the value.


                However, what we really need is to identify which condition set the print is being called from.

                In post # 2 I've requested that you add a print to two different condition sets and that a label be added (to identify the condition set).
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Chelsea,

                  Here's the code o the strategy

                  namespace NinjaTrader.NinjaScript.Strategies
                  {
                  public class CASUNoRep : Strategy
                  {
                  private double LimitPrice;
                  private bool OrderPlaced;
                  private bool IsBearish;


                  private Series<double> CustomHighSeries;

                  protected override void OnStateChange()
                  {
                  if (State == State.SetDefaults)
                  {
                  Description = @"Enter Long After Price Drops";
                  Name = "Chart116UpTrendNoRep";
                  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;
                  // Disable this property for performance gains in Strategy Analyzer optimizations
                  // See the Help Guide for additional information
                  IsInstantiatedOnEachOptimizationIteration = true;
                  LimitPrice = 0;
                  OrderPlaced = false;
                  IsBearish = false;
                  }
                  else if (State == State.Configure)
                  {
                  }
                  else if (State == State.DataLoaded)
                  {
                  CustomHighSeries = new Series<double>(this);
                  SetProfitTarget(CalculationMode.Ticks, 20);
                  SetStopLoss(CalculationMode.Ticks, 60);
                  }
                  }

                  protected override void OnBarUpdate()
                  {
                  if (BarsInProgress != 0)
                  return;

                  if (CurrentBars[0] < 2)
                  return;

                  // Set 1
                  if ((Low[0] < Low[1])
                  && (Low[1] < Low[2]))
                  {
                  OrderPlaced = false;
                  }

                  // Set 2
                  if (CurrentBars[0] > 0)
                  {
                  CustomHighSeries[0] = CustomHighSeries[1];
                  }

                  // Set 3
                  if (CurrentBars[0] == 1)
                  {
                  CustomHighSeries[0] = High[0];
                  }

                  // Set 4
                  if ((Close[0] > Close[1])
                  && (Close[1] > Close[2]))
                  {
                  CustomHighSeries[0] = High[0];
                  LimitPrice = (CustomHighSeries[0] + (-40 * TickSize)) ;
                  }

                  // Set 5
                  if ((Close[0] > Close[1])
                  && (Close[1] > Close[2])
                  && (LimitPrice > 0)
                  && (OrderPlaced == false))
                  {
                  EnterLongLimit(2, LimitPrice, "");
                  OrderPlaced = true;
                  }

                  Print(Convert.ToString(Times[0][0].TimeOfDay) + @" | OrderPlaced Value: " + Convert.ToString(OrderPlaced));
                  }
                  }
                  }​

                  Thanks & Regards

                  Comment


                    #10
                    Hello maaxk,

                    The print is showing outside of any condition sets.

                    We are wanting to see when the condition sets are evaluating as true.

                    The print I am expecting to be in the 'Do the following' section of the same condition set that is setting the bool.

                    I see the bool is set in Condition Set 1 and Condition Set 5.

                    There are no prints above the bool assignment in these sets.

                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Chelsea,

                      Let me add these prints in the conditions 1 and 5.

                      Thanks & Regards

                      Comment


                        #12
                        Hello Chelsea,

                        I have done as you asked me to do in addition i added one more print in the set 4 to print the limit price as well, i thought it might help you out.
                        Below is the output:
                        12:22:46.1970000 | OrderPlaced Condition 1 Value: False
                        12:22:46.5030000 | OrderPlaced Condition 1 Value: False
                        12:22:46.5050000 | OrderPlaced Condition 1 Value: False
                        12:22:46.5120000 | OrderPlaced Condition 1 Value: False
                        12:22:46.5140000 | OrderPlaced Condition 1 Value: False
                        12:22:46.6220000 | OrderPlaced Condition 1 Value: False
                        12:22:47.1390000 | OrderPlaced Condition 1 Value: False
                        12:24:28.2550000 | Limit Price Value: 21506.25
                        12:24:28.2550000 | OrderPlaced Condition 5 Value: True
                        12:24:28.7350000 | Limit Price Value: 21506.75
                        12:24:28.7350000 | Limit Price Value: 21507.25
                        12:24:29.0620000 | Limit Price Value: 21507.75
                        12:24:29.2460000 | Limit Price Value: 21508.25
                        12:25:40.7000000 | Limit Price Value: 21508.75
                        12:25:40.8160000 | Limit Price Value: 21509.25
                        12:26:27.9920000 | Limit Price Value: 21509.75
                        12:26:27.9980000 | Limit Price Value: 21510.25
                        12:26:27.9980000 | Limit Price Value: 21510.75
                        12:26:27.9990000 | Limit Price Value: 21511.25
                        12:26:27.9990000 | Limit Price Value: 21511.75
                        12:26:27.9990000 | Limit Price Value: 21512.25
                        12:26:28.0130000 | Limit Price Value: 21512.75
                        12:26:28.0280000 | Limit Price Value: 21513.25
                        12:26:28.0280000 | Limit Price Value: 21513.75
                        12:26:28.0280000 | Limit Price Value: 21514.25
                        12:26:28.0280000 | Limit Price Value: 21514.75
                        12:26:29.9810000 | Limit Price Value: 21515.25
                        12:26:29.9890000 | Limit Price Value: 21515.75
                        12:26:30.3370000 | Limit Price Value: 21516.25
                        12:26:30.4100000 | Limit Price Value: 21516.75
                        12:26:30.5730000 | Limit Price Value: 21517.25
                        12:26:41.6230000 | Limit Price Value: 21517.75
                        12:27:00.3850000 | Limit Price Value: 21518.25
                        12:27:00.3850000 | Limit Price Value: 21518.75
                        12:27:00.4110000 | Limit Price Value: 21519.25
                        12:28:06.2860000 | Limit Price Value: 21519.75
                        12:28:06.2930000 | Limit Price Value: 21520.25
                        12:28:06.3070000 | Limit Price Value: 21520.75
                        12:28:06.3070000 | Limit Price Value: 21521.25
                        12:28:06.3070000 | Limit Price Value: 21521.75
                        12:28:06.5700000 | Limit Price Value: 21522.25
                        12:28:06.5810000 | Limit Price Value: 21522.75
                        12:28:06.5830000 | Limit Price Value: 21523.25
                        12:28:06.5830000 | Limit Price Value: 21523.75
                        12:28:06.5830000 | Limit Price Value: 21524.25
                        12:28:06.5830000 | Limit Price Value: 21524.75
                        12:28:07.7770000 | Limit Price Value: 21525.25
                        12:28:07.7990000 | Limit Price Value: 21525.75
                        12:28:07.7990000 | Limit Price Value: 21526.25
                        12:28:07.8110000 | Limit Price Value: 21526.75
                        12:28:08 | Limit Price Value: 21527.25
                        12:28:08.2690000 | Limit Price Value: 21527.75
                        12:28:08.3220000 | Limit Price Value: 21528.25
                        12:40:49.9150000 | Limit Price Value: 21528.75
                        12:40:49.9150000 | Limit Price Value: 21529.25
                        12:40:49.9150000 | Limit Price Value: 21529.75
                        12:40:51.5070000 | Limit Price Value: 21530.25
                        12:40:51.5180000 | Limit Price Value: 21530.75
                        12:40:52.0700000 | Limit Price Value: 21531.25
                        12:40:52.0700000 | Limit Price Value: 21531.75
                        12:40:52.0780000 | Limit Price Value: 21532.25
                        12:40:52.0780000 | Limit Price Value: 21532.75
                        12:40:52.0780000 | Limit Price Value: 21533.25
                        12:40:57.8350000 | Limit Price Value: 21533.75
                        12:40:57.8350000 | Limit Price Value: 21534.25
                        12:40:57.8980000 | Limit Price Value: 21534.75
                        12:42:22.2450000 | Limit Price Value: 21535.25
                        12:42:22.4270000 | Limit Price Value: 21535.75
                        12:42:22.8790000 | Limit Price Value: 21536.25
                        12:42:22.9330000 | Limit Price Value: 21536.75
                        12:42:22.9330000 | Limit Price Value: 21537.25
                        12:42:24.1560000 | Limit Price Value: 21537.75
                        12:42:26.5900000 | Limit Price Value: 21538.25
                        12:51:32.3370000 | Limit Price Value: 21538.75
                        12:52:46.9730000 | Limit Price Value: 21539.25
                        12:52:47.2030000 | Limit Price Value: 21539.75
                        12:52:47.2230000 | Limit Price Value: 21540.25
                        12:52:47.2230000 | Limit Price Value: 21540.75
                        12:52:47.2310000 | Limit Price Value: 21541.25
                        12:57:03.8990000 | Limit Price Value: 21541.75
                        12:57:04.7480000 | Limit Price Value: 21542.25
                        12:57:04.8030000 | Limit Price Value: 21542.75
                        12:57:04.8230000 | Limit Price Value: 21543.25
                        12:57:04.8320000 | Limit Price Value: 21543.75
                        12:57:05.0350000 | Limit Price Value: 21544.25
                        12:57:06.2170000 | Limit Price Value: 21544.75
                        12:57:06.3240000 | Limit Price Value: 21545.25
                        12:57:06.9300000 | Limit Price Value: 21545.75
                        12:57:07.0980000 | Limit Price Value: 21546.25
                        12:57:07.4980000 | Limit Price Value: 21546.75
                        12:57:07.5220000 | Limit Price Value: 21547.25
                        12:57:16.2300000 | Limit Price Value: 21547.75
                        12:57:17.5320000 | Limit Price Value: 21548.25
                        12:57:17.6450000 | Limit Price Value: 21548.75
                        12:57:17.6570000 | Limit Price Value: 21549.25
                        12:57:20.6490000 | Limit Price Value: 21549.75
                        12:57:20.6510000 | Limit Price Value: 21550.25
                        12:57:22.4830000 | Limit Price Value: 21550.75
                        12:57:22.4990000 | Limit Price Value: 21551.25
                        12:57:22.6270000 | Limit Price Value: 21551.75
                        12:57:25.2800000 | Limit Price Value: 21552.25
                        12:57:25.2800000 | Limit Price Value: 21552.75
                        12:57:26.0450000 | Limit Price Value: 21553.25
                        12:57:26.0560000 | Limit Price Value: 21553.75
                        12:57:27.6060000 | Limit Price Value: 21554.25
                        12:57:37.9460000 | Limit Price Value: 21554.75
                        12:57:38.1560000 | Limit Price Value: 21555.25
                        12:57:38.4840000 | Limit Price Value: 21555.75
                        12:58:00.6350000 | Limit Price Value: 21556.25
                        12:58:00.6660000 | Limit Price Value: 21556.75
                        12:58:00.6660000 | Limit Price Value: 21557.25
                        12:58:00.7150000 | Limit Price Value: 21557.75
                        12:58:00.7170000 | Limit Price Value: 21558.25
                        12:58:00.7240000 | Limit Price Value: 21558.75
                        12:58:00.7340000 | Limit Price Value: 21559.25
                        12:58:04.6170000 | Limit Price Value: 21559.75
                        12:58:04.6250000 | Limit Price Value: 21560.25
                        12:58:05.6710000 | Limit Price Value: 21560.75
                        12:58:05.6910000 | Limit Price Value: 21561.25
                        12:58:06.2490000 | Limit Price Value: 21561.75
                        12:58:06.3510000 | Limit Price Value: 21562.25
                        12:58:10.1060000 | Limit Price Value: 21562.75
                        12:58:34.7200000 | Limit Price Value: 21563.25
                        12:58:34.9370000 | Limit Price Value: 21563.75
                        12:58:34.9370000 | Limit Price Value: 21564.25
                        12:58:34.9370000 | Limit Price Value: 21564.75
                        12:58:36.3940000 | Limit Price Value: 21565.25
                        12:58:36.4740000 | Limit Price Value: 21565.75
                        12:58:40.9840000 | Limit Price Value: 21566.25
                        12:58:41.1660000 | Limit Price Value: 21566.75
                        12:58:41.4460000 | Limit Price Value: 21567.25
                        12:58:41.6190000 | Limit Price Value: 21567.75
                        12:58:41.6820000 | Limit Price Value: 21568.25
                        12:58:44.4320000 | Limit Price Value: 21568.75
                        12:58:44.5340000 | Limit Price Value: 21569.25
                        12:58:46.3640000 | Limit Price Value: 21569.75
                        12:58:46.3650000 | Limit Price Value: 21570.25
                        12:58:46.5120000 | Limit Price Value: 21570.75
                        12:58:46.5130000 | Limit Price Value: 21571.25
                        12:58:52.1240000 | Limit Price Value: 21571.75
                        12:58:52.2370000 | Limit Price Value: 21572.25
                        12:58:54.0450000 | Limit Price Value: 21572.75
                        12:58:54.1640000 | Limit Price Value: 21573.25
                        12:58:55.5540000 | Limit Price Value: 21573.75
                        12:58:55.6410000 | Limit Price Value: 21574.25
                        12:58:55.7760000 | Limit Price Value: 21574.75
                        12:58:56.0310000 | Limit Price Value: 21575.25
                        12:58:56.0320000 | Limit Price Value: 21575.75
                        12:58:56.0320000 | Limit Price Value: 21576.25
                        12:58:56.0320000 | Limit Price Value: 21576.75
                        12:58:57.1080000 | Limit Price Value: 21577.25
                        12:59:04.7470000 | Limit Price Value: 21577.75
                        12:59:04.7770000 | Limit Price Value: 21578.25
                        12:59:05.4550000 | Limit Price Value: 21578.75
                        12:59:15.3440000 | Limit Price Value: 21579.25
                        12:59:15.3540000 | Limit Price Value: 21579.75
                        12:59:15.3540000 | Limit Price Value: 21580.25
                        12:59:15.3620000 | Limit Price Value: 21580.75
                        12:59:15.4820000 | Limit Price Value: 21581.25
                        12:59:15.4850000 | Limit Price Value: 21581.75
                        12:59:15.4860000 | Limit Price Value: 21582.25
                        12:59:18.5300000 | Limit Price Value: 21582.75
                        12:59:19.7510000 | Limit Price Value: 21583.25
                        12:59:19.7590000 | Limit Price Value: 21583.75
                        12:59:21.4840000 | Limit Price Value: 21584.25
                        12:59:21.4870000 | Limit Price Value: 21584.75
                        12:59:21.4870000 | Limit Price Value: 21585.25
                        12:59:22.2710000 | Limit Price Value: 21585.75
                        12:59:33.7160000 | Limit Price Value: 21586.25
                        12:59:52.0710000 | Limit Price Value: 21586.75
                        12:59:53.0070000 | Limit Price Value: 21587.25
                        12:59:53.0300000 | Limit Price Value: 21587.75
                        12:59:53.0320000 | Limit Price Value: 21588.25
                        12:59:56.4220000 | Limit Price Value: 21588.75
                        12:59:56.7240000 | Limit Price Value: 21589.25
                        13:01:45.9840000 | OrderPlaced Condition 1 Value: False
                        13:01:45.9910000 | OrderPlaced Condition 1 Value: False
                        13:02:05.8200000 | OrderPlaced Condition 1 Value: False
                        13:02:05.8230000 | OrderPlaced Condition 1 Value: False
                        13:02:05.8230000 | OrderPlaced Condition 1 Value: False
                        13:02:05.8850000 | OrderPlaced Condition 1 Value: False
                        13:02:05.8990000 | OrderPlaced Condition 1 Value: False
                        13:02:05.9070000 | OrderPlaced Condition 1 Value: False
                        13:02:05.9180000 | OrderPlaced Condition 1 Value: False
                        13:02:05.9960000 | OrderPlaced Condition 1 Value: False
                        13:02:06.0860000 | OrderPlaced Condition 1 Value: False
                        13:02:07.7250000 | OrderPlaced Condition 1 Value: False
                        13:02:07.7250000 | OrderPlaced Condition 1 Value: False
                        13:03:01.0220000 | OrderPlaced Condition 1 Value: False
                        13:03:04.5690000 | OrderPlaced Condition 1 Value: False
                        13:03:04.5700000 | OrderPlaced Condition 1 Value: False
                        13:03:04.6210000 | OrderPlaced Condition 1 Value: False
                        13:03:29.4980000 | OrderPlaced Condition 1 Value: False
                        13:03:29.5190000 | OrderPlaced Condition 1 Value: False
                        13:03:29.9600000 | OrderPlaced Condition 1 Value: False
                        13:03:29.9600000 | OrderPlaced Condition 1 Value: False
                        13:03:30.0110000 | OrderPlaced Condition 1 Value: False
                        13:03:30.0160000 | OrderPlaced Condition 1 Value: False
                        13:03:30.0370000 | OrderPlaced Condition 1 Value: False
                        13:03:30.2390000 | OrderPlaced Condition 1 Value: False
                        13:03:30.2610000 | OrderPlaced Condition 1 Value: False
                        13:05:25.5840000 | OrderPlaced Condition 1 Value: False
                        13:05:25.5970000 | OrderPlaced Condition 1 Value: False
                        13:05:25.5970000 | OrderPlaced Condition 1 Value: False
                        13:05:25.6140000 | OrderPlaced Condition 1 Value: False
                        13:05:25.7100000 | OrderPlaced Condition 1 Value: False
                        13:06:29.6850000 | OrderPlaced Condition 1 Value: False
                        13:06:29.6850000 | OrderPlaced Condition 1 Value: False
                        13:06:29.8750000 | OrderPlaced Condition 1 Value: False
                        13:06:30.1150000 | OrderPlaced Condition 1 Value: False
                        13:06:30.1260000 | OrderPlaced Condition 1 Value: False
                        13:06:30.1300000 | OrderPlaced Condition 1 Value: False
                        13:06:30.1300000 | OrderPlaced Condition 1 Value: False
                        13:06:30.8090000 | OrderPlaced Condition 1 Value: False
                        13:06:30.8120000 | OrderPlaced Condition 1 Value: False
                        13:06:30.8250000 | OrderPlaced Condition 1 Value: False
                        13:06:30.8350000 | OrderPlaced Condition 1 Value: False
                        13:06:30.8350000 | OrderPlaced Condition 1 Value: False
                        13:06:32.2790000 | OrderPlaced Condition 1 Value: False
                        13:06:32.2810000 | OrderPlaced Condition 1 Value: False
                        13:06:33.2180000 | OrderPlaced Condition 1 Value: False
                        13:06:33.2180000 | OrderPlaced Condition 1 Value: False
                        13:06:35.0910000 | OrderPlaced Condition 1 Value: False
                        13:06:35.1300000 | OrderPlaced Condition 1 Value: False
                        13:06:37.7870000 | OrderPlaced Condition 1 Value: False
                        13:06:37.7870000 | OrderPlaced Condition 1 Value: False
                        13:06:37.9280000 | OrderPlaced Condition 1 Value: False
                        13:07:15.0620000 | OrderPlaced Condition 1 Value: False
                        13:07:15.0700000 | OrderPlaced Condition 1 Value: False
                        13:07:15.2060000 | OrderPlaced Condition 1 Value: False
                        13:07:15.2200000 | OrderPlaced Condition 1 Value: False
                        13:07:15.2200000 | OrderPlaced Condition 1 Value: False
                        13:07:15.2200000 | OrderPlaced Condition 1 Value: False
                        13:09:28.2460000 | OrderPlaced Condition 1 Value: False
                        13:09:28.2460000 | OrderPlaced Condition 1 Value: False
                        13:09:28.3010000 | OrderPlaced Condition 1 Value: False
                        13:09:32.4000000 | OrderPlaced Condition 1 Value: False
                        13:09:32.4260000 | OrderPlaced Condition 1 Value: False
                        13:09:32.4370000 | OrderPlaced Condition 1 Value: False
                        13:09:32.9120000 | OrderPlaced Condition 1 Value: False
                        13:09:32.9200000 | OrderPlaced Condition 1 Value: False
                        13:09:32.9200000 | OrderPlaced Condition 1 Value: False
                        13:09:33.7140000 | OrderPlaced Condition 1 Value: False
                        13:09:38.3180000 | OrderPlaced Condition 1 Value: False
                        13:10:05.3180000 | OrderPlaced Condition 1 Value: False
                        13:10:05.3180000 | OrderPlaced Condition 1 Value: False
                        13:10:05.3180000 | OrderPlaced Condition 1 Value: False
                        13:10:05.3310000 | OrderPlaced Condition 1 Value: False
                        13:10:06.7070000 | OrderPlaced Condition 1 Value: False
                        13:10:06.7130000 | OrderPlaced Condition 1 Value: False
                        13:10:06.7130000 | OrderPlaced Condition 1 Value: False
                        13:10:07.5810000 | OrderPlaced Condition 1 Value: False
                        13:10:07.5920000 | OrderPlaced Condition 1 Value: False
                        13:10:07.5920000 | OrderPlaced Condition 1 Value: False
                        13:10:08.2390000 | OrderPlaced Condition 1 Value: False
                        13:10:08.2390000 | OrderPlaced Condition 1 Value: False
                        13:10:08.2480000 | OrderPlaced Condition 1 Value: False
                        13:10:08.2640000 | OrderPlaced Condition 1 Value: False
                        13:10:08.2640000 | OrderPlaced Condition 1 Value: False
                        13:10:08.5730000 | OrderPlaced Condition 1 Value: False
                        13:10:08.5730000 | OrderPlaced Condition 1 Value: False
                        13:10:10.4690000 | OrderPlaced Condition 1 Value: False
                        13:10:15.2450000 | OrderPlaced Condition 1 Value: False
                        13:10:15.5890000 | OrderPlaced Condition 1 Value: False
                        13:10:15.6520000 | OrderPlaced Condition 1 Value: False
                        13:10:15.6520000 | OrderPlaced Condition 1 Value: False
                        13:10:16.8210000 | OrderPlaced Condition 1 Value: False
                        13:10:16.8360000 | OrderPlaced Condition 1 Value: False
                        13:10:16.8360000 | OrderPlaced Condition 1 Value: False
                        13:10:42.6670000 | OrderPlaced Condition 1 Value: False
                        13:10:42.6670000 | OrderPlaced Condition 1 Value: False
                        13:10:42.8710000 | OrderPlaced Condition 1 Value: False
                        13:10:43.0050000 | OrderPlaced Condition 1 Value: False
                        13:10:43.1180000 | OrderPlaced Condition 1 Value: False
                        13:10:43.1830000 | OrderPlaced Condition 1 Value: False
                        13:10:43.1930000 | OrderPlaced Condition 1 Value: False
                        13:10:44.1820000 | OrderPlaced Condition 1 Value: False
                        13:10:44.1890000 | OrderPlaced Condition 1 Value: False
                        13:10:44.1890000 | OrderPlaced Condition 1 Value: False
                        13:10:44.1890000 | OrderPlaced Condition 1 Value: False
                        13:10:44.2460000 | OrderPlaced Condition 1 Value: False
                        13:10:44.2460000 | OrderPlaced Condition 1 Value: False
                        13:10:44.2460000 | OrderPlaced Condition 1 Value: False
                        13:11:00.8110000 | OrderPlaced Condition 1 Value: False
                        13:17:05.8260000 | OrderPlaced Condition 1 Value: False
                        13:17:29.3530000 | OrderPlaced Condition 1 Value: False
                        13:17:29.3690000 | OrderPlaced Condition 1 Value: False
                        13:17:29.3700000 | OrderPlaced Condition 1 Value: False
                        13:17:29.3960000 | OrderPlaced Condition 1 Value: False
                        13:17:29.4100000 | OrderPlaced Condition 1 Value: False
                        13:17:29.4120000 | OrderPlaced Condition 1 Value: False
                        13:17:29.4200000 | OrderPlaced Condition 1 Value: False
                        13:20:06.5750000 | OrderPlaced Condition 1 Value: False
                        13:20:06.6150000 | OrderPlaced Condition 1 Value: False
                        13:20:14.6460000 | OrderPlaced Condition 1 Value: False
                        13:20:14.6710000 | OrderPlaced Condition 1 Value: False
                        13:20:14.7010000 | OrderPlaced Condition 1 Value: False
                        13:20:15.1380000 | OrderPlaced Condition 1 Value: False
                        13:20:15.1400000 | OrderPlaced Condition 1 Value: False
                        13:20:15.1560000 | OrderPlaced Condition 1 Value: False
                        13:20:15.2090000 | OrderPlaced Condition 1 Value: False
                        13:20:15.2190000 | OrderPlaced Condition 1 Value: False
                        13:20:15.2190000 | OrderPlaced Condition 1 Value: False
                        13:20:15.9630000 | OrderPlaced Condition 1 Value: False
                        13:20:16.0590000 | OrderPlaced Condition 1 Value: False
                        13:20:16.0730000 | OrderPlaced Condition 1 Value: False
                        13:21:58.1190000 | OrderPlaced Condition 1 Value: False
                        13:21:58.1190000 | OrderPlaced Condition 1 Value: False
                        13:21:58.3430000 | OrderPlaced Condition 1 Value: False
                        13:21:59.5260000 | OrderPlaced Condition 1 Value: False
                        13:21:59.5360000 | OrderPlaced Condition 1 Value: False
                        13:21:59.5360000 | OrderPlaced Condition 1 Value: False
                        13:21:59.7550000 | OrderPlaced Condition 1 Value: False
                        13:21:59.9170000 | OrderPlaced Condition 1 Value: False
                        13:22:00.0160000 | OrderPlaced Condition 1 Value: False
                        13:22:00.0270000 | OrderPlaced Condition 1 Value: False
                        13:22:00.0350000 | OrderPlaced Condition 1 Value: False
                        13:22:00.0350000 | OrderPlaced Condition 1 Value: False
                        13:22:07.3180000 | OrderPlaced Condition 1 Value: False
                        13:22:07.4260000 | OrderPlaced Condition 1 Value: False
                        13:22:08.2180000 | OrderPlaced Condition 1 Value: False
                        13:22:08.2300000 | OrderPlaced Condition 1 Value: False
                        13:22:08.2560000 | OrderPlaced Condition 1 Value: False
                        13:22:11.2380000 | OrderPlaced Condition 1 Value: False
                        13:22:11.2550000 | OrderPlaced Condition 1 Value: False
                        13:30:34.2410000 | OrderPlaced Condition 1 Value: False
                        13:30:34.2410000 | OrderPlaced Condition 1 Value: False
                        13:31:05.9440000 | OrderPlaced Condition 1 Value: False
                        13:31:19.4540000 | OrderPlaced Condition 1 Value: False
                        13:31:19.5550000 | OrderPlaced Condition 1 Value: False
                        13:31:19.5810000 | OrderPlaced Condition 1 Value: False
                        13:31:41.5260000 | OrderPlaced Condition 1 Value: False
                        13:31:41.5260000 | OrderPlaced Condition 1 Value: False
                        13:31:41.6080000 | OrderPlaced Condition 1 Value: False
                        13:31:42.5130000 | OrderPlaced Condition 1 Value: False
                        13:31:42.5130000 | OrderPlaced Condition 1 Value: False
                        13:34:55.0630000 | OrderPlaced Condition 1 Value: False
                        13:34:57.3200000 | OrderPlaced Condition 1 Value: False
                        13:34:57.4010000 | OrderPlaced Condition 1 Value: False
                        13:34:57.4130000 | OrderPlaced Condition 1 Value: False
                        13:34:57.4180000 | OrderPlaced Condition 1 Value: False
                        13:36:36.0880000 | OrderPlaced Condition 1 Value: False
                        13:36:36.4240000 | OrderPlaced Condition 1 Value: False
                        13:36:36.4460000 | OrderPlaced Condition 1 Value: False
                        13:36:39.1800000 | OrderPlaced Condition 1 Value: False
                        13:36:39.1800000 | OrderPlaced Condition 1 Value: False
                        13:37:18.4350000 | OrderPlaced Condition 1 Value: False
                        13:37:18.7050000 | OrderPlaced Condition 1 Value: False
                        13:37:18.7050000 | OrderPlaced Condition 1 Value: False
                        13:37:18.7330000 | OrderPlaced Condition 1 Value: False
                        13:37:18.7330000 | OrderPlaced Condition 1 Value: False
                        13:37:18.7410000 | OrderPlaced Condition 1 Value: False
                        13:37:18.7990000 | OrderPlaced Condition 1 Value: False
                        13:37:18.7990000 | OrderPlaced Condition 1 Value: False
                        13:37:19.6620000 | OrderPlaced Condition 1 Value: False
                        13:37:19.7320000 | OrderPlaced Condition 1 Value: False
                        13:37:35.4560000 | OrderPlaced Condition 1 Value: False
                        13:37:35.5650000 | OrderPlaced Condition 1 Value: False
                        13:37:35.9620000 | OrderPlaced Condition 1 Value: False
                        13:37:35.9720000 | OrderPlaced Condition 1 Value: False
                        13:37:36.0310000 | OrderPlaced Condition 1 Value: False
                        13:37:36.0310000 | OrderPlaced Condition 1 Value: False
                        13:37:36.9480000 | OrderPlaced Condition 1 Value: False
                        13:37:36.9480000 | OrderPlaced Condition 1 Value: False
                        13:37:37.1770000 | OrderPlaced Condition 1 Value: False
                        13:41:21.6540000 | OrderPlaced Condition 1 Value: False
                        13:41:23.5130000 | OrderPlaced Condition 1 Value: False
                        13:41:24.8000000 | OrderPlaced Condition 1 Value: False
                        13:41:29.1410000 | OrderPlaced Condition 1 Value: False
                        13:41:32.8530000 | OrderPlaced Condition 1 Value: False
                        13:41:34.4010000 | OrderPlaced Condition 1 Value: False
                        13:41:34.7500000 | OrderPlaced Condition 1 Value: False
                        13:41:35.6600000 | OrderPlaced Condition 1 Value: False
                        13:41:36.1240000 | OrderPlaced Condition 1 Value: False
                        13:41:36.1310000 | OrderPlaced Condition 1 Value: False
                        13:51:44.2830000 | OrderPlaced Condition 1 Value: False
                        13:51:45.7500000 | Limit Price Value: 21489.75
                        13:51:45.7500000 | OrderPlaced Condition 5 Value: True
                        13:51:46.5040000 | Limit Price Value: 21490.25
                        13:51:51.9800000 | Limit Price Value: 21490.75
                        13:51:51.9800000 | Limit Price Value: 21491.25
                        13:51:57.8180000 | Limit Price Value: 21491.75​
                        Thanks & Regards
                        Maaz Khan

                        Comment


                          #13
                          Hello maaxk,

                          The output should be saved as a text file (right-click the output window, select save as) and the text file should be attached to your post.
                          (In case there is a lot of output)

                          Currently, we are only investigating when each of the conditions that set the bool are evaluating as true. We will focus on the why next.
                          Additional prints are not necessary at this time, and will detract from what we are trying to focus on.

                          After making changes to any default properties, the existing instance of the script will need to be removed from the chart or strategies tab of the control center and a new instance added from the Available list.
                          If you have changed the TraceOrders setting, this will allow that to take effect.

                          We should be able to see from the TraceOrders when the entry order is being submitted.

                          After the entry is submitted we would focus on the next prints immediately after to see which conditions are evaluating as true.

                          The issue is that the bool is being set back to false at an unexpected time, is this correct?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello Chelsea,

                            I have attached the output, please check.
                            Yes,
                            The issue is that the bool is being set back to false at an unexpected time, is this correct?
                            this is correct as we want to reset the value of the flag to false as bearish trend is detected, so there's an independent condition that checks whether the trend is bearish or not, if it detects bearish it will set the bool to false so that when the next bullish trend startes it should again enter a long limit order and once that order is entered into the long position it should set the flag to true until it detects the bearish trend again.

                            What i am stuck at is the flag setting true after placing the limit order, if you see in the output:
                            13:51:45.7500000 | Limit Price Value: 21489.75
                            13:51:45.7500000 | OrderPlaced Condition 5 Value: True
                            13:51:46.5040000 | Limit Price Value: 21490.25
                            13:51:51.9800000 | Limit Price Value: 21490.75​
                            only the first limit price value and flag value true is printed after that only limit price is printed and not the value which means that the limit price is being updated but order placement is not updated because the flag value is true which stops it from updating the limit price.

                            I want to set the flag true once the order is fulfilled or the order is entered.

                            Thanks & regards
                            Maaz Khan
                            Attached Files
                            Last edited by maaxk; 12-19-2024, 02:22 PM.

                            Comment


                              #15
                              Hello maaxk,

                              The order would only be submitted if OrderPlaced is false.

                              // Set 5
                              if ((Close[0] > Close[1])
                              && (Close[1] > Close[2])
                              && (LimitPrice > 0)
                              && (OrderPlaced == false))
                              {
                              EnterLongLimit(2, LimitPrice, "");
                              OrderPlaced = true;
                              }​

                              So once the order is submitted, the OrderPlaced bool is set to true.

                              If the order does not fill on the submission bar it will automatically be cancelled as the bool is true and the order will not be resubmitted on subsequent bars until the bool is set back to false.

                              Are you wanting to submit the order on each new bar to keep it alive?

                              Below is a link to an example that does this with an exit stop order.


                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              558 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              324 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              545 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              547 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X