All Custom Indicators return ZERO!
Forums › ProRealTime English forum › ProBuilder support › All Custom Indicators return ZERO!
- This topic has 6 replies, 3 voices, and was last updated 3 weeks ago by Iván.
-
-
04/03/2024 at 8:57 AM #23095704/03/2024 at 2:08 PM #23099004/03/2024 at 3:35 PM #231003
Sure, originally I think the code was called hyper trend? So I added some code to count the bars in a down or up trend and use that to determine a high or low level within the specific trend…the code returns the correct value within a strategy but not within a indicator. It was working before today so I do not really know why it suddenly returns a zero value?
mult = 5
slope = 14
width = 80
once avg = close
once hold = 0if barindex > 200 then
atr = AverageTrueRange[200] * mult
endifIf abs(close – avg) > atr then
avg = (close+avg)/2
//avg = avgN
else
avg = avg + os*(hold/mult/slope)
//avg = avgN
endifos = sgn(avg – avg[1])
If os <> os[1] then
hold = atr
else
hold = hold[1]
endifgreenbarcount = 0
if avg[2] > avg[1] and avg[1] < avg Then
greenbar = barindex
endif
if avg[1] < avg Then
greenbarcount = barindex – greenbar
endifif greenbarcount >=1 then
Longhigh = highest[greenbarcount](high)
endif
if greenbarcount =1 then
Longlow = low
endifReturn Longhigh
04/03/2024 at 6:05 PM #23101104/03/2024 at 6:17 PM #231012Hi..
I’ve got a theory, any preloaded bars in a strategy my give a valid ATR value for the logic.
In indicator, it needs 200 bars before valid ATR value available, since starting at bar zero.
This might have found a never ‘true’ condition in the logic so no output.
If you move the ‘ENDIF’ keyword, for the ‘BARINDEX>200 ‘IF’ block, to the end of the code just before ‘RETURN’, then something happens!
Not sure if this ‘something’ is the desired outcome.
Seems strange to use ‘ATR’ later in the code run but it may be ‘UNDEFIND’ till 200 bars up.
Moving this ‘ENDIF’ means all code inside new code block waits till valid ‘ATR’ value before executing.
Regards druby
1 user thanked author for this post.
04/04/2024 at 6:40 AM #23102904/04/2024 at 8:27 AM #231036 -
AuthorPosts
Find exclusive trading pro-tools on