Fantastic Intraday Trading System - Only Lacking small modification

#1
Hello Everyone,

I'm Rustom from Hyderabad. I have been using the Schaff Trend Life Cycle indicator along with a few EMAs to identify buying and selling opportunities for intraday trading.

I downloaded the AFL code for the indicator from an open source website and added a few conditions to it so that I could use it as an exploration in Amibroker

The system works like this :-

Buy when EMA(10)>EMA(21)>EMA(50)>EMA(100) and STLC indicator goes above 25
Sell when EMA(10)<EMA(21)<EMA(50)<EMA(100) and STLC indicator goes below 75

When a signal is formed, one needs to wait for confirmation before entering trade. In case of a buy signal, one would enter trade only after a candlestick closes above the high of the candlestick where the signal was formed. In case of a sell signal, one would only short sell after a candlestick closes below the low of the candlestick where the signal was formed.

THE ISSUE: This exploration is coded to the extent of identifying buy and sell signal formation BUT NOT CONFIRMATION.

Can someone please help me with modifying the AFL code so that the exploration only reveals confirmed signals?

Thanks in advance.

The AFL code is as follows:
// Downloaded From www.WiseStockTrader.com
/*
Ported directly from original STC Tradestation code
results differ from other Amibroker versions that are not based directly on original EasyLanguage code
http://mediaserver.fxstreet.com/Rep...886c/ebfbf387-4b27-4a0f-848c-039f4ab77c00.pdf
*/
MA1=23;
MA2=50;
TCLen=10;
MA1=Param("ShortMACDLen",23,5,36);
MA2=Param("LOngMACDLen",50,10,100);
TCLen=Param("TCLen(StochPeriod)",10,5,20);
Factor=.5;
//Calculate a MACD Line
XMac = MACD(MA1,MA2) ; // MACD in Amibroker always uses Close for MACD calculation

//1st Stochastic: Calculate Stochastic of a MACD
Value1 = LLV(XMac, TCLen);
Value2 = HHV(XMac, TCLen) - Value1;

//Frac1=1; // prime Frac1 to a default of 1
//Frac1 = IIf(Value2 > 0, ((XMac - Value1) / Value2) * 100, Ref(FRAC1,-1));
// have to "prime" first value so that reference to "i-1" does not result in subscript out of range
// since MACD for both periods is not defined until MA2 period, 0 seems to be mathematically correct priming value
frac1=0;
for (i = 1; i < BarCount; i++) {
if (Value2 > 0) {
frac1 = ((XMac - Value1)/Value2)*100;
}
else {
frac1= frac1[i-1];
}
}

//Smoothed calculation for %FastD of MACD

PF[0]=frac1[0];
PF[1]=frac1[1];
for (i = 2; i < BarCount; i++) {
PF=PF[i-1]+(Factor*(frac1-PF[i-1]));
}


//2nd Stochastic: Calculate Stochastic of Smoothed Percent FastD, above.
Value3 = LLV(PF, TCLen);
Value4 = HHV(PF, TCLen) - Value3;

//%FastK of PF
/*
Frac2=1;
Frac2 = IIf(Value4 > 0, ((PF - Value3) / Value4) * 100, Ref(FRAC2,-1));
*/

frac2[0]=0;
for (i = 1; i < BarCount; i++) {
if (Value4 > 0 ) {
frac2=((PF - Value3)/Value4)*100;
}
else {
frac2=frac2[i-1];
}
}

//Smoothed calculation for %FastD of PF
PFF[0]=frac2[0];
PFF[1]=frac2[1];
for (i = 2; i < BarCount; i++) {
PFF=PFF[i-1]+(Factor*(frac2-PFF[i-1]));
}

Plot(pff,"STLC",colorRed,styleLine);
Plot(75,"",colorRed,styleLine|styleDashed);
Plot(25,"",colorGreen,styleLine|styleDashed);

A1=Ref(pff,-1);
Bull=EMA(Close,10)>EMA(Close,21) AND EMA(Close,21)>EMA(Close,50)AND EMA(Close,50)>EMA(Close,100) AND pff>25 AND pff>A1;
Bear=EMA(Close,10)<EMA(Close,21) AND EMA(Close,21)<EMA(Close,50)AND EMA(Close,50)<EMA(Close,100) AND pff<75 AND pff<A1;

AlertIf( Bull, "SOUND C:\\Windows\\Media\\Alarm04.wav", "Audio alert", 1 );
AlertIf( Bear, "SOUND C:\\Windows\\Media\\Alarm04.wav", "Audio alert", 1 );

Filter=Bull OR Bear;


AddColumn(Bull,"Level 1 Long",1.2);
AddColumn(Bear,"Level 1 Short",1.2);
 
#5
Hello Friends Plz check code with correction.


MA1=23;
MA2=50;
TCLen=10;
MA1=Param("ShortMACDLen",23,5,36);
MA2=Param("LOngMACDLen",50,10,100);
TCLen=Param("TCLen(StochPeriod)",10,5,20);
Factor=.5;
//Calculate a MACD Line
XMac = MACD(MA1,MA2) ; // MACD in Amibroker always uses Close for MACD calculation

//1st Stochastic: Calculate Stochastic of a MACD
Value1 = LLV(XMac, TCLen);
Value2 = HHV(XMac, TCLen) - Value1;

//Frac1=1; // prime Frac1 to a default of 1
//Frac1 = IIf(Value2 > 0, ((XMac - Value1) / Value2) * 100, Ref(FRAC1,-1));
// have to "prime" first value so that reference to "i-1" does not result in subscript out of range
// since MACD for both periods is not defined until MA2 period, 0 seems to be mathematically correct priming value
frac1=0;
for (i = 1; i < BarCount; i++) {
if (Value2 > 0) {
frac1 = ((XMac - Value1)/Value2)*100;
}
else {
frac1= frac1[i-1];
}
}

//Smoothed calculation for %FastD of MACD

PF[0]=frac1[0];
PF[1]=frac1[1];
for (i = 2; i < BarCount; i++) {
PF=PF[i-1]+(Factor*(frac1-PF[i-1]));
}

//2nd Stochastic: Calculate Stochastic of Smoothed Percent FastD, above.
Value3 = LLV(PF, TCLen);
Value4 = HHV(PF, TCLen) - Value3;

//%FastK of PF
/*
Frac2=1;
Frac2 = IIf(Value4 > 0, ((PF - Value3) / Value4) * 100, Ref(FRAC2,-1));
*/

frac2[0]=0;
for (i = 1; i < BarCount; i++) {
if (Value4 > 0 ) {
frac2=((PF - Value3)/Value4)*100;
}
else {
frac2=frac2[i-1];
}
}

//Smoothed calculation for %FastD of PF
PFF[0]=frac2[0];
PFF[1]=frac2[1];
for (i = 2; i < BarCount; i++) {
PFF=PFF[i-1]+(Factor*(frac2-PFF[i-1]));
}

Plot(pff,"STLC",colorRed,styleLine);
Plot(75,"",colorBlue,styleLine|styleDashed);
Plot(25,"",colorYellow,styleLine|styleDashed);
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?