Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to start a strategy from now

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

    How to start a strategy from now

    Hi,

    Could someone please tell me how to start a strategy starting from current bar?

    I've been trying to do this using below code but I am thinking there is a better way to do this. The problem with below is that if the strategy lasts more than a day then the strategy stops running unless the startTime is 100 (1min after midnight).

    if (ToDay(Time[0]) >= tradingDate && ToTime(Time[0]) >= startTime)
    {
    do something
    }

    Any help is appreciated.

    Thanks,

    #2
    Hi stevebong,

    Thank you for your post.

    If you write

    if (Historical)
    {
    return;
    }

    as the first line after OnBarUpdate(), the strategy will not execute on historical bars.
    TimNinjaTrader Customer Service

    Comment


      #3
      Hi, I am trying to do the same thing but I am getting multiple errors, not sure what I am doing wrong. Thanks.
      Attached Files

      Comment


        #4
        vegasfoster, you need to include this in the OnBarUpdate() and pay attention to correct bracing -

        Code:
         
        protected override void OnBarUpdate()
        [B][SIZE=3]{[/SIZE][/B]
         
        if (Historical) return;
         
        [B][SIZE=3]}[/SIZE][/B]

        Comment


          #5
          Thanks for replying. The problem was that I added it exactly as you described, as follows:


          "protected override void OnBarUpdate()

          {

          if (Historical) return;

          }


          {
          // Condition set 1
          if (High[1] > MovingHL(100, 24).MovingHigh[2]
          && Close[
          0] == Low[1])
          {....}"

          Having two sets of the outer squiggly brackets was fouling it up. When I changed it to the following it worked:

          "protected override void OnBarUpdate()

          {

          if (Historical) return;

          // Condition set 1
          if (High[1] > MovingHL(100, 24).MovingHigh[2]
          && Close[
          0] == Low[1])
          {....}"

          It's just taking me a while to learn these things, e.g. 20 <> 20.0, PointValue <> pointvalue, etc. I will get there.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          64 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          35 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          59 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          62 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          51 views
          0 likes
          Last Post CarlTrading  
          Working...
          X