Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time... Hour of Day error

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

    Time... Hour of Day error

    Hi,

    Cant get a value for the hour of the day to work.

    It does print out the simple hour number as in 9 for 09:00 when i check output window, but unable to get it in if statement.

    Would rather avoid the Time Tostring 090000 s dont want to keep writing longwinded times juat want simple hours

    tried

    if (Time[0].Hour = hourOfDay)

    Errors

    Strategy\BollEtcEtcHours.cs Property or indexer 'System.DateTime.Hour' cannot be assigned to -- it is read only CS0200 - click for info 96 6


    Strategy\BollEtcEtcHours.cs Cannot implicitly convert type 'int' to 'bool' CS0029 - click for info 96 6




    Cheers

    #2
    try:

    if (Time[0].Hour == hourOfDay)

    Comment


      #3
      Hello AussieMike,

      From the error message it looks like hourOfDay is a "bool". You would need to reference Time[0].Hour to an int.

      JCNinjaTrader Customer Service

      Comment


        #4
        Originally posted by Aussiemike View Post
        Hi,

        Cant get a value for the hour of the day to work.

        It does print out the simple hour number as in 9 for 09:00 when i check output window, but unable to get it in if statement.

        Would rather avoid the Time Tostring 090000 s dont want to keep writing longwinded times juat want simple hours

        tried

        if (Time[0].Hour = hourOfDay)

        Errors

        Strategy\BollEtcEtcHours.cs Property or indexer 'System.DateTime.Hour' cannot be assigned to -- it is read only CS0200 - click for info 96 6


        Strategy\BollEtcEtcHours.cs Cannot implicitly convert type 'int' to 'bool' CS0029 - click for info 96 6




        Cheers
        Your statement is an assignation, instead of a comparison. For a comparison, you need to double up on the equals sign.

        Code:
        [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (Time[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]].Hour =[SIZE=3][COLOR=red][B]=[/B][/COLOR][/SIZE] hourOfDay)[/COLOR][/SIZE][/FONT][/SIZE][/FONT]

        Comment


          #5
          Thanks Again,

          Sorry about that. Thought i recognised the error. Still no programmer ;-)

          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