// Downloaded From https://www.WiseStockTrader.com

/*
an exploration system, having separate 3 indicators 

explore to find stocks having BuyPoint/SellPoint >=3 AND ROCSI >=250 to<=900
consider high volume, usestyleCandle for ROCSI in plot.


*/

EMA_Type		= Param("EMA-1, TEMA-2, JMA-3", 2, 1, 3, 1);
EMA_prds 		= Param("EMA_periods", 7, 1, 30, 1);
Std_MACD		= Param("Standard MACD? No-0, Yes-1", 1, 0, 1, 1);
Plot_fashion	= Param("Bar+Arrows-1, Impulse  Bars-2", 2, 1, 2, 1);


// Allow user to define Weekly and Monthly Ribbon Location and Height
WR_P1 = Param("Weekly Ribbon Location", -10.5, -1000, 1000, 0.1);
WR_P2 = Param("Weekly Ribbon Height", 366.5, -0.001, 500, 0.1);

MR_P1 = Param("Monthly Ribbon Location", 5.2, -1000, 1000, 0.1);
MR_P2 = Param("Monthly Ribbon Height", 199, -0.001, 500, 0.1);


// Compute EMA and MACD Histogram
if(EMA_Type == 1)
{
	DayEMA	= EMA(Close, EMA_prds);
}
if (EMA_Type == 2)
{
	DayEMA	= TEMA(Close, EMA_prds);
}

if(EMA_Type == 3)
{
	// Line below to be used with Jurik JMA
	// DayEMA = JurikJMA(C, EMA_Prds);
}

Histogram	= MACD() - Signal();

// Determine if we have an Impulse UP, DOWN or None
Impulse_Up		=	DayEMA > Ref(DayEMA, -1) AND Histogram > Ref(Histogram, -1);
Impulse_Down	=	DayEMA < Ref(DayEMA, -1) AND Histogram < Ref(Histogram, -1);   
Impulse_None		=	(NOT Impulse_UP) AND (NOT Impulse_Down);

// Compute Weekly MACD and determine whether rising or falling
// Note: uses "non-standard"  parameters!
TimeFrameSet(inWeekly);

if (Std_MACD == 0)
{
MACD_val		=	MACD(5, 8);
Signal_val		=	Signal(5, 8, 5);
}
else
{
MACD_val		=	MACD(12, 26);
Signal_val		=	Signal(12, 26, 9);
}

Hist_in_w		=	MACD_val - Signal_val;

wh_rising = Hist_in_w > Ref(Hist_in_w, -1);
wh_falling = Hist_in_w < Ref(Hist_in_w, -1);

TimeFrameRestore();

// Now get Monthly MACD Histogram....
TimeFrameSet(inMonthly);
MACD_val		=	MACD(5, 8);
Signal_val		=	Signal(5, 8, 5);
Hist_in_m		=	MACD_val - Signal_val;

mh_rising = Hist_in_m > Ref(Hist_in_m, -1);
mh_falling = Hist_in_m < Ref(Hist_in_m, -1);

TimeFrameRestore();

wh_rising 		= TimeFrameExpand( wh_rising, inWeekly, expandLast ); 
wh_falling 		= TimeFrameExpand( wh_falling, inWeekly, expandLast); 
mh_rising 	= TimeFrameExpand(mh_rising, inMonthly, expandLast);
mh_falling 	= TimeFrameExpand(mh_falling, inMonthly, expandLast);

kol 	= IIf( wh_rising, colorGreen,  IIf(wh_falling, colorRed, colorLightGrey));
mkol 	= IIf( mh_rising, colorBlue,  IIf(mh_falling, colorYellow,
colorLightGrey));

// Plot them all!
if (Plot_fashion == 1)
{
	//Plot(Close, "Close", colorTeal, styleBar);
	//PlotShapes(shapeUpArrow * Impulse_Up, colorBlue, 0, Low, -12);
	//PlotShapes(shapeDownArrow * Impulse_Down, colorRed, 0, High, -12);
	//PlotShapes(shapeSmallCircle * Impulse_None, colorWhite, 0, High, 5);
}
else
{
	bar_kol	=	IIf(impulse_UP, colorBlue, IIf(impulse_Down, colorRed, colorWhite));
	//Plot(C, "Close", bar_kol, styleBar);
}

