Search code examples
pine-scripttradingview-apipine-script-v4

Conversion failed required (...)+ loop did not match anything at character 'd'


I coded my custom indicator in this:

Rule 1 checks if the first candle of the current day closes above the previous day's range in a 5-minute timeframe. It uses the condition time[1].dayofweek != time.dayofweek to ensure it's the first candle of the current day. If this condition is met, it plots a green triangle below the bar as "1st Rule Completed."

Rule 2 remains the same as before, checking for the pattern of two or more green candles followed by a red candle and then a green candle. It plots a red triangle above the bar when this condition is met.

It giving me error:

Conversion failed, reason: Pine source is incorrect. line 8: required (...)+ loop did not match anything at character 'd'

Code:

//@version=4
study(title="Custom Rules Indicator", shorttitle="CRI", overlay=true)

rule1_condition = time[1].dayofweek != time.dayofweek and close > high[1] and close > low[1]

rule2_condition = close > open and close[1] > open[1] and close[2] > open[2] and close[3] < open[3] and close[4] > open[4]

plotshape(series=rule1_condition, title="1st Rule Completed", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=rule2_condition, title="2nd Rule Completed", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

Where am I wrong?

It seems that TradingView does not support the use of the ... notation for matching multiple conditions in Pine Script.

To fix this issue, I have rewrite the condition for Rule 1 without using the ... notation. but still not working still giving me error.


Solution

  • There is no time.dayofweek variable.

    This is correct:

    //@version=4 
    study(title="Custom Rules Indicator", shorttitle="CRI", overlay=true)
    
    rule1_condition = dayofweek[1] != dayofweek and close > high[1] and close > low[1]
    rule2_condition = close > open and close[1] > open[1] and close[2] > open[2] and close[3] < open[3] and close[4] > open[4]
    plotshape(series=rule1_condition, title="1st Rule Completed", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small) 
    plotshape(series=rule2_condition, title="2nd Rule Completed", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)