Multi timeframe supertrend plot

I am trying to plot daily tf, 15 min tf and 5 min tf supertrend on the same 5 min heikenashi chart.
15 min and 5 min tf supertrend works fine but daily tf supertrend returns empty values.
Kindly suggest some solutions.
Thanks.

SetChartOptions(0,chartShowArrows | chartShowDates);
_SECTION_BEGIN("Plot Heikenashi Chart");
Close = (O + H + L + C)/4; 
Open = AMA( Ref( Close, -1 ), 0.5 ); 
Hi = Max( H, Max( Close, Open ) ); 
Lo = Min( L, Min( Close, Open ) ); 
xDiff = (Hi - lo) * 10000;
barcolor = IIf(Close >= Open,colorGreen,colorRed);
PlotOHLC( Open, Hi, Lo, Close, "", barcolor, styleCandle );
_SECTION_END();

_SECTION_BEGIN("Daily supertrend calculation");
TimeFrameSet(inDaily);
SetBarsRequired(100000,0);

DailySupp=DailyRess=Null;
Close = (O + H + L + C)/4; 
Open = AMA( Ref( Close, -1 ), 0.5 ); 
Hi = Max( H, Max( Close, Open ) ); 
Lo = Min( L, Min( Close, Open ) ); 
xDiff = (Hi - lo) * 10000;
SetChartOptions( 0, chartShowArrows | chartShowDates );
SetBarsRequired( 100000, 0 );

atr1 = Param( "ATR Factor", 3, 1, 20, 0.1 );
per1 = Param( "ATR Period", 21, 3, 100, 1 );

//SetPositionSize( 1, spsShares );
Close = (O + H + L + C)/4; 
Open = AMA( Ref( Close, -1 ), 0.5 ); 
Hi = Max( H, Max( Close, Open ) ); 
Lo = Min( L, Min( Close, Open ) ); 

UpBand1 = ( Hi + Lo ) / 2 + ( atr1 * ATR( per1 ) );
DnBand1 = ( Hi + Lo ) / 2 - ( atr1 * ATR( per1 ) );
indi1 = ATR( per1 );
RessArray = SuppArray = Null;
trend[0] = 1;
changeOfTrend = 0;
flag = flagh = 0;

for ( i = 1; i < BarCount; i++ )
{

    trend[i] = 1;
    trend2[i] = 1;


    if ( Close[i] > UpBand1[i-1] )
    {
        trend[i] = 1;

        if ( trend[i-1] == -1 )
            changeOfTrend = 1;
    }
    else
        if ( Close[i] < DnBand1[i-1] )
        {
            trend[i] = -1;

            if ( trend[i-1] == 1 )
                changeOfTrend = 1;
        }
        else
            if ( trend[i-1] == 1 )
            {
                trend[i] = 1;
                changeOfTrend = 0;
            }
            else
                if ( trend[i-1] == -1 )
                {
                    trend[i] = -1;
                    changeOfTrend = 0;
                }
                
    if ( trend[i] < 0 && trend[i-1] > 0 )
    {
        flag = 1;
    }
    else
    {
        flag = 0;
    }

    if ( trend[i] > 0 && trend[i-1] < 0 )
    {
        flagh = 1;
    }
    else
    {
        flagh = 0;
    }

    if ( trend[i] > 0 && DnBand1[i] < DnBand1[i-1] )
    {
        DnBand1[i] = DnBand1[i-1];
    }

    if ( trend[i] < 0 && UpBand1[i] > UpBand1[i-1] )
    {
        UpBand1[i] = UpBand1[i-1];
    }

    if ( flag == 1 )
    {
        UpBand1[i] = ( Hi[i] + Lo[i] ) / 2 + ( atr1 * indi1[i] );;
    }

    if ( flagh == 1 )
    {
        DnBand1[i] = ( Hi[i] + Lo[i] ) / 2 - ( atr1 * indi1[i] );;
    }

    if ( trend[i] == 1 )
    {
        RessArray[i] = DnBand1[i];

        if ( changeOfTrend == 1 )
        {
            RessArray[i-1] = SuppArray[i-1];
            changeOfTrend = 0;
        }
    }
    else
        if ( trend[i] == -1 )
        {
            SuppArray[i] = UpBand1[i];

            if ( changeOfTrend == 1 )
            {
                SuppArray[i-1] = RessArray[i-1];
                changeOfTrend = 0;
            }
        }
}
DailySupp=SuppArray;
DailyRess=RessArray;
TimeFrameRestore();
Plot( TimeFrameExpand(RessArray,inDaily), "Support", colorYellow );
Plot( TimeFrameExpand(SuppArray,inDaily), "Resistance", colorViolet );