//Plot(10, "ribbon", kol, styleOwnScale|styleArea|styleNoLabel, WR_P1, WR_P2);	//
//Weekly trend
//Plot(10, "ribbon", mkol, styleOwnScale|styleArea|styleNoLabel, MR_P1, MR_P2);	//
//Monthly Trend

// Explorer Section
// Determine if Impulse status is bullish, neutral or bearish.  Display as Text
//Column.
Impulse_State		=	WriteIf(Impulse_Up, "Bulllish", WriteIf(Impulse_Down,
"Bearish", "Neutral"));

// Set the background color for Impulse Status Column
Impulse_Col		=	IIf(Impulse_Up, colorGreen, IIf(Impulse_Down, colorRed,
colorLightGrey));

// Determine Weekly Trend. Display as Text Column
Weekly_Trend		=	WriteIf(wh_rising, "Rising", WriteIf(wh_falling, "Falling",
"Flat!"));
Weekly_Col		=	IIf(wh_rising, colorGreen, IIf(wh_falling, colorRed,
colorLightGrey));

// Determine Monthly Trend. Display as Text Column
Monthly_Trend	=	WriteIf(mh_rising, "Rising", WriteIf(mh_falling, "Falling",
"Flat!"));
Monthly_Col		=	IIf(mh_rising, colorGreen, IIf(mh_falling, colorRed,
colorLightGrey));

// Determine how many bars has the current state existed
bars_in_bull	=	Min(BarsSince(impulse_none), BarsSince(impulse_down));
bars_in_bear	=	Min(BarsSince(impulse_up), BarsSince(impulse_none));
bars_in_neut	=	Min(BarsSince(impulse_down), BarsSince(impulse_up));

// Set a single variable to show number of bars in current state depending upon

// actual Impulse Status - Bullish, Bearish or Neutral
bars_in_state	=	IIf(Impulse_Up, bars_in_bull, IIf(Impulse_down, bars_in_bear,
bars_in_neut));

// Columns for display in Explorer 
//AddTextColumn(Impulse_State, "Impulse Status", 1, colorWhite, Impulse_Col);
//AddColumn(bars_in_state, "Bars in this state", 1, colorWhite, Impulse_col);
//AddTextColumn(Weekly_Trend, "Weekly Trend", 1, colorWhite, Weekly_Col);
//AddTextColumn(Monthly_Trend, "Monthly Trend", 1, colorWhite, Monthly_Col);



impBuyCond1= Impulse_Col ==colorGreen AND Ref(Impulse_Col !=colorGreen ,-1);
impShortCond1=Impulse_Col==colorRed  AND Ref(Impulse_Col !=colorRed ,-1);


Buysum=0;
Sellsum=0;
BuySum=impBuyCond1;
Sellsum=impShortCond1;

/*




*/
_SECTION_END();


//////////////////////////////

//non linear

Price = (H+L)/2;
CoefLookback = 5;

Coef = (Price-Ref(Price, -1))^2+(Price-Ref(Price, -2))^2+(Price-Ref(Price, -3))^2+(Price-Ref(Price, -4))^2+(Price-Ref(Price, -5))^2;

SumCoef=0;
SumCoefPrice=0;
for(i=0; i < CoefLookback; i++) {
	SumCoef = SumCoef + Ref(Coef, -i);
	SumCoefPrice = SumCoefPrice + (Ref(Coef, -i) * Ref(Price, -i));
}

DCEF = SumCoefPrice / SumCoef;



//Title = "nonlinear: " + IIf(Close>DCEF, colorGreen, colorRed)+ NumToStr( DCEF, 1.6 );



//Plot(Close, "Close", colorWhite, styleLine);
//Plot(DCEF, "NonLinear Ehlers Filter", IIf(Close>DCEF, colorGreen, colorRed), styleLine);
///////////////////////////////

//Swim

/* SWIM INDEX 
 coded by KAILASH K PAREEK - INDIA .

As the name of indicator explains it self, It measures the
swim of Price. Day Trader may find it very useful as it gives
trend reversal in next 2-3 trading.

INTERPATION: 

Expect trend reversal or at least consolidation when SI 
Spikes higher, (for Peak) OR lower, (for bottom), than 
Relative spikes and turns back. I have found couple of times
The thing called "HING" which appears 1-2 day before the
Price reversal and common in Stochastic Oscillator.


*/

C1 = Ref ( C , -1 ) ;
O1 = Ref ( O, -1 ) ;
K   = HHV ( ( H - C1 ) OR ( L - C1 ) , 1 ) ;
L   =  C1 * 0.20;
R  =  ATR ( 1 );

