Error on Use of Highest Function

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #144714 quote
    scoot3r83
    Participant
    Average

    Hello Forum,

    I am trying to write some code to display the 4 hour candles on the 5 minute chart. I have written some code and I receive and error that ‘a positive integer field is expected with the HIGHEST’. As I am trying to capture the current 4 hour data I cycle through the last candles up to 48 candles (48 * 5 mins = 4 hours) and then begin the new candle. So I am using a variable in the highest function called ‘currentBar’ which I expect to be the counted bars since the start of the current 4 hour candle. Is this error telling me I cannot use a variable in this location and can only use a written integer?

    Any help on correcting this error would be appreciated.

     

    PS – For now ignore how wide I am drawing the actual candlestick bodies, I had not reached that part of the project and had borrowed the candle drawing code from another indicator.

     

    // Indicator Parameters
    Period  = 48
    CandleStart = 030001
    CandleStop = 030059
    
    ONCE startIndex = 0
    ONCE CandleOpen = Open
    ONCE CandleClose = Close
    ONCE CandleHigh = High
    ONCE CandleLow = Low
    
    IF CurrentTime > CandleStart AND CurrentTime < CandleStop AND BarIndex > Period THEN
    startIndex = BarIndex
    ENDIF
    
    IF BarIndex - startIndex > Period THEN
    startIndex = BarIndex
    ENDIF
    
    // Current Bar Position
    IF startIndex > 0 THEN
    currentBar =  abs(BarIndex - startIndex)
    ELSE
    currentBar = abs(BarIndex)
    ENDIF
    
    // Calculate 4 Hr Open
    IF startIndex > 0 THEN
    CandleOpen = Open[currentBar]
    ENDIF
    
    // Calculate 4 Hr Close
    IF startIndex > 0 THEN
    CandleClose = Close[currentBar]
    ENDIF
    
    // Calculate 4 Hr High
    IF startIndex > 0 THEN
    CandleHigh = highest[currentBar]
    ENDIF
    
    // Calculate 4 Hr Low
    IF startIndex > 0 THEN
    CandleLow = lowest[currentBar]
    ENDIF
    
    // Draw Candle
    
    //candlestick color
    if CandleOpen>CandleClose then
    direction = -1
    else
    direction = 1
    endif
    
    if direction = 1 then
    // Candlestick body
    DRAWRECTANGLE(barindex-5,CandleOpen,barindex,CandleClose) COLOURED(10,255,10)
    // Candlestick high and low
    DRAWRECTANGLE(barindex-3,CandleClose,barindex-2,CandleHigh) COLOURED(10,255,10)
    DRAWRECTANGLE(barindex-3,CandleOpen,barindex-2,CandleLow) COLOURED(10,255,10)
    endif
     
    //bearish candle
    if direction = -1 then
    // Candlestick body
    DRAWRECTANGLE(barindex-5,CandleClose,barindex,CandleOpen) COLOURED(255,10,10)
    // Candlestick high and low
    DRAWRECTANGLE(barindex-3,CandleOpen,barindex-2,CandleHigh) COLOURED(255,10,10)
    DRAWRECTANGLE(barindex-3,CandleClose,barindex-2,CandleLow) COLOURED(255,10,10)
    endif
    return CandleOpen as "CandleOpen", CandleClose as "CandleClose", CandleHigh as "CandleHigh", CandleLow as "CandleLow"
    4HR-Candles.itf
    #144721 quote
    robertogozzi
    Moderator
    Master

    Try adding this at line 26:

    currentBar = max(1, currentBar)

    to make sure currentBar is at least 1.

    scoot3r83 thanked this post
    #144819 quote
    scoot3r83
    Participant
    Average

    Thank you. That has done the trick.

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

Error on Use of Highest Function


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
scoot3r83 @scoot3r83 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by scoot3r83
5 years, 4 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/18/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...