Coding for high and low between set hours

Viewing 15 posts - 1 through 15 (of 39 total)
  • Author
    Posts
  • #7231 quote
    Dave Charles
    Participant
    New

    Hi,

    I am currently coding a pivot indicator to use with Indexes. PRT already has a pivot indicator, but this runs from 12.00am to 11.59.59pm. This means that the pivots aren’t using cash data (10am – 4pm) and aren’t as effective.

    What I am wanting to do is create a pivot indicator that uses the highest and lowest price between 10.00am and 4.00pm and uses the closing price at 4.00pm.

    I am having little bit of trouble creating the logic for this. I can understand what I want it to say, but I can’t work out the correct programming language to use.

    Basically..

    Cashhigh = highest price of the prior weekday, between the hours of 10.00.00 and 16.00.00

    Cashlow = lowest price of the prior weekday, between the hours of 10.00.00 and 16.00.00

    Cash close = price at 16.00.00 of the prior weekday.

    And what I mean by saying the prior weekday, is that if today is Monday looking at data from Friday between 10am-4pm, if today is Tuesday looking at data from Monday between 10am- 4pm, etc.

    Does anyone have any pointers?

    Thank you!

    #7246 quote
    Adolfo
    Participant
    Senior

    Hi Dave, need to know in which timeframe are you working in order to code it. In this example I’m using 15min chart, so variables Highest and Lowest are set to 24 (6 hours back) at 16:00h

    DEFPARAM CUMULATEORDERS = FALSE
    
    REM ESTABLISH MAX AND MIN EACH DAY OF WEEK 
    IF TIME=160000 AND DAYOFWEEK=1 THEN
    CashHighMo = Highest[24](high)
    CashLowMo = Lowest[24](low)
    ENDIF
    IF TIME=160000 AND DAYOFWEEK=2 THEN
    CashHighTu = Highest[24](high)
    CashLowTu = Lowest[24](low)
    ENDIF
    IF TIME=160000 AND DAYOFWEEK=3 THEN
    CashHighWe = Highest[24](high)
    CashLowWe = Lowest[24](low)
    ENDIF
    IF TIME=160000 AND DAYOFWEEK=4 THEN
    CashHighTh = Highest[24](high)
    CashLowTh = Lowest[24](low)
    ENDIF
    IF TIME=160000 AND DAYOFWEEK=5 THEN
    CashHighFr = Highest[24](high)
    CashLowFr = Lowest[24](low)
    ENDIF
    
    IF DAYOFWEEK=1 AND close>CashHighFr THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    IF DAYOFWEEK=2 AND close>CashHighMo THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    IF DAYOFWEEK=3 AND close>CashHighTu THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    IF DAYOFWEEK=4 AND close>CashHighWe THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    IF DAYOFWEEK=5 AND close>CashHighTh THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    
    IF DAYOFWEEK=1 AND Close<CashLowFr THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    IF DAYOFWEEK=2 AND Close<CashLowMo THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    IF DAYOFWEEK=3 AND Close<CashLowTu THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    IF DAYOFWEEK=4 AND Close<CashLowWe THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    IF DAYOFWEEK=5 AND Close<CashLowTh THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    Jeff thanked this post
    #7249 quote
    Adolfo
    Participant
    Senior

    Sorry Dave, I did it for ProOrder before…

    This one is for ProBuilder

    REM ESTABLISH MAX AND MIN EACH DAY OF WEEK
    IF TIME=160000 AND DAYOFWEEK=1 THEN
    CashHighMo = Highest[24](high)
    CashLowMo = Lowest[24](low)
    ENDIF
    IF TIME=160000 AND DAYOFWEEK=2 THEN
    CashHighTu = Highest[24](high)
    CashLowTu = Lowest[24](low)
    ENDIF
    IF TIME=160000 AND DAYOFWEEK=3 THEN
    CashHighWe = Highest[24](high)
    CashLowWe = Lowest[24](low)
    ENDIF
    IF TIME=160000 AND DAYOFWEEK=4 THEN
    CashHighTh = Highest[24](high)
    CashLowTh = Lowest[24](low)
    ENDIF
    IF TIME=160000 AND DAYOFWEEK=5 THEN
    CashHighFr = Highest[24](high)
    CashLowFr = Lowest[24](low)
    ENDIF
    
    return CashHighMo as "Max Monday",CashLowMo as "Min Monday",CashHighTu as "Max Tuesday",CashLowTu as "Min Tuesday",CashHighWe as "Max Wednesday",CashLowWe as "Min Wednesday",CashHighTh as "Max Thursday",CashLowTh as "Min Thursday",CashHighFr as "Max Friday",CashLowFr as "Min Friday"
    Jeff thanked this post
    #7255 quote
    Adolfo
    Participant
    Senior

    [attachment file=”7256″]

    Simplified

    REM ESTABLISH MAX AND MIN EACH DAY OF WEEK
    IF DAYOFWEEK=1 THEN
    MAXIMO = CashHighFr
    MINIMO = CashLowFr
    IF TIME=160000 THEN
    CashHighMo = Highest[24](high)
    CashLowMo = Lowest[24](low)
    ENDIF
    ENDIF
    IF DAYOFWEEK=2 THEN
    MAXIMO = CashHighMo
    MINIMO = CashLowMo
    IF TIME=160000 THEN
    CashHighTu = Highest[24](high)
    CashLowTu = Lowest[24](low)
    ENDIF
    ENDIF
    IF DAYOFWEEK=3 THEN
    MAXIMO = CashHighTu
    MINIMO = CashLowTu
    IF TIME=160000 THEN
    CashHighWe = Highest[24](high)
    CashLowWe = Lowest[24](low)
    ENDIF
    ENDIF
    IF DAYOFWEEK=4 THEN
    MAXIMO = CashHighWe
    MINIMO = CashLowWe
    IF TIME=160000 THEN
    CashHighTh = Highest[24](high)
    CashLowTh = Lowest[24](low)
    ENDIF
    ENDIF
    
    IF DAYOFWEEK=5 THEN
    MAXIMO = CashHighTh
    MINIMO = CashLowTh
    IF TIME=160000 THEN
    CashHighFr = Highest[24](high)
    CashLowFr = Lowest[24](low)
    ENDIF
    ENDIF
    return MAXIMO AS "LAST DAY MAX",MINIMO AS "LAST DAY LOW"

    [attachment file=7258]

    Max-Low-Last-Day.itf Max-min-last-day.png Max-min-last-day.png
    #7332 quote
    Dave Charles
    Participant
    New

    ADOLFO YOU ARE AMAZING!!!!

    I worked out how to do the cash close from what you have written!

    I have a question though, is it possible to get it to look at the highest and lowest prices between 10am-4pm without having to adjust the number of bars within the highest/lowest brackets.

    It just makes it challenging to flick between time frames, which I do often. 🙂

     

    Thank you so much for you help!

    
    REM ESTABLISHED CLOSE OF MARKET
    
    IF DAYOFWEEK=1 THEN
    cashclose=CashCloseFr
    IF TIME=160000 THEN
    CashCloseMo = Close
    ENDIF
    ENDIF
    IF DAYOFWEEK=2 THEN
    cashclose=CashCloseMo
    IF TIME=160000 THEN
    CashCloseTu = Close
    ENDIF
    ENDIF
    IF DAYOFWEEK=3 THEN
    cashclose=CashCloseTu
    IF TIME=160000 THEN
    CashCloseWe = Close
    ENDIF
    ENDIF
    IF DAYOFWEEK=4 THEN
    cashclose=CashCloseWe
    IF TIME=160000 THEN
    CashCloseTh = Close
    ENDIF
    ENDIF
    
    IF DAYOFWEEK=5 THEN
    cashclose=CashCloseTh
    IF TIME=160000 THEN
    CashCloseFr = Close
    ENDIF
    ENDIF
    return cashclose AS "CASHCLOSE"
    
    #7336 quote
    Adolfo
    Participant
    Senior

    You’re wellcome Dave!

    I think we can’t use “TIMEFRAME” function in ProBuilder, as far as I know is only for ProScreener at the moment, but I got an idea about “TIME“, maybe it will test bar by bar and know which timeframe are we using, and then we can set Highest and Lowest brackets with the right numbers.

    On it, will be back with news.

    #7340 quote
    Dave Charles
    Participant
    New

    Awesome thanks!

     

    I actually had a break through. But the problem is that it is taking the value from 9am and I am unsure how to stop it. Or what I am doing right or wrong, or even what in the code is redundant! For example not sure whether the line below is doing anything.

    IF TIME<160000 and time>100000 THEN
    
    

    Getting closer!

     

    Thanks!

     

    REM ESTABLISH MAX AND MIN EACH DAY OF WEEK
    
    
    IF DAYOFWEEK=1 THEN
    MAXIMO = CashHighFr
    MINIMO = CashLowFr
    cashclose=CashCloseFr
    IF TIME<160000 and time>100000 THEN
    CashHighMo = ( DHIGH(0))
    CashLowMo =( DLOW(0))
    CashCloseMo = Close
    ENDIF
    ENDIF
    IF DAYOFWEEK=2 THEN
    MAXIMO = CashHighMo
    MINIMO = CashLowMo
    cashclose=CashCloseMo
    IF TIME<160000 and time>100000 THEN
    CashHighTu = ( DHIGH(0))
    CashLowTu = ( DLOW(0))
    CashCloseTu = Close
    ENDIF
    ENDIF
    IF DAYOFWEEK=3 THEN
    MAXIMO = CashHighTu
    MINIMO = CashLowTu
    cashclose=CashCloseTu
    IF TIME<160000 and time>100000 THEN
    CashHighWe = ( DHIGH(0))
    CashLowWe = ( DLOW(0))
    CashCloseWe = Close
    ENDIF
    ENDIF
    IF DAYOFWEEK=4 THEN
    MAXIMO = CashHighWe
    MINIMO = CashLowWe
    cashclose=CashCloseWe
    IF TIME<160000 and time>100000 THEN
    CashHighTh = (  DHIGH(0))
    CashLowTh = ( DLOW(0))
    CashCloseTh = Close
    ENDIF
    ENDIF
    
    IF DAYOFWEEK=5 THEN
    MAXIMO = CashHighTh
    MINIMO = CashLowTh
    cashclose=CashCloseTh
    IF TIME<160000 and time>100000 THEN
    CashHighFr = ( DHIGH(0))
    CashLowFr = ( DLOW(0))
    CashCloseFr = Close
    ENDIF
    ENDIF
    
    return MAXIMO AS "LAST DAY MAX",MINIMO AS "LAST DAY LOW", cashclose AS "CASH CLOSE"
    
    
    #7343 quote
    Adolfo
    Participant
    Senior

    Looks nice! Still working on how to know wich timeframe is using, as far as i’m testing on 15 min chart, this works ok but when i change timeframe, it won’t, YET! 😉

    base = 360 // 1 minute, 6 hours back
    actualbar = Time
    lastbar = Time[1]
    period = actualbar-lastbar
    n = abs(round(periodo/base))
    x = abs(round(base/n))  // Result is 24 so works on 15 mins..
    IF DAYOFWEEK=1 THEN
    MAXIMO = CashHighFr
    MINIMO = CashLowFr
    CashHighMo = Highest[x](high)
    CashLowMo = Lowest[x](low)

    ……………………………………………………….

    I’ll have a break and continue later, gl!

    #7347 quote
    Adolfo
    Participant
    Senior

    And… Here it is 🙂 ( Hope so  )

    REM ESTABLISH MAX AND MIN EACH DAY OF WEEK
    IF TIME=160000 THEN
    base = 360
    horaanterior = Time[1]
    periodo = 156000-horaanterior
    n = abs(round(periodo/100))
    x = abs(round(base/n))
    IF DAYOFWEEK=1 THEN
    MAXIMO = CashHighFr
    MINIMO = CashLowFr
    CashHighMo = Highest[x](high)
    CashLowMo = Lowest[x](low)
    CashCloseMo = Close
    CashClose = CashCloseFr
    ENDIF
    IF DAYOFWEEK=2 THEN
    MAXIMO = CashHighMo
    MINIMO = CashLowMo
    CashHighTu = Highest[x](high)
    CashLowTu = Lowest[x](low)
    CashCloseTu = Close
    CashClose = CashCloseMo
    ENDIF
    IF DAYOFWEEK=3 THEN
    MAXIMO = CashHighTu
    MINIMO = CashLowTu
    CashHighWe = Highest[x](high)
    CashLowWe = Lowest[x](low)
    CashCloseWe = Close
    CashClose = CashCloseTu
    ENDIF
    IF DAYOFWEEK=4 THEN
    MAXIMO = CashHighWe
    MINIMO = CashLowWe
    CashHighTh = Highest[x](high)
    CashLowTh = Lowest[x](low)
    CashCloseTh = Close
    CashClose = CashCloseWe
    ENDIF
    IF DAYOFWEEK=5 THEN
    MAXIMO = CashHighTh
    MINIMO = CashLowTh
    CashHighFr = Highest[x](high)
    CashLowFr = Lowest[x](low)
    CashCloseFr = Close
    CashClose = CashCloseTh
    ENDIF
    ENDIF
    return MAXIMO AS "LAST DAY MAX",MINIMO AS "LAST DAY LOW",CashClose as "Cash Close"
    
    Dave Charles thanked this post
    #7432 quote
    Dave Charles
    Participant
    New

    Thanks Adolfo!

    That is great and it works on any time frame!

    There is a little problem though, I just put it on the chart and it is a 1 day out, what I mean is that the high and low from Monday, instead of being shown on the Tuesday, is shown on the day after on the Wednesday.

    Is there an easy fix I tried fiddling with the code but couldn’t work it out? 🙂

    So on the picture the high, lows and close need to be a day earlier. Where the red lines are drawn.

    Thanks Adolfo, I am super appreciative of the effort you have put in!

    -Dave

    screenshot.png screenshot.png
    #7437 quote
    Adolfo
    Participant
    Senior

    Yep Dave, you’re right… Gotta check it,  I’ll be back soon 🙂

    #7442 quote
    Adolfo
    Participant
    Senior

    Dave, after check it on my chart, didn’t find any error, here is the code and screenshot. Can you confirm we got the same?

    REM ESTABLISH MAX AND MIN EACH DAY OF WEEK
    IF TIME=160000 THEN
    base = 360
    horaanterior = Time[1]
    periodo = 156000-horaanterior
    n = abs(round(periodo/100))
    x = abs(round(base/n))
    IF DAYOFWEEK=1 THEN
    MAXIMO = CashHighFr
    MINIMO = CashLowFr
    CashHighMo = Highest[x](high)
    CashLowMo = Lowest[x](low)
    CashCloseMo = Close
    CashClose = CashCloseFr
    ENDIF
    IF DAYOFWEEK=2 THEN
    MAXIMO = CashHighMo
    MINIMO = CashLowMo
    CashHighTu = Highest[x](high)
    CashLowTu = Lowest[x](low)
    CashCloseTu = Close
    CashClose = CashCloseMo
    ENDIF
    IF DAYOFWEEK=3 THEN
    MAXIMO = CashHighTu
    MINIMO = CashLowTu
    CashHighWe = Highest[x](high)
    CashLowWe = Lowest[x](low)
    CashCloseWe = Close
    CashClose = CashCloseTu
    ENDIF
    IF DAYOFWEEK=4 THEN
    MAXIMO = CashHighWe
    MINIMO = CashLowWe
    CashHighTh = Highest[x](high)
    CashLowTh = Lowest[x](low)
    CashCloseTh = Close
    CashClose = CashCloseWe
    ENDIF
    IF DAYOFWEEK=5 THEN
    MAXIMO = CashHighTh
    MINIMO = CashLowTh
    CashHighFr = Highest[x](high)
    CashLowFr = Lowest[x](low)
    CashCloseFr = Close
    CashClose = CashCloseTh
    ENDIF
    ENDIF
    return MAXIMO AS "LAST DAY MAX",MINIMO AS "LAST DAY LOW",CashClose as "Cash Close"
    
    Max-min-last-day-1.png Max-min-last-day-1.png max-min-yesterday.itf lastdaymaxmin.png lastdaymaxmin.png
    #7449 quote
    Dave Charles
    Participant
    New

    Hi Adolfo,

    I just uploaded your .itf file, and it is 24 hrs out 🙂 As soon as the session finishes the max and min should move to the high and low of the session that has just finished, but instead it goes to max and min of the session before.

    So Mondays max and min is on Wednesday’s session but it should be on Tuesdays 🙂

     

    Thanks 🙂

    #7450 quote
    Adolfo
    Participant
    Senior

    Just to confirm, my charts are at GMT+2.

    So now, we got the new max and min changing at 16:00h, to lastday before. You mean they should change each new session (00:00 or intradaybarindex=0).

    Each new day, max, min and close should be: max-min between 10-16 and yesterday close, is it ok?

    #7451 quote
    Adolfo
    Participant
    Senior

    Finally.. Got it!! :):):)… As far as it only works from 1m to 1h…

    REM ESTABLISH MAX AND MIN EACH DAY OF WEEK
    base = 360
    periodo = 006000-horaanterior
    n = abs(round(periodo/100))
    x = abs(round(base/n))
    
    IF TIME=010000 THEN
    horaanterior = Time[1]
    endif
    
    IF DAYOFWEEK=1 THEN
    MAXIMO = CashHighFr
    MINIMO = CashLowFr
    CashClose = DClose(1)
    IF TIME = 160000 THEN
    CashHighMo = Highest[x](high)
    CashLowMo = Lowest[x](low)
    ENDIF
    ENDIF
    
    IF DAYOFWEEK=2 THEN
    MAXIMO = CashHighMo
    MINIMO = CashLowMo
    CashClose = DClose(1)
    IF TIME = 160000 THEN
    CashHighTu = Highest[x](high)
    CashLowTu = Lowest[x](low)
    ENDIF
    ENDIf
    
    IF DAYOFWEEK=3 THEN
    MAXIMO = CashHighTu
    MINIMO = CashLowTu
    CashClose = DClose(1)
    IF TIME = 160000 THEN
    CashHighWe = Highest[x](high)
    CashLowWe = Lowest[x](low)
    ENDIF
    ENDIF
    
    IF DAYOFWEEK=4 THEN
    MAXIMO = CashHighWe
    MINIMO = CashLowWe
    CashClose = DClose(1)
    IF TIME = 160000 THEN
    CashHighTh = Highest[x](high)
    CashLowTh = Lowest[x](low)
    ENDIF
    ENDIF
    
    IF DAYOFWEEK=5 THEN
    MAXIMO = CashHighTh
    MINIMO = CashLowTh
    CashClose = DClose(1)
    IF TIME = 160000 THEN
    CashHighFr = Highest[x](high)
    CashLowFr = Lowest[x](low)
    ENDIF
    ENDIF
    
    return MAXIMO AS "LAST DAY MAX",MINIMO AS "LAST DAY LOW",CashClose as "Cash Close"
    
    Dave Charles thanked this post
    lastdaymaxmin-1.png lastdaymaxmin-1.png max-min-yesterday-1.itf
Viewing 15 posts - 1 through 15 (of 39 total)
  • You must be logged in to reply to this topic.

Coding for high and low between set hours


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 38 replies,
has 1 voice, and was last updated by Velociraptux
4 years, 9 months ago.

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