// Downloaded From https://www.WiseStockTrader.com
//  Formula Name:    Modified Triple Screen Trading System
//  Author/Uploader: Buvanes					 
//  E-mail:          buvanes1989@gmail.com	
//  Date/Time Added: 2010-06-21 13:32:18
//  Origin:          Translated from the "Triple Screen Trading System" by Dennis Skoblar
//  Keywords:        trading system trend
//------------------------------------------------------------------------------------------------------------------
//This is a modified elder impulse system.the original triple screen system is further filtered by 200 day ema. non trending stocks is filtered 
//using ADX directional system. Usually stocks above 20 are said to be stongly trending. I hav used 15 for ADX system. However u can 
//tweak as per ur wish. Also The coloring system use by ELDER is used here. For long only stocks which are blue and green are selected and vice 
//versa. Also for long the daily trend is confirmed by the slope of 22period EMA. Here you can modify any settings 
//as per ur wish for 
//--------------------------------------------------------------------------------------------------------------------
//-----------------------------Modified Triple Screen Trading System--------------------------------------------------
//--------------------------------------For GOING LONG----------------------------------------------------------------
//Stock is above its 200day EMA
//ADX is greater than 15. By this stocks in trading range are ignored
//DAILY MACD HISTOGRAM RISING
//WEEKLY MACD HISTOGRAM RISING
//RSI is greater than 20 and should be less than 90. overbought issues are filtered
//5period EMA is above the 13 period EMA(Both are fibonacci numbers)
//22 period DAILY EMA is rising 
//------------------------------------------------------------------------------------------------------------
//-----------------------------------------FOR GOING SHORT---------------------------------------------------
//Stock is below its 200day EMA
//ADX greater than 15
//DAILY MACD HISTOGRAM IS FALLING
//WEEKLY MACD HISTOGRAM is FALLING
//RSI is greater than 50
//5 period EMA is below the 13period EMA
//22 period dailyEMA is falling
//------------------------------------------------------------------------------------------------------------------


//GOING LONG

//The Close Price of the current bar is GREATER than the EMA (Long) of 1 bar ago */
LongEMA = Param( "LONG EMA LOOKBAVK", 50, 30, 200, 1 );
Buy1 = Close > EMA( C, LongEMA );

//The ADX of the current bar is greater than 15 */
a1=Param("ADX VALUE",20,5,100,1,0);
a2=Param("ADX LOOKBACK PERIOD", 14, 10, 100, 1, 0);
Buy2 = ADX( a2 ) > a1;

//The RSI of the current bar is greater than 20 */
Buy3 = RSIa( Close, 14 ) > 20;

//The RSI of the current bar is less than 90 */
Buy4 = RSIa( Close, 14 ) < 90;

//The Exponential MA (Short) of the current bar is greater than the Exponential MA (Medium) of the current bar */
Buy5 = EMA( Close, 5 ) > EMA( Close, 13 );

//22 PERIOD DAILY EMA IS RISING */
Buy9 = EMA( Close, 22 ) > Ref( EMA( Close, 22 ), -1 );

TimeFrameSet( inWeekly );
WeeklyMACD = MACD(12,26) - Signal(12,26,9);
WeekHistRising = Ref(WeeklyMACD, -1) < Ref(WeeklyMACD, 0);
WeekHistFalling = Ref(WeeklyMACD, -1) > Ref(WeeklyMACD, 0);
TimeFrameRestore();

// Weekly criteria
MACDLongW = WeekHistRising;
MACDShortW= WeekHistFalling;

TimeFrameSet( inDaily );
DailyMACD = MACD(12,26) - Signal(12,26,9);
DHistRising = Ref(DailyMACD, -1) < Ref(DailyMACD, 0);
DHistFalling = Ref(DailyMACD, -1) > Ref(DailyMACD, 0);
TimeFrameRestore();

// DAILY criteria FOR HISTOGRAM
MACDLongD = DHistRising;
MACDShortD= DHistFalling;


// Daily criteria
FIDaily = EMA(V*(C-Ref(C,-1)),2);
FILongD = FIDaily < 0;
FIShortD = FIDaily > 0;

TimeFrameSet( inDaily) ;

//MACD
r1 = Param( "Impulse Fast avg", 12, 2, 200, 1 );
r2 = Param( "Impulse Slow avg", 26, 2, 200, 1 );
r3 = Param( "Impulse Signal avg", 9, 2, 200, 1 );

ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);
Hist = ml-sl;

MACUP = Hist > Ref(Hist,-1);
MACDN = Hist < Ref(Hist,-1);

MA1 = Param( "Impluse MA", 21, 21, 200, 1 );

MAUP = EMA(C,MA1) > Ref(EMA(C,MA1),-1);
MADN = EMA(C,MA1) < Ref(EMA(C,MA1),-1);

BarColor = IIf(Close == Open,
colorBlack,IIf(Close>Open,colorGreen,colorRed));

BarColor  = IIf(MACUP AND MAUP,colorGreen,IIf(MACDN AND
MADN,colorRed,colorBlue));

Sell8 = MACDN AND MADN;

Buy6 = MACUP AND MAUP;

Buy7 = MACUP AND MADN;

Buy8 = MACDN AND MAUP;

// Scan criteria
ElderLong = Buy1 AND Buy2 AND MACDLongW AND MACDLongD AND Buy3 AND Buy4 AND Buy5 AND (Buy6 OR Buy7 OR Buy8) AND Buy9;

//======================================================================================================================


// FOR GOING SHORT

//The Close Price of the current bar is LESSER than the 200 PERIOD EMA */
ShortEMA = Param( "SHORT EMA LOOKBAVK", 50, 30, 200, 1 );
Sell1 = BarsSince( Close >= EMA( C,ShortEMA ) ) >= 1;


/*The RSI has been greater than 70 within the last 5 bars */
s1=Param("SHORT RSI Value", 50, 10, 100, 1, 0);
Sell5 = Ref( HHV( RSIa( Close, 14 ), 5 ), 0 ) > s1;

//5 PERIOD EMA IS LESS THAN 13 PERIOD EMA
Sell6 = EMA( Close, 5 ) <  EMA( Close, 13 );

//22 PERIOD DAILY EMA IS FALLING */
Sell7= EMA( Close, 22 ) < Ref( EMA( Close, 22 ), -1 );

// Scan criteria
ElderShort = Sell1 AND Buy2 AND MACDShortD AND MACDShortW AND Sell5 AND Sell7 AND (Buy7 OR Buy8 OR Sell8);

Buy = ElderLong;
Sell = 0;
Short = ElderShort;
Cover = 0;