I am trying to plot lastvalue line on supertrend but it is not showing the lastvalue line on candle , so plz correct my code and help me to get lastvalue of supertrend on candle.
CODE
_SECTION_BEGIN("My first trading Strategy");
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetChartOptions(0,chartShowArrows|chartShowDates); //Enable X-Axis (Date/Time Axis)
Plot(Close,"Candles",colorDefault,styleCandle); //Plot Candles
_SECTION_END();
// SUPERTRENT FUNCTION //
function FunctionST (Period, Multiplier)
{
ATR_Val=ATR(Period);
UpperBand=LowerBand=final_UpperBand=final_LowerBand=SuperTrend=0;
// CALCULATE SUPERTRENT //
for( i = Period; i < BarCount; i++ )
{
UpperBand=((High + Low)/2) + Multiplier*ATR_Val;
LowerBand=((High + Low)/2) - Multiplier*ATR_Val;
final_UpperBand = IIf( ((UpperBand<final_UpperBand[i-1]) OR (Close[i-1]>final_UpperBand[i-1])), (UpperBand), final_UpperBand[i-1]);
final_LowerBand = Iif( ((LowerBand>final_LowerBand[i-1]) OR (Close[i-1]<final_LowerBand[i-1])), (LowerBand), final_LowerBand[i-1]);
SuperTrend = IIf(((SuperTrend[i-1]==final_UpperBand[i-1]) AND (Close<=final_UpperBand)),final_UpperBand,
IIf(((SuperTrend[i-1]==final_UpperBand[i-1]) AND (Close>=final_UpperBand)),final_LowerBand,
IIf(((SuperTrend[i-1]==final_LowerBand[i-1]) AND (Close>=final_LowerBand)),final_LowerBand,
IIf(((SuperTrend[i-1]==final_LowerBand[i-1]) AND (Close<=final_LowerBand)),final_UpperBand,0))));
}
Plot( SuperTrend, "SuperTrend", (IIf( SuperTrend>Close, ParamColor("Resistance", colorRed ), ParamColor( "Support", colorGreen ))), ParamStyle("Style") | styleThick | styleLine );
Return SuperTrend;
}
Periods_set = Param("Periods", 1, 1, 50 );
Multiplier_set = Param("Multiplier ", 1, 1, 10 );
Multiplier = Multiplier_set;
Period = Periods_set ;
SuperTrend = FunctionST(Period,Multiplier);
buuy = supertrend<C;
seel= supertrend>C;
lasval=LastValue(seel);
Plot(lasval,"lasval",colorRed);
CODE
_SECTION_BEGIN("My first trading Strategy");
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetChartOptions(0,chartShowArrows|chartShowDates); //Enable X-Axis (Date/Time Axis)
Plot(Close,"Candles",colorDefault,styleCandle); //Plot Candles
_SECTION_END();
// SUPERTRENT FUNCTION //
function FunctionST (Period, Multiplier)
{
ATR_Val=ATR(Period);
UpperBand=LowerBand=final_UpperBand=final_LowerBand=SuperTrend=0;
// CALCULATE SUPERTRENT //
for( i = Period; i < BarCount; i++ )
{
UpperBand=((High + Low)/2) + Multiplier*ATR_Val;
LowerBand=((High + Low)/2) - Multiplier*ATR_Val;
final_UpperBand = IIf( ((UpperBand<final_UpperBand[i-1]) OR (Close[i-1]>final_UpperBand[i-1])), (UpperBand), final_UpperBand[i-1]);
final_LowerBand = Iif( ((LowerBand>final_LowerBand[i-1]) OR (Close[i-1]<final_LowerBand[i-1])), (LowerBand), final_LowerBand[i-1]);
SuperTrend = IIf(((SuperTrend[i-1]==final_UpperBand[i-1]) AND (Close<=final_UpperBand)),final_UpperBand,
IIf(((SuperTrend[i-1]==final_UpperBand[i-1]) AND (Close>=final_UpperBand)),final_LowerBand,
IIf(((SuperTrend[i-1]==final_LowerBand[i-1]) AND (Close>=final_LowerBand)),final_LowerBand,
IIf(((SuperTrend[i-1]==final_LowerBand[i-1]) AND (Close<=final_LowerBand)),final_UpperBand,0))));
}
Plot( SuperTrend, "SuperTrend", (IIf( SuperTrend>Close, ParamColor("Resistance", colorRed ), ParamColor( "Support", colorGreen ))), ParamStyle("Style") | styleThick | styleLine );
Return SuperTrend;
}
Periods_set = Param("Periods", 1, 1, 50 );
Multiplier_set = Param("Multiplier ", 1, 1, 10 );
Multiplier = Multiplier_set;
Period = Periods_set ;
SuperTrend = FunctionST(Period,Multiplier);
buuy = supertrend<C;
seel= supertrend>C;
lasval=LastValue(seel);
Plot(lasval,"lasval",colorRed);