How can I make only current date's graph as intraday( 5min / 10 min interval etc) and older data as daily using AFL?

Any help would be appreciated :slight_smile: !

SetBarsRequired(sbrall);
dd = Day();
DayChangeStart = dd != Ref(dd, -1);
DayChangeStart[0] = True;
DayChangeEnd = dd != Ref(dd, 1);
bsDayStart = LastValue(BarsSince(DayChangeStart))+1;

OD = ValueWhen(DayChangeStart, O);
HD = HighestSince(DayChangeStart, H);
LD = LowestSince(DayChangeStart, L);
CD = ValueWhen(DayChangeEnd, C);

// build daily candles
scOD = SparseCompress(DayChangeEnd,OD);
scHD = SparseCompress(DayChangeEnd,HD);
scLD = SparseCompress(DayChangeEnd,LD);
scCD = SparseCompress(DayChangeEnd,CD);
scDD = SparseCompress(DayChangeEnd,DateNum());

//Make room for intraday
scOD = Ref(scOD, bsDayStart);
scHD = Ref(scHD, bsDayStart);
scLD = Ref(scLD, bsDayStart);
scCD = Ref(scCD, bsDayStart);
scDD = Ref(scDD, bsDayStart);

//merge intraday data with day
LastDay = dd == LastValue(dd);
scOD = IIf( LastDay, O, scOD);
scHD = IIf( LastDay, H, scHD);
scLD = IIf( LastDay, L, scLD);
scCD = IIf( LastDay, C, scCD);
scDD = IIf( LastDay, DateNum(), scDD);

PlotOHLC(scOD, scHD, scLD, scCD,"OHLC", colorBlack, styleCandle);
Plot(scDD \ 10000 + 1900,"year", colorBlue, styleNoLine | styleNoLabel | styleOwnScale);
Plot(scDD % 10000 \ 100,"month", colorBlue, styleNoLine | styleNoLabel | styleOwnScale);
Plot(scDD % 100,"day", colorBlue, styleNoLine | styleNoLabel | styleOwnScale);


14 Likes

@awilson very nice piece of code. Thanks

1 Like

Thanks a lot for the quick response @awilson ! : ) I’ll test this out in the following week and

@awilson excellent work . !.. . I would like to use HEIKE NASHI candles for intraday and daily to keep it as is i.e style bar .. How do i trick it ..appreciate any help .. Tried different ways but in vein ..Is it possible ?

// for intra day candles
p=6;
Om=MA(O,p);
hm=MA(H,p);
lm=MA(L,p);
Cm=MA(C,p);
HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), colorBlack, styleCandle | styleNoLabel );

Hi @amsai !

Not sure I understood what you want. Do you want my code above plotting Heikin Ashi ?

Hi @awilson ,

this is current chart
image

would like to get like this (image cut and paste..not actual coded )

image

Daily bars = Candle Sticks
Intradday bars = HEIKE NASHI candles
This way i can use only one chart . Thanks for your time and attention.

// By --- Anderson Wilson ----

SetBarsRequired(sbrall);
dd = Day();
DayChangeStart = dd != Ref(dd, -1);
DayChangeStart[0] = True;
DayChangeEnd = dd != Ref(dd, 1);
bsDayStart = LastValue(BarsSince(DayChangeStart))+1;

OD = ValueWhen(DayChangeStart, O);
HD = HighestSince(DayChangeStart, H);
LD = LowestSince(DayChangeStart, L);
CD = ValueWhen(DayChangeEnd, C);

// build daily candles
scOD = SparseCompress(DayChangeEnd,OD);
scHD = SparseCompress(DayChangeEnd,HD);
scLD = SparseCompress(DayChangeEnd,LD);
scCD = SparseCompress(DayChangeEnd,CD);
scDD = SparseCompress(DayChangeEnd,DateNum());

//Make room for intraday
scOD = Ref(scOD, bsDayStart);
scHD = Ref(scHD, bsDayStart);
scLD = Ref(scLD, bsDayStart);
scCD = Ref(scCD, bsDayStart);
scDD = Ref(scDD, bsDayStart);

//merge intraday data with day
LastDay = dd == LastValue(dd);

//=========
// intraday in Heiken-Ashi
p=6;
Om=MA(O,p);
hm=MA(H,p);
lm=MA(L,p);
Cm=MA(C,p);
HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );

scOD = IIf( LastDay, Om, scOD);
scHD = IIf( LastDay, Hm, scHD);
scLD = IIf( LastDay, Lm, scLD);
scCD = IIf( LastDay, Cm, scCD);
scDD = IIf( LastDay, DateNum(), scDD);

PlotOHLC(scOD, scHD, scLD, scCD,"OHLC", colorBlack, styleCandle);
Plot(scDD \ 10000 + 1900,"year", colorBlue, styleNoLine | styleNoLabel | styleOwnScale);
Plot(scDD % 10000 \ 100,"month", colorBlue, styleNoLine | styleNoLabel | styleOwnScale);
Plot(scDD % 100,"day", colorBlue, styleNoLine | styleNoLabel | styleOwnScale);
6 Likes

That's the trick .. Thanks a lot @awilson . Really appreciate your time

image