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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          637 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          366 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          107 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          569 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          572 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X