Sum open to close of candles in a defined time range?

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #102542 quote
    robdav
    Participant
    Veteran

    I’m writing a validation indicator because the system I’m working on works off the open of the current candle, not the evaluation of it on the next candle open.

    I’m using a trading session of TIME > 080000 AND < TIME 100000 and would like to total the SUM of Close-Open for long trades and Open-Close for short i.e. how many points could be made trading the open to close in the trading session for the candles that meet the criteria. Easy to do for a single candle but I’m not sure how to total them for the trading session.

    So if I was trading a 2 hour session on a 30 min timeframe and only two candles meet the criteria then I only want to sum those two. The timeframe might be an odd one like 36 mins.

    Some candles might be long or short in the trading session but that’s worked out on the criteria, it’s the totalling I need help with.

    Is this possible please?

    Thanks, Rob

    #102543 quote
    robertogozzi
    Moderator
    Master

    There you go:

    ONCE StartTime = 080000
    ONCE EndTime   = 100000
    ONCE BullCount = 0
    ONCE BearCount = 0
    Bullish = close > open
    Bearish = close < open
    IF Time = StartTime THEN
       BullCount = 0
       BearCount = 0
    ENDIF
    IF time >= StartTime AND time <= EndTime THEN
       IF Bullish THEN
          BullCount = BullCount + (close - open)
       ENDIF
       IF Bearish THEN
          BearCount = BearCount + (open - close)
       ENDIF
    ENDIF

    after EndTime both bullish and bearish candlesticks will have been tallied.

    Next day the counting will be restarded at StartTime.

    robdav thanked this post
    #102544 quote
    GraHal
    Participant
    Master

    Link to above code added to here

    Snippet Link Library

    robertogozzi thanked this post
    #102545 quote
    robdav
    Participant
    Veteran

    There you go:

    after EndTime both bullish and bearish candlesticks will have been tallied.

    Next day the counting will be restarded at StartTime.

    Hi Roberto

    This is close to what I need but it adds the cumulative bullish/bearish points to the previous session. I was hoping just to capture the number of bullish/bearish points for each individual session.

    Does that make sense? I’ve tried to show this in the attached image.

    Thanks again

    Rob

    #102547 quote
    robertogozzi
    Moderator
    Master

    Please do not quote posts unless necessary.

    Everyday, at StartTime, it restarts.

    The candle must CLOSE at StartTime, if you want to use a custom TF,  say 7 or 36 minute TF you must either:

    1 – change the StartTime and EndTime

    2 – replace = with < at line 7.

    #102548 quote
    robertogozzi
    Moderator
    Master

    You also need to remove = from line 11 if you want the time interval to be only > than StartTime and < EndTime.

    #102549 quote
    robdav
    Participant
    Veteran

    Thanks Roberto but it’s still the total for the period rather than each candle that I’m after.

    Thanks though.

    Rob

    #102550 quote
    robertogozzi
    Moderator
    Master

    I read you could do that individually but wanted their sum,

    A single candle count is easy;

    IF time >= 080000 AND time <= 100000 THEN
       Count = abs(close - open)
    ENDIF
    RETURN

    Of course you’ll have to add your conditions, other than bullish or bearish, if any, at lines 12 and 15.

    My code is generic and counts all of them.

    robdav and Kovit thanked this post
    #148219 quote
    Kovit
    Participant
    Senior

    Hi Roberto thanks for the code listed above would it be possible to adapt it so it does a rolling count of bear and bullish candles that updates every hour ?  I’ve been looking for something to help remove some losses with a long position on a 1 minute time frame and wondered if this could be adapted ?  Happy to open a new thread if needed ?

    Thanks in advance.

    #148241 quote
    robertogozzi
    Moderator
    Master

    There you go:

    ONCE BullCount = 0
    ONCE BearCount = 0
    Bullish = close > open
    Bearish = close < open
    IF OpenHour <> OpenHour[1] THEN
       BullCount = 0
       BearCount = 0
    ENDIF
    IF Bullish THEN
       BullCount = BullCount + (close - open)
    ENDIF
    IF Bearish THEN
       BearCount = BearCount + (open - close)
    ENDIF
    Return BullCount as “Bullish”, BearCount as “Bearish”
    Kovit thanked this post
    #148251 quote
    Kovit
    Participant
    Senior

    Perfect thanks Roberto.:)

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

Sum open to close of candles in a defined time range?


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
robdav @robdav Participant
Summary

This topic contains 10 replies,
has 4 voices, and was last updated by Kovit
5 years, 3 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/14/2019
Status: Active
Attachments: 1 files
Logo Logo
Loading...