Search code examples
pine-scriptindicator

conversion pine script v2 to v3


This is my code.

isBuyPlotted=isBuyPlotted[1]==true?true:nz(buySetup[MAXSIGNALDELAY+1])==9?true:false or nz(buySetup)==9?false:buySignal[1]==true  // init

buySignal=nz(buySetup[MAXSIGNALDELAY])>9-MAXSIGNALDELAY and close>nz(high[1]) and nz(close[1])>nz(open[1]) and nz(close)>nz(open) and not isBuyPlotted

I try to modify pine version 2 to version 3.

isBuyPlotted=0.0
isBuyPlotted:=isBuyPlotted[1]==true?true:nz(buySetup[MAXSIGNALDELAY+1])==9?true:false or nz(buySetup)==9?false:buySignal[1]==true  // init
buySignal=0.0
buySignal:=nz(buySetup[MAXSIGNALDELAY])>9-MAXSIGNALDELAY and close>nz(high[1]) and nz(close[1])>nz(open[1]) and nz(close)>nz(open) and not isBuyPlotted

But this error happens. Variable buySignal was declared with float type. Cannot assign it expression of type series[bool]


Solution

  • Both those variables are of type bool in the original code but you have declared them as float. That's what the error message tells you.

    Change it to:

    isBuyPlotted=false
    buySignal=false
    isBuyPlotted:=isBuyPlotted[1]==true?true:nz(buySetup[MAXSIGNALDELAY+1])==9?true:false or nz(buySetup)==9?false:buySignal[1]==true  // init
    buySignal:=nz(buySetup[MAXSIGNALDELAY])>9-MAXSIGNALDELAY and close>nz(high[1]) and nz(close[1])>nz(open[1]) and nz(close)>nz(open) and not isBuyPlotted