SI  =  ( ( C-C1+0.5*(C-O)+0.25*(C1-O1))/R)*(K/L);

//Graph0 = SI;


//Plot(SI, "SWIM index",colorGreen , styleArea);

//PlotOHLC( 1.1*SI, 1.1* SI, 1.1* SI, 1.1* SI, 

 //  "Price chart shifted 10% up", colorRed, styleGradient ); 





//Title = "SI: " +EncodeColor( colorRed ) + NumToStr( SI, 1.6 );
/*
_N(Title = StrFormat("{{NAME}} - " +FullName() +
   " - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) SI " +
   WriteVal( SI, 1.6 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( SI,1,True )) )); 


*/


 

Buy1=Cross(Close,DCEF) AND ( SI>0 AND Ref(SI,-1)<0 ) AND (ROC(SI)>0 AND ROC(Ref(SI,-1))<0  );
Sell1=Cross(DCEF,Close) AND ( SI<0 AND Ref(SI,-1)>0 ) AND (ROC(SI)<0 AND ROC(Ref(SI,-1))>0  );



BuySum=BuySum+Cross(Close,DCEF);
Sellsum=Sellsum+Cross(DCEF,Close);



BuySum=BuySum+(( SI>0 AND Ref(SI,-1)< 0.0 ));
Sellsum=Sellsum+(( SI<0 AND Ref(SI,-1)> 0.0 ));



//BuySum=BuySum +(( sign( ROC(SI,1) ) != sign( ROC(Ref(SI,-1),1)) ));
//Sellsum=Sellsum+(( sign( ROC(SI,1)) != sign(ROC(Ref(SI,-1), 1))));

/*
PlotShapes(Buy1*shapeUpArrow,colorGreen,0,DCEF);
PlotShapes(Sell1*shapeDownArrow,colorRed,0,DCEF);
*/

///////////////////
//gmma


/* ------------------------------------------------------------------------------------------------- GUPPY MULTIPLE MOVING AVEREGES ------------------
   Guppy GMMA from AmiBroker Library, enhanced with "derived" Indicators 
 ---------------------------------------------------------------------------*/
EnableTextOutput(False);
GuppyGraphType  = ParamList("Type of Guppy Graphic","Guppy GMMA,Guppy Compressions,Guppy Sonar",0);
// Normalization   = ParamToggle("Normalization Array","CLOSE,EMA30",0);
LocalBuySignal  = LocalSellSignal = 0;
MinMaxPeriod    = 20;
// --- DEFINE/CALCULATE ALL DATA NEEDED FOR BUY & SELL COMPOSITE SIGNALS outside the IndicatorType IF --- 
EMA03           = EMA(Close,3); 
EMA15           = EMA(Close,15);
EMA30           = EMA(Close,30);
EMA60           = EMA(Close, 60);
NormalizerArray = EMA30;   // IIf(Normalization == 0, Close, EMA30);
//
GMMADeltaPerc   = ((EMA(Close,9)- EMA(Close,35)) / EMA(Close,35)) * 100;  //default 15,30

      
       GMMAUP    = GMMADeltaPerc > Ref(GMMADeltaPerc,-1);
       GMMADOWN  = GMMADeltaPerc < Ref(GMMADeltaPerc,-1);
       BarColor  = IIf(GMMAUP AND GMMADeltaPerc >= 0,colorBrightGreen, IIf(GMMADOWN AND GMMADeltaPerc > 0,colorGreen, IIf(GMMAUP AND GMMADeltaPerc < 0, colorRed, colorDarkRed)));
      // Plot(GMMADeltaPerc, "\\c16, % Gap \\c29T\\c16 - \\c32INV\\c16 vs EMA(30)", BarColor, styleHistogram | styleThick );   
		// Plot(GMMADeltaPerc ,"up",colorAqua);
  /*    Title = "sonar: "  + "UP "+NumToStr( GMMAUP, 1.2 )+
					"  DOWN "+NumToStr( GMMADOWN  , 1.2 );
*/
        


BuySum=BuySum+ ((GMMAUP==1)&& (Ref(GMMAUP,-1)==0));
Sellsum=Sellsum+((GMMADOWN==1)&& (Ref(GMMADOWN,-1)==0));

AddColumn(Close,"close");
AddColumn(BuySum,"BuyPoints");
AddColumn(Sellsum,"SellPoints");
AddColumn(ROC(SI,1),"rocSI");

