Coding with time

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #7664 quote
    JensG
    Participant
    New

    Hi

    I am having trouble coding with time. I have created a simple indicator to learn how to incorporate the ‘Time’ constant into my coding in order to trade between certain times only. I would like the indicator to return a 1 only between 9:00 and 17:00 everyday. I have gotten as far as to generate a “1” from 9:00 and reset it each day but I cant get it to return to ZERO after 17:00. The code is as follows:

     

    If intradaybarindex = 0 then
       tradeon = 0
    endif
    
    If time > 91000 then
       tradeon = 1
    elsif time > 170500 then
       tradeon = 0
    endif
    
    Return tradeon

    I have gone through the manuals and some of the code on this site but I am missing something as I cant get the indicator to return to Zero after 17:00. I’ve tried variation of this but cant get it right. I don’t think it was really necessary but I’ve included an image of my results. The chart is set to 5min candles.

    Some help and insight as to why this is happening will be much appreciated

     

    Thanks

    Jens

    #7667 quote
    Adolfo
    Participant
    Senior

    Hi Jens!

    IF TIME >= 090000 AND TIME < 170000 THEN
    tradeon = 1
    ELSE
    tradeon = 0
    ENDIF
    

    Hope it helps you.

    Regards.

    #7821 quote
    JensG
    Participant
    New

    It Works. Seems so obvious when you see it but I couldn’t think it.

    Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Coding with time


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
JensG @jg123 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by JensG
9 years, 8 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/22/2016
Status: Active
Attachments: No files
Logo Logo
Loading...