Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I want strategy to run from 6:00 PM local until 10:00 AM local only

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

    I want strategy to run from 6:00 PM local until 10:00 AM local only

    Hi, I want my strategy to only run or generate signals for me from 6:00 PM local time until 10:00 am local time, how do I program in these time stipulations? So I do NOT want it to run or generate signals from 10:01 AM until 5:59 PM.

    #2
    Jim, I use the following code snippet. You need to set interger variables for PitOpenTime and PitCloseTime in the format HHMMSS (e.g. 183000 for 6:30:00 pm)

    PHP Code:
    [SIZE=1]if (PitOpenTime == -1) // Strategy set to run 24 hours a day[/SIZE]
    [SIZE=1]{[/SIZE]
    [SIZE=1]  if (Bars.FirstBarOfSession == true)[/SIZE]
    [SIZE=1]  {[/SIZE]
    [SIZE=1]    Print(TimeStamp+"\tStart Processing Strategy Again");[/SIZE]
    [SIZE=1]    haltProcessing = false;[/SIZE]
    [SIZE=1]  }[/SIZE]
    [SIZE=1]  // Stop all strategy logic in the OnBarUpdate() method.[/SIZE]
    [SIZE=1]  if (haltProcessing == true)[/SIZE]
    [SIZE=1]  {[/SIZE]
    [SIZE=1]    return;[/SIZE]
    [SIZE=1]  } [/SIZE]
    [SIZE=1]}[/SIZE]
    [SIZE=1]else if (PitCloseTime > PitOpenTime)[/SIZE]
    [SIZE=1]{[/SIZE]
    [SIZE=1]  if (ToTime(Time[0]) <= PitOpenTime &&[/SIZE]
    [SIZE=1]  ToTime(Time[0]) >= 0 &&[/SIZE]
    [SIZE=1]  haltProcessing == true)[/SIZE]
    [SIZE=1]  {[/SIZE]
    [SIZE=1]    Print(TimeStamp+"\tStart Processing Strategy Again");[/SIZE]
    [SIZE=1]    haltProcessing = false;[/SIZE]
    [SIZE=1]  }[/SIZE]
    [SIZE=1]  if (ToTime(Time[0]) < PitOpenTime ||[/SIZE]
    [SIZE=1]  (ToTime(Time[0]) > PitOpenTime && haltProcessing == true))[/SIZE]
    [SIZE=1]  {[/SIZE]
    [SIZE=1]    return;[/SIZE]
    [SIZE=1]  }[/SIZE]
    [SIZE=1]  // Stop all strategy logic in the OnBarUpdate() method.[/SIZE]
    [SIZE=1]  if (haltProcessing == true)[/SIZE]
    [SIZE=1]  {[/SIZE]
    [SIZE=1]    return;[/SIZE]
    [SIZE=1]  }[/SIZE]
    [SIZE=1]  if (ToTime(Time[0]) > PitCloseTime)[/SIZE]
    [SIZE=1]  {[/SIZE]
    [SIZE=1]    StopStrategy("EndOfSession"); // Call custom method to close all open positions and cancel all working orders[/SIZE]
    [SIZE=1]  }[/SIZE]
    [SIZE=1]}[/SIZE]
    [SIZE=1]else if (PitCloseTime < PitOpenTime)[/SIZE]
    [SIZE=1]{[/SIZE]
    [SIZE=1]  if (ToTime(Time[0]) >= PitOpenTime &&[/SIZE]
    [SIZE=1]  haltProcessing == true)[/SIZE]
    [SIZE=1]  {[/SIZE]
    [SIZE=1]    Print(TimeStamp+"\tStart Processing Strategy Again");[/SIZE]
    [SIZE=1]    haltProcessing = false;[/SIZE]
    [SIZE=1]  }[/SIZE]
    [SIZE=1]  // Stop all strategy logic in the OnBarUpdate() method.[/SIZE]
    [SIZE=1]  if (haltProcessing == true)[/SIZE]
    [SIZE=1]  {[/SIZE]
    [SIZE=1]    return;[/SIZE]
    [SIZE=1]  }[/SIZE]
    [SIZE=1]  if (ToTime(Time[0]) < PitOpenTime && [/SIZE]
    [SIZE=1]  ToTime(Time[0]) > PitCloseTime)[/SIZE]
    [SIZE=1]  {[/SIZE]
    [SIZE=1]    StopStrategy("EndOfSession"); // Call custom method to close all open positions and cancel all working orders[/SIZE]
    [SIZE=1]  }[/SIZE]
    [SIZE=1]}[/SIZE]
    [SIZE=1]else[/SIZE]
    [SIZE=1]{[/SIZE]
    [SIZE=1]  Print(TimeStamp+"\tError - PitOpenTime equals PitCloseTime");[/SIZE]
    [SIZE=1]}[/SIZE]
    [SIZE=1][/SIZE] 
    
    The link below has the code I used for the StopStrategy method. I used a modified version of SampleHaltAdvancedStrategy



    Greg
    The Trading Mantis
    NinjaTrader Ecosystem Vendor - The Trading Mantis

    Comment


      #3
      My bad on formatting the post. Don't include any [/SIZE] or [SIZE=1] statements in the code.
      The Trading Mantis
      NinjaTrader Ecosystem Vendor - The Trading Mantis

      Comment


        #4
        Hello,

        Also please take a look at the following reference sample on how to code this:



        Let me know if I can be of further assistance.
        BrettNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 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
        549 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        549 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X