_SECTION_END();


_SECTION_BEGIN("15 min supertrend calculation");
TimeFrameSet(in15Minute);
SetBarsRequired(100000,0);

QhrSupp=QhrRess=Null;
Close = (O + H + L + C)/4; 
Open = AMA( Ref( Close, -1 ), 0.5 ); 
Hi = Max( H, Max( Close, Open ) ); 
Lo = Min( L, Min( Close, Open ) ); 
xDiff = (Hi - lo) * 10000;
SetChartOptions( 0, chartShowArrows | chartShowDates );
SetBarsRequired( 100000, 0 );

atr1 = Param( "ATR Factor", 3, 1, 20, 0.1 );
per1 = Param( "ATR Period", 21, 3, 100, 1 );

//SetPositionSize( 1, spsShares );
Close = (O + H + L + C)/4; 
Open = AMA( Ref( Close, -1 ), 0.5 ); 
Hi = Max( H, Max( Close, Open ) ); 
Lo = Min( L, Min( Close, Open ) ); 

UpBand1 = ( Hi + Lo ) / 2 + ( atr1 * ATR( per1 ) );
DnBand1 = ( Hi + Lo ) / 2 - ( atr1 * ATR( per1 ) );
indi1 = ATR( per1 );
RessArray = SuppArray = Null;
trend[0] = 1;
changeOfTrend = 0;
flag = flagh = 0;

for ( i = 1; i < BarCount; i++ )
{

    trend[i] = 1;
    trend2[i] = 1;


    if ( Close[i] > UpBand1[i-1] )
    {
        trend[i] = 1;

        if ( trend[i-1] == -1 )
            changeOfTrend = 1;
    }
    else
        if ( Close[i] < DnBand1[i-1] )
        {
            trend[i] = -1;

            if ( trend[i-1] == 1 )
                changeOfTrend = 1;
        }
        else
            if ( trend[i-1] == 1 )
            {
                trend[i] = 1;
                changeOfTrend = 0;
            }
            else
                if ( trend[i-1] == -1 )
                {
                    trend[i] = -1;
                    changeOfTrend = 0;
                }
                
    if ( trend[i] < 0 && trend[i-1] > 0 )
    {
        flag = 1;
    }
    else
    {
        flag = 0;
    }

    if ( trend[i] > 0 && trend[i-1] < 0 )
    {
        flagh = 1;
    }
    else
    {
        flagh = 0;
    }

    if ( trend[i] > 0 && DnBand1[i] < DnBand1[i-1] )
    {
        DnBand1[i] = DnBand1[i-1];
    }

    if ( trend[i] < 0 && UpBand1[i] > UpBand1[i-1] )
    {
        UpBand1[i] = UpBand1[i-1];
    }

    if ( flag == 1 )
    {
        UpBand1[i] = ( Hi[i] + Lo[i] ) / 2 + ( atr1 * indi1[i] );;
    }

    if ( flagh == 1 )
    {
        DnBand1[i] = ( Hi[i] + Lo[i] ) / 2 - ( atr1 * indi1[i] );;
    }

    if ( trend[i] == 1 )
    {
        RessArray[i] = DnBand1[i];

        if ( changeOfTrend == 1 )
        {
            RessArray[i-1] = SuppArray[i-1];
            changeOfTrend = 0;
        }
    }
    else
        if ( trend[i] == -1 )
        {
            SuppArray[i] = UpBand1[i];

            if ( changeOfTrend == 1 )
            {
                SuppArray[i-1] = RessArray[i-1];
                changeOfTrend = 0;
            }
        }
}
QhrSupp=SuppArray;
QhrRess=RessArray;

