Hello , I have been trying code this strategy since last 11days but I am not getting it right as the system is not show proper entry , so I really need your help by correcting this code (right entry) .
Buy = Buy only if the 1st candle of current green supertrend goes above prev green or +ve supertrend.
( Plz see attached pics )
Code for entry
Buy = supertrend<C AND C>Ref(supertrend,-1) ;
Sell = supertrend>C ;
Thank you….
Copy & paste for better reference
_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);
Sell = supertrend>C ;
Buy = supertrend<C AND C>Ref(supertrend,-1) ;
Buy = ExRem(Buy,Sell); //remove excessive buy signals
Sell = ExRem(Sell,Buy); //remove excessive sell signals
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
Buy = Buy only if the 1st candle of current green supertrend goes above prev green or +ve supertrend.
( Plz see attached pics )
Code for entry
Buy = supertrend<C AND C>Ref(supertrend,-1) ;
Sell = supertrend>C ;
Thank you….
Copy & paste for better reference
_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);
Sell = supertrend>C ;
Buy = supertrend<C AND C>Ref(supertrend,-1) ;
Buy = ExRem(Buy,Sell); //remove excessive buy signals
Sell = ExRem(Sell,Buy); //remove excessive sell signals
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
Attachments
-
167.1 KB Views: 15