period = 14;
formula=100*( ( RSI( period ) - LLV( RSI( period ) , period ) ) / ( ( HHV( RSI(
period ) , period ) ) - LLV(RSI( period ), period ) ) );

//AddColumn(ROC(formula,2),"ROCstck");
//AddColumn(formula,"stck");

//Filter=abs(ROC(SI,1))>200;
//Filter=1;

Cond1= (BuySum>=3 OR SellSum >=3 ); 
Filter=Cond1;
txt=WriteIf(BuySum>=3,NumToStr(BuySum), 
          WriteIf(SellSum>=3,NumToStr(SellSum)," ") );

///////////////////////////////////////////

txtBuy="";
/*
AddColumn(impBuyCond1,"imp Buy",1);
AddColumn(Cross(Close,DCEF),"nl Buy");
AddColumn(( SI>0 AND Ref(SI,-1)< 0.0 ),"SIBuy" );
//AddColumn( sign(ROC(SI,1)) != sign(ROC(Ref(SI,-1),1)) ,"ROC(SI)Buy" );
AddColumn((GMMAUP==1)&& (Ref(GMMAUP,-1)==0),"GMMABuy");
*/
txtBuy= WriteIf(Cross(Close,DCEF)," nl ","");
txtBuy=txtBuy+ WriteIf(impBuyCond1," elder ","");
txtBuy= txtBuy+WriteIf(( SI>0 AND Ref(SI,-1)< 0.0 )," si ","");
txtBuy= txtBuy+WriteIf(sign(ROC(SI,1)) != sign(ROC(Ref(SI,-1),1))," roc(si) ","");


txtSell="";
/*
AddColumn(impShortCond1,"imp Sell",1);
AddColumn(Cross(DCEF,Close),"nl Sell" );
AddColumn(( SI<0 AND Ref(SI,-1)> 0.0 ),"SISell");
AddColumn( sign(ROC(SI,1)) != sign(ROC(Ref(SI,-1),1))  ,"ROC(SI)" ); 
AddColumn((GMMADOWN==1)&& (Ref(GMMADOWN,-1)==0),"GyyMMASell" );
*/

txtSell= WriteIf(Cross(DCEF,Close)," nl ","");
txtSell=txtSell+ WriteIf(impShortCond1," elder ","");
txtSell=txtSell+ WriteIf(( SI<0 AND Ref(SI,-1)> 0.0 )," si ","");
txtSell=txtSell+ WriteIf(sign(ROC(SI,1)) != sign(ROC(Ref(SI,-1),1))," roc(si) ","");


//---------------------------------------------------------------------------------------
BBVol=(Volume/EMA(Volume,30))*100;


Vol1=IIf(  Sum(BBVol>EMA(BBVol,30),2)>0,BBVol,0);
//------------------------------------------------------------------------------------
//Plot(BuySum,"nl",colorGreen,styleHistogram);
//Plot(SellSum,"nl",colorRed,styleHistogram);

tmp=IIf( Sum(BuySum,2)>=3,Sum(BuySum,2),IIf(Sum(SellSum,2)>=3,Sum(SellSum,2),0));


Filter= (tmp>=3);

AddColumn(tmp>=3,"score");
AddColumn(Vol1,"volume");
AddTextColumn(txtBuy+txtSell,"txt");


//Title="buySum: "+BuySum+" SellSum: "+SellSum+
 //  " buy-> "+txtBuy+ " Sell->"+txtSell; 


SetSortColumns( -2,-8 ) ;


AlertIf( tmp>=3, "SOUND C:\\Windows\\Media\\Notify.WAV", "score: "+tmp+ " "+txtBuy +txtSell+
 "volume: "+WriteVal(Vol1) 
, 0 ,1+2+8,5);

///////////////////////////////////

/*


FirstTradeTime = 091500;				// Earliest time to take a trade
LastTradeTime = 151500;					// Latest time to take new trades
ExitAllPositionsTime = 151500;	

change = Param("% change",0.6,0.1,25,0.1); 
z = Zig(Close, change);

Buy=(BuyCond)  AND (TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTime );
Sell = IIf(z < Ref(z, -1), 1, 0) ;//OR TimeNum() > ExitAllPositionsTime;
Short=(ShortCond) AND (TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTime );
Cover = IIf(z > Ref(z, -1), 1, 0);// OR	 TimeNum() > ExitAllPositionsTime;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short); 
*/

/////////////