BardParticipant
Master
Hi there, I don’t know if this is a Timeframe issue but I have a “percent moves” indicator that is used on a Daily chart that I want to be able to use on a 12, 8 or 1 hr chart. I think it’s the AnchorDate code that is not allowing me to use the code? How would I convert this so that I can choose an AnchorDate too?
Cheers,
Bard
//Version 2.1
//DEFPARAM DrawOnLastBarOnly = true
Timeframe(Daily,UpdateOnClose)
//Timeframe(Hourly,UpdateOnClose)
//ONCE DTE = 15 //15 bars
//ONCE pcUP = 5 //5% each move
//ONCE pcDN = -5
ONCE tUP = 0 //tally
ONCE tDN = 0
//ONCE n = 0 //tally 15-period chunks
//ONCE BarInc = DTE //0/1 = tally ALL big moves even if consecutive, 2...= tally only in chunks
AnchorDate = 20200127 //Date anchor YYYYMMDD format
if date=anchordate then
startbar=barindex
endif
lookback = max(1,barindex-startbar)
if lookback>0 and date>=AnchorDate then
ONCE BarStart = period
if closeVSrange = 1 then
pcMove = 100 * (close - close[period]) / close[period]
elsif closeVSrange = 0 then
pcMove = 100 * (highest[period](high) - lowest[period](low)) / lowest[period](low)
endif
pcMove = 100 * (close - close[DTE]) / close[DTE]
sigma = std[period](pcmove)
pcMoveCorr = pcMove / sigma
pcUPmod = pcUP/sigma
pcDNmod = pcDN/sigma
tUP = 0
tDN = 0
IF BarIndex >= BarStart THEN
for i = 1 to barindex-barstart
if pcMoveCorr[i] > pcUpmod then
tUP = tUP + 1
elsif pcMoveCorr[i] <- pcDnmod then
tDN = tDN + 1
endif
next
PerCentUP = tUP * 100 / (barindex-barstart )//n
PerCentDN = tDN * 100 / (barindex-barstart )//n
endif
endif
RETURN PerCentUP coloured (0,255,0) style (line,2) as "Percent Chance P Moves Up to Target %", PerCentDN coloured (255,0,0) style (line,2) as "Percent Chance P Moves Down to Target %"
//, pcUP/sigma coloured (0,210,0), pcDN/sigma coloured (210,0,0)//t AS "Tally", PerCent as "%"
Hi..
If you comment out lines 3, 14 and make anchordate a dynamic variable with a default value, that appears to work.
Removing line 3, doesn’t link the code to another time frame other than the chart default.
And adding ‘anchordate’ as a dynamic variable allow you to set an appropriate date depending on what chart time frame your on.
That’s a simple solution.
Additionally, because their’s no feedback between what you may set a dynamic value to, and whats acceptable in the code, you could set up some checking and an error message if you go out of an acceptable range.
This might not be a problem because you may only setup once and forget.
But for the date, you could compare the date ‘set’ with the date on bar zero to see if its in the chart’s loaded historical data. etc
Just one last note, if your code uses a lot of dynamic variable, it’s best to export your code and upload. This save’s time and allow others to run your code with the settings you use and focus on getting a solution.
Best regard