Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel pending Limit/Stop orders at a certain chart time

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

    Cancel pending Limit/Stop orders at a certain chart time

    Hi!

    I am trying to implement a filter to my strategy cancelling the pending limit/stop orders at a certain chart time, but I am having some issued.

    As a beginner, I try to look for examples online, and came to the following conclusion:

    Code:
    else if ToTime(00,00,00)
                        || ToTime(10,00,00)
                        || ToTime(16,00,00)
                        || ToTime(21,00,00))
                    {
                        CancelOrder(entryOrder2);
                    }​
    However I got the following error while compiling:

    "operators cannot be appliet to bool or int" (Not exactly the message, but I hope you get it)

    Can you please help me?


    #2
    Hello Maliboo,

    The error is telling you that you are not making a comparison.

    If ToTime(00,00,00) is what?

    later than another time?

    earlier to another time?

    equal to another time?

    Make a comparison that can evaluate as true or false.

    For example if you want to know if the time of the bar is greater than 12:30 PM.

    if (ToTime(Time[0]) > 123000)

    Try using the Strategy Builder to generate time conditions and then look at the code that is generated to learn from it.

    Below are links to resources on time conditions.
    https://ninjatrader.com/support/help...imeComparisons
    https://ninjatrader.com/support/help...to_limit_t.htm
    https://ninjatrader.com/support/foru...es#post1112291
    https://ninjatrader.com/support/foru...06#post1185206

    Also, below is a link to a forum post with helpful resources on getting started with C# and NinjaScript.
    https://ninjatrader.com/support/foru...pts#post786040
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Maliboo,

      The error is telling you that you are not making a comparison.

      If ToTime(00,00,00) is what?

      later than another time?

      earlier to another time?

      equal to another time?

      Make a comparison that can evaluate as true or false.

      For example if you want to know if the time of the bar is greater than 12:30 PM.

      if (ToTime(Time[0]) > 123000)

      Try using the Strategy Builder to generate time conditions and then look at the code that is generated to learn from it.

      Below are links to resources on time conditions.
      https://ninjatrader.com/support/help...imeComparisons
      https://ninjatrader.com/support/help...to_limit_t.htm
      https://ninjatrader.com/support/foru...es#post1112291
      https://ninjatrader.com/support/foru...06#post1185206

      Also, below is a link to a forum post with helpful resources on getting started with C# and NinjaScript.
      https://ninjatrader.com/support/foru...pts#post786040

      Hi Chelsea,

      I understand... The problem is that I am using Renko bars, so one bar can be 1 second and another can be 5 hours, so I cannot rely on them.

      So I was looking for something like "If Charttime or Servertime is = 000000, then close all pending orders" I do not know if I can approach that anyhow, or maybe you can guide me on how can I implement it. Maybe with DateTime.Now?

      Comment


        #4
        Hello Maliboo,

        Time[0] is the time of the bar. Core.Globals.Now is the current computer time.

        Either way you still have to make a comparison.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        70 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        143 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        76 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        47 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        51 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X