Buongiorno,
Chiedo cortesemente un piccolo aiuto.
Vorrei identificare il valore di una media eseguita sulle candele giornaliere, rispettando i giorni della settimana.
Semplifico con un piccolo esempio:
Supponiamo che la Candela di Oggi corrisponda al giorno della settimana “1=Lunedì” e che io voglia la media solo dei giorni “1” per “x” tempo. Escludendo la candela corrente.
N = Average[21](giorno=1)
Naturalmente con la condizione “IF” per calcolare di giorno in giorno in automatico.
In attesa di un cortese riscontro, ringrazio anticipatamente.
Good morning,
I kindly ask for a little help.
I would like to identify the value of an average performed on daily candles, respecting the days of the week.
Let me simplify with a small example:
Let’s suppose that Today’s Candle corresponds to the day of the week “1 = Monday” and that I want the average of days “1” only for “x” time. Excluding the current candle.
N = Average [21] (day = 1)
Of course with the “IF” condition to calculate day by day automatically.
Waiting for a kind reply, thank you in advance.
JSParticipant
Senior
Normally you can use:
If CurrentDayOfWeek = 1 then
Y = Close
EndIf
But when I use CurrentDayOf Week = 1 nothing happens
CurrentDayOfWeek = 2 returns Monday
CurrentDayOfWeek = 3 returns Tuesday
???
Thank you so much.
Have a nice day
Maybe this is what you were looking for (only a simple average can be calculated):
ONCE Periods = 20
FOR i = 1 TO 5 //5 days (Monday to Friday)
$MyTotal[i] = 0
$MyAverage[i] = 0
$MyTally[i] = 0
NEXT
ALLscanned = 0
IF BarIndex > (Periods * 5) THEN
FOR j = 1 TO BarIndex[1]
FOR i = 1 TO 5
IF i = OpenDayOfWeek[j] THEN
IF $MyTally[i] < Periods THEN
$MyTally[i] = $MyTally[i] + 1
$MyTotal[i] = $MyTotal[i] + close[j]
$MyAverage[i] = $MyTotal[i] / $MyTally[i]
IF $MyTally[i] = Periods THEN
ALLscanned = ALLscanned + 1
ENDIF
ENDIF
break
ENDIF
NEXT
IF ALLscanned = 5 THEN
break
ENDIF
NEXT
ENDIF
x1 = $MyAverage[1]
x2 = $MyAverage[2]
x3 = $MyAverage[3]
x4 = $MyAverage[4]
x5 = $MyAverage[5]
RETURN x1 AS "Mon",x2 AS "Tue",x3 AS "Wed",x4 AS "Thu",x5 AS "Fri"
Perfect!
Thank you so much. 🙂