SuperTrend Error

"I am posting for the first time in this forum. Hope it is in the correct thread. If not, please shift it to the correct thread."

I am attaching herewith two screenshots (one from my Broker provided TradingView Charting platform and the other one from my Ambroker platform. Both are depicting the same symbol (HDFCBANK_NSE), both 5-minute intraday charts, and display SuperTrend Indicator (7,1).

As one may see, although all settings/parameters are the same, the supertrend line in Amibroker crosses the price line almost 50 minutes after it has crossed on the TradingView Chart.

Appreciate if one of the seniors in this forum can point me in the right direction to make the SuperTrend follow the similar pattern as displayed in my broker's charting platform(TradingView).

_SECTION_BEGIN("Supertrend"); 

// SuperTrend parameters
Multiplier = Param("Period", 7, 1, 50 );
Period = Param("Multiplier", 1, 1, 10 );

ResistanceColor = ParamColor("Resistance", colorRed);
SupportColor = ParamColor( "Support", colorGreen);
Style = ParamStyle("Line Style", styleThick);
         
function calculateSupertrend(Period, Multiplier)
{
    ATR_Val=ATR(Period);
 
    UpperBand=LowerBand=final_UpperBand=final_LowerBand=SuperTrend=0;
     
    for( i = Period; i < BarCount; i++ )
    {
        UpperBand[i]=((High[i] + Low[i])/2) + Multiplier*ATR_Val[i];
        LowerBand[i]=((High[i] + Low[i])/2) - Multiplier*ATR_Val[i];
        final_UpperBand[i] = IIf( ((UpperBand[i]<final_UpperBand[i-1]) OR (Close[i-1]>final_UpperBand[i-1])), (UpperBand[i]), final_UpperBand[i-1]);
        final_LowerBand[i] = Iif( ((LowerBand[i]>final_LowerBand[i-1]) OR (Close[i-1]<final_LowerBand[i-1])), (LowerBand[i]), final_LowerBand[i-1]);
             
        SuperTrend[i] = IIf(((SuperTrend[i-1]==final_UpperBand[i-1]) AND (Close[i]<=final_UpperBand[i])),final_UpperBand[i],
        IIf(((SuperTrend[i-1]==final_UpperBand[i-1]) AND (Close[i]>=final_UpperBand[i])),final_LowerBand[i],
        IIf(((SuperTrend[i-1]==final_LowerBand[i-1]) AND (Close[i]>=final_LowerBand[i])),final_LowerBand[i],
        IIf(((SuperTrend[i-1]==final_LowerBand[i-1]) AND (Close[i]<=final_LowerBand[i])),final_UpperBand[i],0))));
 
    }
     
    Plot( SuperTrend, "SuperTrend", IIf( SuperTrend>Close, ResistanceColor, SupportColor), Style);
    Return SuperTrend;  
}
 
SuperTrend = calculateSupertrend(Period,Multiplier);


Buy = Cross(Close,SuperTrend);

Sell = Cross(SuperTrend,Close);


Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-25);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-35);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-30);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=25);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=35);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-30);



_SECTION_END();

Amibroker
TradingView

Perhaps start with these two being swapped.

John.

3 Likes

Thanks, Mate for pointing out my silly typo error.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.