Dear all,
I am trying to create a Bear condition out of Nicola’s excellent Kagi on price chart. I get a syntax error, and I cannot understand why. Anyone spotting the error, thanks!
//PRC_Kagi on price chart | indicator
//05.09.2019
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
// --- settings
// select one of the two possible setting (0=don't use)
ReversalAmountPercent = 1.5 //amount of price percent to inverse Kagi trend
//ReversalAmountPoints = 0 //amount of points to inverse Kagi trend
// --- end of settings
once kagi=close
if ReversalAmountPercent>0 then
//percent retracement
pup = (close-kagi)/kagi
pdn = (kagi-close)/kagi
InvDec = 1/0.1
//bullish reversal
if pup>=ReversalAmountPercent/100 then
coeff = abs(pup/ReversalAmountPercent)*100
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi+(kagi*(ReversalAmountPercent/100)*coeff)
endif
//bearish reversal
if pdn>=ReversalAmountPercent/100 then
coeff = abs(pdn/ReversalAmountPercent)*100
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi-(kagi*(ReversalAmountPercent/100)*coeff)
endif
if ReversalAmountPoints>0 then
//points retracement
pup = close-kagi
pdn = kagi-close
InvDec = 1
//bullish reversal
if pup>=ReversalAmountPoints*pointsize then
coeff = (pup/pointsize)/ReversalAmountPoints
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi+(ReversalAmountPoints*pointsize)*coeff
endif
//bearish reversal
if pdn>=ReversalAmountPoints*pointsize then
coeff = (pdn/pointsize)/ReversalAmountPoints
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi-(ReversalAmountPoints*pointsize)*coeff
endif
BearKagi=(pdn>=ReversalAmountPercent/100) or (pdn>=ReversalAmountPoints*pointsize)
The “ReversalAmountPoints” is still commented in your code at line 9.
Thanks Nicolas. It was careless of me. Unfortunately, I still get the syntax error message. Any more observations or possible ideas, thanks!
//PRC_Kagi on price chart | indicator
//05.09.2019
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
// --- settings
// select one of the two possible setting (0=don't use)
ReversalAmountPercent = 1.5 //amount of price percent to inverse Kagi trend
ReversalAmountPoints = 0 //amount of points to inverse Kagi trend
// --- end of settings
once kagi=close
if ReversalAmountPercent>0 then
//percent retracement
pup = (close-kagi)/kagi
pdn = (kagi-close)/kagi
InvDec = 1/0.1
//bullish reversal
if pup>=ReversalAmountPercent/100 then
coeff = abs(pup/ReversalAmountPercent)*100
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi+(kagi*(ReversalAmountPercent/100)*coeff)
endif
//bearish reversal
if pdn>=ReversalAmountPercent/100 then
coeff = abs(pdn/ReversalAmountPercent)*100
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi-(kagi*(ReversalAmountPercent/100)*coeff)
endif
if ReversalAmountPoints>0 then
//points retracement
pup = close-kagi
pdn = kagi-close
InvDec = 1
//bullish reversal
if pup>=ReversalAmountPoints*pointsize then
coeff = (pup/pointsize)/ReversalAmountPoints
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi+(ReversalAmountPoints*pointsize)*coeff
endif
//bearish reversal
if pdn>=ReversalAmountPoints*pointsize then
coeff = (pdn/pointsize)/ReversalAmountPoints
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi-(ReversalAmountPoints*pointsize)*coeff
endif
BearKagi=(pdn>=ReversalAmountPercent/100) or (pdn>=ReversalAmountPoints*pointsize)
If you are just looking for when the new Kagi is up or down, just check the color in the original code.
If R>0 , then its red, otherwise it’s green.
To spot a new reversal, check if the previous R was >0 or = to 0.
bearish = r>0 and r[1]=0
and vice versa for a new bullish reversal condition:
bullish = r[1]>0 and r=0
Thanks Nicolas, you solved it.
//PRC_Kagi on price chart | indicator
//05.09.2019
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
// --- settings
// select one of the two possible setting (0=don't use)
ReversalAmountPercent = 1.5 //amount of price percent to inverse Kagi trend
ReversalAmountPoints = 0 //amount of points to inverse Kagi trend
// --- end of settings
once kagi=close
if ReversalAmountPercent>0 then
//percent retracement
pup = (close-kagi)/kagi
pdn = (kagi-close)/kagi
InvDec = 1/0.1
//bullish reversal
if pup>=ReversalAmountPercent/100 then
coeff = abs(pup/ReversalAmountPercent)*100
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi+(kagi*(ReversalAmountPercent/100)*coeff)
r=0
//g=255
endif
//bearish reversal
if pdn>=ReversalAmountPercent/100 then
coeff = abs(pdn/ReversalAmountPercent)*100
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi-(kagi*(ReversalAmountPercent/100)*coeff)
r=255
//g=0
endif
endif
if ReversalAmountPoints>0 then
//points retracement
pup = close-kagi
pdn = kagi-close
InvDec = 1
//bullish reversal
if pup>=ReversalAmountPoints*pointsize then
coeff = (pup/pointsize)/ReversalAmountPoints
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi+(ReversalAmountPoints*pointsize)*coeff
r=0
//g=255
endif
//bearish reversal
if pdn>=ReversalAmountPoints*pointsize then
coeff = (pdn/pointsize)/ReversalAmountPoints
coeff = round(InvDec*coeff-0.5)/InvDec
kagi=kagi-(ReversalAmountPoints*pointsize)*coeff
r=255
//g=0
endif
endif
BearKagi=r>0 and r[1]=0