BardParticipant
Master
Hi, Can anyone fix this code?
It was posted here on PRT but has a minor syntax error if anyone can fix it that’d be appreciated as I wanted to compare it to the code I modified from another site and posted here:
https://www.prorealcode.com/topic/kase-dev-stop-dev-stops-4-5-6-0-using-sar-to-flip-devs/
Cheers
Bard
//Kase Deviation Stoploss Bands
n = 30
DTR = max(max(High - Low[2], abs(High - Close[2])),max(abs(Low - Close[2]),(abs(Low - Close[2]))))
avg = average[n](DTR)
st = std[n](DTR)
maFast = average[9,1](close)
maSlow = average[21,1](close)
once DevInit = 1
If DevInit = 1 Then
If maFast > maSlow Then
DevLong = 1
DevLongC = 0
Else
DevLong = 0
DevShortC = 0
EndIf
DevInit = 0
ElsIf DevInit = 0 and DevLong = 1 Then
HighestDev3 = Dev3
For y = 1 to DevLongC Do
If Dev3[y] > HighestDev3 Then
HighestDev3 = Dev3[y]
EndIf
Next
If close < HighestDev3 Then
DevLong = 0
DevShortC = 0
EndIf
ElsIf DevInit = 0 and DevLong = 0 Then
LowestDev3 = Dev3
For x = 1 to DevShortC Do
If Dev3[x] < LowestDev3 Then
DevLong = 1
DevLongC = 0
EndIf
EndIf
If DevLong = 1 Then
DevLongC = DevLongC + 1
//WarningLine = typicalprice-avg
//Dev1 = typicalprice-avg - st
Dev2 = typicalprice-avg - 2.2*st
Dev3 = typicalprice-avg - 3.6*st
ElsIf DevLong = 0 Then
DevShortC = DevShortC + 1
//WarningLine = typicalprice+avg
//Dev1 = typicalprice+avg + st
Dev2 = typicalprice+avg + 2.2*st
Dev3 = typicalprice+avg + 3.6*st
EndIf
Return Dev2 coloured(2, 118, 253) style(dottedline,2) as "Dev Stop 2.2",
Dev3 coloured(2, 118, 253) style(dottedline,2) as "Dev Stop 3.6"
I fixed the syntax error of your code, don’t know if the indicator is computing correctly though, here it is:
//Kase Deviation Stoploss Bands
n = 30
DTR = max(max(High - Low[2], abs(High - Close[2])),max(abs(Low - Close[2]),(abs(Low - Close[2]))))
avg = average[n](DTR)
st = std[n](DTR)
maFast = average[9,1](close)
maSlow = average[21,1](close)
once DevInit = 1
If DevInit = 1 Then
If maFast > maSlow Then
DevLong = 1
DevLongC = 0
Else
DevLong = 0
DevShortC = 0
EndIf
DevInit = 0
ElsIf DevInit = 0 and DevLong = 1 Then
HighestDev3 = Dev3
For y = 1 to DevLongC Do
If Dev3[y] > HighestDev3 Then
HighestDev3 = Dev3[y]
EndIf
Next
If close < HighestDev3 Then
DevLong = 0
DevShortC = 0
EndIf
ElsIf DevInit = 0 and DevLong = 0 Then
LowestDev3 = Dev3
For x = 1 to DevShortC Do
If Dev3[x] < LowestDev3 Then
DevLong = 1
DevLongC = 0
EndIf
next
If DevLong = 1 Then
DevLongC = DevLongC + 1
//WarningLine = typicalprice-avg
//Dev1 = typicalprice-avg - st
Dev2 = typicalprice-avg - 2.2*st
Dev3 = typicalprice-avg - 3.6*st
ElsIf DevLong = 0 Then
DevShortC = DevShortC + 1
//WarningLine = typicalprice+avg
//Dev1 = typicalprice+avg + st
Dev2 = typicalprice+avg + 2.2*st
Dev3 = typicalprice+avg + 3.6*st
EndIf
endif
Return Dev2 coloured(2, 118, 253) style(dottedline,2) as "Dev Stop 2.2",Dev3 coloured(2, 118, 253) style(dottedline,2) as "Dev Stop 3.6"
BardParticipant
Master
Thanks @nicolas, but unfortunately not, pls see screen:
I have the SAR Dev Stop code that I modified and posted on this forum but was wondering how it compared to @juanj’s code and if he has an idea why his code is not performing as intended?
Cheers
Sorry, I don’t understand, so many topics about the same indis and their applications.., I’m totally lost… 🙁
BardParticipant
Master
Me too… The bands were meant to hug the price series but didn’t when applied via the spanner to the Price Chart.
BardParticipant
Master
Note sure why this image didn’t attach with the post above about juanj’s code not working but his Dev Stop lines are flat horizontal lines on the indicator window and don’t appear at all when applied to the main Price chart window. (The Kase Dev Stops are similar to ATR bands).
Cheers, hope this makes sense.
Maybe @juanj could help with his code?