Final update, silly mistake corrected and coding efficiency improved.
Posted to help someone having my similar problem:
Bisto
_SECTION_BEGIN( "Weekly-daily MACD Histogram" );
function MACDmy( array, Sh, Lo )
{
eSh = EMA( array, Sh );
eLo = EMA( array, Lo );
return eSh -eLo;
}
function SignalMy( array, smooth )
{
return EMA( array, smooth );
}
function HistMACD( array, Sh, Lo, Smooth )
{
m = MACDmy( Array, Sh, Lo );
s = SignalMy( m, smooth );
return m - s;
}
for ( y = 0; y < 5; y++ )
{
z = 0;
temp = 0;
VarSet( "C" + y , 0 );
temp = VarGet( "C" + y );
for ( i = y; i < BarCount ; i = i + 5 )
{
temp[z] = C[i];
z++;
}
VarSet( "C" + y , temp );
}
for ( i = 0;i < 5;i++ )
VarSet( "HistMACD" + i, HistMACD( VarGet( "C" + i ), 12, 26, 9 ) );
temp0 = VarGet( "HistMACD" + 0 );
temp1 = VarGet( "HistMACD" + 1 );
temp2 = VarGet( "HistMACD" + 2 );
temp3 = VarGet( "HistMACD" + 3 );
temp4 = VarGet( "HistMACD" + 4 );
tot = 0;
step = step0 = step1 = step2 = step3 = step4 = 0;
for ( i = 0;i < BarCount ;i++ )
{
switch ( True )
{
case step == 0:
tot[i] = temp0[step0];
step0++;
step++;
break;
case step == 1:
tot[i] = temp1[step1];
step1++;
step++;
break;
case step == 2:
tot[i] = temp2[step2];
step2++;
step++;
break;
case step == 3:
tot[i] = temp3[step3];
step3++;
step++;
break;
case step == 4:
tot[i] = temp4[step4];
step4++;
step = 0;
}
}
Plot( tot , "Weekly-daily MACD Histogram ", colorPaleGreen, styleHistogram |
styleNoLabel | styleThick, Null, Null, Null, 1 );
// OLD STYLE comparison
TimeFrameSet( inWeekly );
m = MACD( 12, 26 ); // MACD from WEEKLY data
s = Signal( 12, 26, 9 ); // Signal from WEEKLY data
HMACD = m - s ; // MACD Histogram from WEEKLY data
TimeFrameRestore();
HMACD1 = TimeFrameExpand( HMACD, inWeekly );
Plot( HMACD1, "Weekly MACD Histogram", colorGreen, styleArea | styleNoLabel ,
Null, Null, Null, -1 );
_SECTION_END();
--- In [email protected], "bistoman73" <bistoma...@...> wrote:
>
> update: I wrote some code to avoid to use AB timeframe functions.
> It seems very good.
> The last mistery is why the last bar is 0 but I am tired now, please check
> the code to find any "logic" mistake
>
> cheers
>
> Bisto
>
> function MACDmy( array, Sh, Lo )
> {
> eSh = EMA( array, Sh );
> eLo = EMA( array, Lo );
> return eSh -eLo;
> }
>
> function SignalMy( array, smooth )
> {
> return EMA( array, smooth );
> }
>
>
> function HistMACD( array, Sh, Lo, Smooth )
> {
> m = MACDmy( Array, Sh, Lo );
> s = SignalMy( m, smooth );
> return m - s;
> }
>
> for ( y = 0; y < 5; y++ )
> {
> z = 0;
> temp = 0;
> VarSet( "C" + y , 0 );
>
> for ( i = y; i < BarCount - 1; i = i + 5 )
> {
> temp = VarGet( "C" + y );
> temp[z] = C[i];
> VarSet( "C" + y , temp );
> z++;
> }
> }
>
> for ( i = 0;i < 5;i++ )
> VarSet( "HistMACD" + i, HistMACD( VarGet( "C" + i ), 12, 26, 9 ) );
>
> tot = 0;
> step = step0 = step1 = step2 = step3 = step4 = 0;
>
> for ( i = 0;i < BarCount -1 ;i++ )
> {
> switch ( True )
> {
> case step == 0:
> temp = VarGet( "HistMACD" + 0 );
> tot[i] = temp[step0];
> step0++;
> step++;
> break;
>
> case step == 1:
> temp = VarGet( "HistMACD" + 1 );
> tot[i] = temp[step1];
> step1++;
> step++;
> break;
>
> case step == 2:
> temp = VarGet( "HistMACD" + 2 );
> tot[i] = temp[step2];
> step2++;
> step++;
> break;
>
> case step == 3:
> temp = VarGet( "HistMACD" + 3 );
> tot[i] = temp[step3];
> step3++;
> step++;
> break;
>
> case step == 4:
> temp = VarGet( "HistMACD" + 4 );
> tot[i] = temp[step4];
> step4++;
> step = 0;
> }
> }
>
>
> Plot( tot , "Weekly-daily MACDmy Histogram ", colorPaleGreen, styleHistogram
> | styleNoLabel | styleThick, Null, Null, Null, 1 );
>
> // OLD STYLE comparison
>
> TimeFrameSet( inWeekly );
> m = MACD(12, 26 ); // MACD from WEEKLY data
> s = Signal(12, 26, 9); // Signal from WEEKLY data
> HMACD = m - s ; // MACD Histogram from WEEKLY data
> TimeFrameRestore();
>
> HMACD1 = TimeFrameExpand( HMACD, inWeekly );
>
> Plot( HMACD1, "Weekly MACD Histogram", colorGreen,styleArea| styleOwnScale|
> styleNoLabel ,Null,Null,Null,-1 );
>
>
> --- In [email protected], "bistoman73" <bistoman73@> wrote:
> >
> > Hi,
> >
> > I had an idea that "almost" solved the problem: to use some arrays shifted
> > of N days to "built" the week.
> >
> > I post here the code to share it and to catch suggestion to solve the
> > problem that it still exists: having used in not normal way the
> > timeframecompress function there are problems in weeks with less than 5
> > trading days like Xmas period. Of course it's not a problem of AB, it's
> > more a misuse of the function.
> >
> > The product is a composed graph with 5 colors bar (one every 5 days) and
> > also a black dashed line that show the problem occuring in period like Xmas
> >
> > I hope it could help giving an (maybe wrong) idea and not produce confusion
> > in the use of AB timeframe functions
> >
> > PS I also had to code a function to calculate MACD on an array because the
> > built in function uses always C
> >
> >
> > function MACDmy( array, Sh, Lo )
> > {
> > eSh = EMA( array, Sh );
> > eLo = EMA( array, Lo );
> > return eSh -eLo;
> > }
> >
> > function SignalMy( array, smooth )
> > {
> > return EMA( array, smooth );
> > }
> >
> >
> > function HistMACD( array, Sh, Lo, Smooth )
> > {
> > m = MACDmy( Array, Sh, Lo );
> > s = SignalMy( m, smooth );
> > return m - s;
> > }
> >
> >
> > Ar0 = TimeFrameCompress(Ref(C,-0), 5*inDaily,compressLast);
> >
> > HMACD0 = TimeFrameExpand(HistMACD(Ar0,12,26,9), 5*inDaily,expandPoint );
> >
> >
> > Ar1 = TimeFrameCompress(Ref(C,-1), 5*inDaily,compressLast);
> >
> > HMACD1 = TimeFrameExpand(HistMACD(Ar1,12,26,9), 5*inDaily ,expandPoint );
> >
> >
> > Ar2 = TimeFrameCompress(Ref(C,-2),5*inDaily,compressLast);
> >
> > HMACD2 = TimeFrameExpand(HistMACD(Ar2,12,26,9), 5*inDaily,expandPoint );
> >
> >
> > Ar3 = TimeFrameCompress(Ref(C,-3),5*inDaily,compressLast);
> >
> > HMACD3 = TimeFrameExpand(HistMACD(Ar3,12,26,9), 5*inDaily,expandPoint );
> >
> >
> > Ar4 = TimeFrameCompress(Ref(C,-4),5*inDaily,compressLast);
> >
> > HMACD4 = TimeFrameExpand(HistMACD(Ar4,12,26,9), 5*inDaily,expandPoint );
> >
> >
> >
> > Plot( HMACD0, "Weekly MACDmy Histogram", colorPink, styleArea |
> > styleNoLabel, Null, Null, Null, -1 );
> >
> > Plot( Ref(HMACD1,1), "Weekly MACDmy Histogram", colorGreen, styleArea |
> > styleNoLabel, Null, Null, Null, -1 );
> >
> > Plot( Ref(HMACD2,2), "Weekly MACDmy Histogram", colorOrange, styleArea |
> > styleNoLabel, Null, Null, Null, -1 );
> >
> > Plot( Ref(HMACD3,3), "Weekly MACDmy Histogram", colorPaleGreen, styleArea
> > | styleNoLabel, Null, Null, Null, -1 );
> >
> > Plot( Ref(HMACD4,4), "Weekly MACDmy Histogram", colorGrey50, styleArea |
> > styleNoLabel, Null, Null, Null, -1 );
> >
> > tot = Nz(HMACD0) + Nz(Ref(HMACD1,1)) + Nz(Ref(HMACD2,2)) +
> > Nz(Ref(HMACD3,3)) + Nz(Ref(HMACD4,4));
> >
> >
> > Plot( tot , "Weekly MACDmy Histogram", colorBlack, styleDashed |
> > styleNoLabel, Null, Null, Null, 1 );
> >
> >
> > --- In [email protected], "m.csabee" <m.csabee@> wrote:
> > >
> > > Greetings all,
> > >
> > >
> > > Most charting softwares that I’ve seen always show the weekly
> > > charts of the end of a week, usually Friday.But who says that a week must
> > > end every Friday?Must a weekly chart reflect only the latest five days of
> > > trading every Friday?I think a proper weekly chart should be one that is
> > > set up to reflect one action that is one magnitude greater than the daily
> > > chart.It should display its latest price bar to always reflect where
> > > prices are relative to the latest 5 days of trading.It changes every day
> > > to reflect the latest 5 days of trading.
> > > I would use Stochastic %D on my trading system.
> > > Is it possible somehow to change the last close price every day (get the
> > > recent close price in stochastic formula) and recalculate the weekly
> > > stochastic value each day?
> > > And is it possible to appear this weekly Stochastic and daily Stochastic
> > > in same window?I would use daily price chart with second window with 2
> > > timeframe indicator below.
> > >
> > > thanks for all help
> > > Regards
> > >
> >
>