Current Daily Bar within one third of the 250-days low
Forums › ProRealTime English forum › ProBuilder support › Current Daily Bar within one third of the 250-days low
- This topic has 4 replies, 2 voices, and was last updated 4 years ago by Roberto.
-
-
04/19/2020 at 7:31 PM #126934
Hello Pro Real Code community,
I am writing an indicator to show me a Yes/No on whether the current candle is within one third of the yearly low. The year is defined as the 250 days prior to the current candle.
The following code shows how far I have gotten, but for every stock it returns “0” though I know that many of those stocks are within one third of the 250-days low.
123456789101112131415for i = 250 to BarIndex doyearlyLow = low[i]yearlyLowDate = date[i]if low[i] < yearlyLow thenyearlyLow = low[i]yearlyLowDate = date[i]endifnextlastThirdStartDate = date[83]withinOneThird = 0if yearlyLowDate >= lastThirdStartDate thenwithinOneThird = 1endifAny chance we can find out wherein the problem lies?
04/19/2020 at 8:25 PM #126949For a starter
1for i = 250 to BarIndex doshould be
1for i = barindex-250 to BarIndex doI would code it like this (not tested):
12345678910111213141516yearlylow = low[250]for i = barindex-250 to BarIndexyearlyLow = min(yearlylow,low[i])if yearlylow = low[i] thenyearlyLowDate = date[i]endifnextlastThirdStartDate = date[83]withinOneThird = 0if yearlyLowDate >= lastThirdStartDate thenwithinOneThird = 1endifreturn withinOneThird04/20/2020 at 7:23 AM #126986In response to your message Vonasi, I have put together the following:
12345678910111213141516171819202122j = 250if BarIndex < 250 thenj = BarIndexendifyearlylow = low[j]for i = BarIndex - j to BarIndexyearlyLow = min(yearlyLow, low[i])if yearlyLow = low[i] thenyearlyLowDate = date[i]endifnextlastThirdStartDate = date[83]withinOneThird = 0if yearlyLowDate >= lastThirdStartDate thenwithinOneThird = 1endifdrawtext("withinOneThird = #withinOneThird#",barindex,0,Dialog,Bold,15)returnUnfortunately, the indicator always returns “0”, even testing it on stocks at their 52-week lows. Any further ideas on what we may be missing here?
Could it be related to this line?:
1if yearlyLowDate >= lastThirdStartDate thenPerhaps the dates are not expressed properly.
04/20/2020 at 8:40 AM #126993Sorry – I shouldn’t try to count backwards in code after a couple of drinks!
This works and is much faster:
123456789101112131415161718192021222324j = 250if BarIndex < j and barindex > 1 thenj = BarIndex-1endifif barindex > 1 thenyearlylow = lowest[j](low)for i = 0 to jif yearlyLow = low[i] thenyearlyLowDate = date[i]breakendifnextlastThirdStartDate = date[83]withinOneThird = 0if yearlyLowDate >= lastThirdStartDate thenwithinOneThird = 1endifendif//drawtext("withinOneThird = #withinOneThird#",barindex,0,Dialog,Bold,15)return withinOneThird04/21/2020 at 7:57 AM #127176 -
AuthorPosts