Plot( RessArray, "Support", colorBlue );
Plot( SuppArray, "Resistance", colorOrange );
TimeFrameRestore();

_SECTION_END();



_SECTION_BEGIN("5 min supertrend calculation");
TimeFrameSet(in5Minute);
SetBarsRequired(100000,0);

mainSupp=mainRess=Null;
Close = (O + H + L + C)/4; 
Open = AMA( Ref( Close, -1 ), 0.5 ); 
Hi = Max( H, Max( Close, Open ) ); 
Lo = Min( L, Min( Close, Open ) ); 
xDiff = (Hi - lo) * 10000;
SetChartOptions( 0, chartShowArrows | chartShowDates );
SetBarsRequired( 100000, 0 );

atr1 = Param( "ATR Factor", 3, 1, 20, 0.1 );
per1 = Param( "ATR Period", 21, 3, 100, 1 );

//SetPositionSize( 1, spsShares );
Close = (O + H + L + C)/4; 
Open = AMA( Ref( Close, -1 ), 0.5 ); 
Hi = Max( H, Max( Close, Open ) ); 
Lo = Min( L, Min( Close, Open ) ); 

UpBand1 = ( Hi + Lo ) / 2 + ( atr1 * ATR( per1 ) );
DnBand1 = ( Hi + Lo ) / 2 - ( atr1 * ATR( per1 ) );
indi1 = ATR( per1 );
RessArray = SuppArray = Null;
trend[0] = 1;
changeOfTrend = 0;
flag = flagh = 0;

for ( i = 1; i < BarCount; i++ )
{

    trend[i] = 1;
    trend2[i] = 1;


    if ( Close[i] > UpBand1[i-1] )
    {
        trend[i] = 1;

        if ( trend[i-1] == -1 )
            changeOfTrend = 1;
    }
    else
        if ( Close[i] < DnBand1[i-1] )
        {
            trend[i] = -1;

            if ( trend[i-1] == 1 )
                changeOfTrend = 1;
        }
        else
            if ( trend[i-1] == 1 )
            {
                trend[i] = 1;
                changeOfTrend = 0;
            }
            else
                if ( trend[i-1] == -1 )
                {
                    trend[i] = -1;
                    changeOfTrend = 0;
                }
                
    if ( trend[i] < 0 && trend[i-1] > 0 )
    {
        flag = 1;
    }
    else
    {
        flag = 0;
    }

    if ( trend[i] > 0 && trend[i-1] < 0 )
    {
        flagh = 1;
    }
    else
    {
        flagh = 0;
    }

    if ( trend[i] > 0 && DnBand1[i] < DnBand1[i-1] )
    {
        DnBand1[i] = DnBand1[i-1];
    }

    if ( trend[i] < 0 && UpBand1[i] > UpBand1[i-1] )
    {
        UpBand1[i] = UpBand1[i-1];
    }

    if ( flag == 1 )
    {
        UpBand1[i] = ( Hi[i] + Lo[i] ) / 2 + ( atr1 * indi1[i] );;
    }

    if ( flagh == 1 )
    {
        DnBand1[i] = ( Hi[i] + Lo[i] ) / 2 - ( atr1 * indi1[i] );;
    }

    if ( trend[i] == 1 )
    {
        RessArray[i] = DnBand1[i];

        if ( changeOfTrend == 1 )
        {
            RessArray[i-1] = SuppArray[i-1];
            changeOfTrend = 0;
        }
    }
    else
        if ( trend[i] == -1 )
        {
            SuppArray[i] = UpBand1[i];

            if ( changeOfTrend == 1 )
            {
                SuppArray[i-1] = RessArray[i-1];
                changeOfTrend = 0;
            }
        }
}
mainSupp=SuppArray;
mainRess=RessArray;

Plot( RessArray, "Support", colorGreen );
Plot( SuppArray, "Resistance", colorRed );
TimeFrameRestore();

_SECTION_END();





2020-05-22%20(2)

1 Like