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

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleBar|styleThick|styleNoTitle); 
_SECTION_END();


// Hien thi cac duong MA50
_SECTION_BEGIN("MA50"); 
MA50 = MA(C,50);
maup = MA50 > Ref(MA50,-1);
colorma50 = IIf( maup, ParamColor("Up Color", colorGreen), ParamColor("Down Color", colorRed )); /* choose color */
if (ParamToggle("MA50", "No|Yes", 1 ))
{
Plot(MA50,"MA50",colorma50,styleLine | styleLine,0,0,1); 

}
_SECTION_END();

// Hien thi cac duong MA200
_SECTION_BEGIN("MA200"); 
MA200 = MA(C,200);
maup = MA200 > Ref(MA200,-1);
colorma200 = IIf( maup, ParamColor("Up Color", colorLightBlue), ParamColor("Down Color", colorRed )); /* choose color */
if (ParamToggle("MA200", "No|Yes", 1 ))
{
Plot(MA200,"MA200",colorma200,styleThick,0,0,1); 

}
_SECTION_END();

// Hien thi cac duong MA200
_SECTION_BEGIN("ICHIMOKU"); 
P1 = Param("Conversion Period", 9, 2, 200, 1, 0);
C1 = ParamColor("Conversion Color", colorBlue);
CL = (HHV(H,P1)+LLV(L,P1))/2;

P2 = Param("Base Period", 26, 2, 200, 1, 0);
C2 = ParamColor("Base Color", colorRed);
BL = (HHV(H,P2)+LLV(L,P2))/2;

C3 = ParamColor("Leading A Color", colorBrightGreen);
LSA = (CL+BL)/2;

P4 = Param("Leading B Span", 52, 2, 200, 1, 0);
C4 = ParamColor("Leading B Color", colorPink);
LSB = (HHV(H,P4)+LLV(L,P4))/2;

P3 = Param("Leading Span Displacement", 26, 2, 200, 1, 0);

P5 = Param("Lagging Displacement", -26, 2, 200, 1, 0);
C5 = ParamColor("Lagging Color", colorGreen);


if (ParamToggle("Kijun", "No|Yes", 1 ))
{
//Plot(CL,"Tenkan-sen (Conversion Line)", C1, styleLine);
Plot(BL, "Kijun-sen", colorCustom12, styleLine);
//Plot(LSA, "Senkou Span A (Leading Span A)", C3, styleLine, 0, 0, P3);
//Plot(LSB, "Senkou Span B (Leading Span B)", C4, styleLine, 0, 0, P3);
//Plot(C, "Chikou Span (Lagging Span)", C5, styleLine, 0, 0, P5);
//PlotOHLC (LSA,LSA,LSB,LSB,"Cloud",IIf(LSA>LSB,ColorBlend(C3, colorWhite, 0.6),ColorBlend(C4,colorWhite, 0.4)),styleCloud, 0, 0, P3);

}
if (ParamToggle("Cloud", "No|Yes", 1 ))
{
//Plot(CL,"Tenkan-sen (Conversion Line)", C1, styleLine);
//Plot(BL, "Kijun-sen", colorCustom12, styleLine);
//Plot(LSA, "Senkou Span A (Leading Span A)", C3, styleLine, 0, 0, P3);
//Plot(LSB, "Senkou Span B (Leading Span B)", C4, styleLine, 0, 0, P3);
//Plot(C, "Chikou Span (Lagging Span)", C5, styleLine, 0, 0, P5);
PlotOHLC (LSA,LSA,LSB,LSB,"Cloud",IIf(LSA>LSB,ColorBlend(C3, colorWhite, 0.6),ColorBlend(C4,colorWhite, 0.4)),styleCloud, 0, 0, P3);

}

_SECTION_END();


_SECTION_BEGIN("7. Volume");

if (ParamToggle("Volume", "No|Yes", 1 ))
{
//Chon mau Volume
VolumeUpcolor       = ParamColor(" - Volume Color Up",      colorGreen );
VolumeDown          = ParamColor(" - Volume Color Down",    colorDarkRed ) ;
Volumecolor         = IIf(C> O, VolumeUpcolor,VolumeDown);

//Chon MAVolume
Volumeperiod       = Param     (" - Volume MA Periods ", 50,  1, 500, 1); 
maVolume           = MA(V,Volumeperiod);                               //Tinh MA Volume theo ky da chon
PmaVolume          = V/maVolume*100;                                   //% Volume so voi Volume trung binh 


Volumeheight       = Param     (" - Volume Height", 4, 1, 100, 1.0) ; // Chieu cao Volume
PaneHghtMin        = LowestVisibleValue( V);
PaneHghtMax        = HighestVisibleValue(V) *Volumeheight;

maVolumecolor      = ParamColor(" - Volume MA Color", colorOrange);

//***************************************** 
//Ve duong Volume

PlotOHLC(0, V, 0, V, "" ,VolumeColor, styleCandle|  styleOwnScale | styleThick | styleNoLabel|styleNoRescale,   PaneHghtMin, PaneHghtMax, 0, 0, 1);
 
//***************************************** 
//Ve line MA Volume 
Plot(maVolume,"MA Volume", maVolumecolor, styleLine| styleNoTitle | styleOwnScale | styleThick | styleNoLabel|styleNoRescale,   PaneHghtMin, PaneHghtMax, 0, 0, 1);

//Ve may MA Volume 
PlotOHLC( Volume, Volume, Volume, Volume, "\nVolume", ParamColor(" - Volume Cloud Color",  colorViolet ), styleGradient| styleOwnScale | styleThick | styleNoLabel|styleNoRescale,   PaneHghtMin, PaneHghtMax, 0, 0, 1);
//PlotOHLC( maVolume, maVolume, maVolume, maVolume, "\nMA Volume", colorLime , styleGradient| styleOwnScale | styleThick | styleNoLabel|styleNoRescale,   PaneHghtMin, PaneHghtMax, 0, 0, 1);
PlotOHLC( PmaVolume, PmaVolume, PmaVolume, PmaVolume, "\n%Chg V/MA", colorYellow, styleGradient| styleOwnScale | styleThick | styleNoLabel|styleNoRescale,   PaneHghtMin, PaneHghtMax, 0, 0, 1);
    
	
}


// Dot pha giai doan 2 theo Stan Weinstein
// gia tren MA200, MA200 huong len,
// RS performance > ma200, RS tang
// Vol trong ngay dot pha tang it nhat 200%, tot nhat la tren 300%

//HANH DONG GIA:  Gia tren duong MA200, MA200 tang, gia ben tren Kijun
MA200 = MA(C,200);
MA50 = MA(C,50);
Uptrend = MA200 > Ref(MA200,-1) AND C > MA200 AND C > BL;


//SETUP hieu suat tuong doi ben tren vach 0
bi = BarIndex();
fvb = Max(0,BeginValue(bi));// Status("firstvisiblebar");
lvb = EndValue(bi);
barcond = bi >= fvb AND bi <= lvb;
RSL = (( C - C[ fvb ] ) / C[ fvb ]);
rslb = 100*RSL;
marslb = MA(rslb ,200);
rsup = rslb > marslb AND rslb > Ref(rslb,-1);

//vol 
MAvol = MA(V,20);
Chgvol = V/MAvol*100;
Chggia = (C - Ref(C,-1))/Ref(C,-1)*100;
thaydoigiatien =(C - Ref(C,-1));


//SETUP BUY SIGNAL

Sigbuy1 = Uptrend AND V >= 2*MAvol AND rsup;
Sigbuy2 = C >5 AND MAvol > 500000;

Buy = Sigbuy1 AND Sigbuy2;
Sell = Cross(BL,C);
Buy = ExRem(Buy, Sell);
Sell= ExRem(Sell, Buy);

PlotShapes(Buy*shapeUpArrow, colorBlue,0,L,-25);
PlotShapes(Sell*shapeDownArrow, colorOrange,0,H,-25);

Filter = Buy;

AddColumn (Chgvol, "Vol% vs 20 day");
AddColumn (C, "Price today");
AddColumn (thaydoigiatien , "Price $ Chg");
AddColumn (chggia, "Price % Chg");
AddColumn (V, "Volume");

// resistance and support
HaClose =EMA((O+H+L+C)/4,3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) ); 


_SECTION_BEGIN("Resistance");

supres=ParamToggle("Sup_Res","No|Yes",1);
if(supres)
{


Prd1=Param("Res_Period1",2,0,200,1);
                   
test   = TEMA  ( High , Prd1 ) ;   

PK = test > Ref(test,-1) AND Ref(test,1) < High;//Peak
PKV0 = ValueWhen(PK,haHigh,0);//PeakValue0
PKV1 = ValueWhen(PK,haHigh,1);//PeakValue1
PKV2 = ValueWhen(PK,haHigh,2);//PeakValue2

MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak

MPKV = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,1); //MajorPeakValue
MPKD = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),1); //MajorPeakDate
SD = IIf(DateNum() < LastValue(MPKD,lastmode = True ), Null, LastValue(MPKV,Lastmode = True));//SelectedDate
Plot(SD, "Resist1",  colorBrown,ParamStyle("ResStyle1",styleLine|styleNoTitle,maskAll));

MPKV2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,2); //MajorPeakValue
MPKD2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),2); //MajorPeakDate
SD2 = IIf(DateNum() < LastValue(MPKD2,lastmode = True ), Null, LastValue(MPKV2,Lastmode = True));//SelectedDate
Plot(SD2, "Resist2",  colorBrown,ParamStyle("ResStyle2",styleLine|styleNoTitle,maskAll));


MPKV3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,3); //MajorPeakValue
MPKD3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),3); //MajorPeakDate
SD3 = IIf(DateNum() < LastValue(MPKD3,lastmode = True ), Null, LastValue(MPKV3,Lastmode = True));//SelectedDate
Plot(SD3, "Resist3", colorBrown,ParamStyle("ResStyle3",styleLine|styleNoTitle,maskAll));


MPKV4 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,4); //MajorPeakValue
MPKD4 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),4); //MajorPeakDate
SD4 = IIf(DateNum() < LastValue(MPKD4,lastmode = True ), Null, LastValue(MPKV4,Lastmode = True));//SelectedDate
Plot(SD4, "Resist4",  colorBrown,ParamStyle("ResStyle4",styleLine|styleNoTitle,maskAll));



MPKV5 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,5); //MajorPeakValue
MPKD5 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),5); //MajorPeakDate
SD5 = IIf(DateNum() < LastValue(MPKD5,lastmode = True ), Null, LastValue(MPKV5,Lastmode = True));//SelectedDate
Plot(SD5, "Resist5",  colorBrown,ParamStyle("ResStyle5",styleLine|styleNoTitle,maskAll));


MPKV6 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,6); //MajorPeakValue
MPKD6 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),6); //MajorPeakDate
SD6 = IIf(DateNum() < LastValue(MPKD6,lastmode = True ), Null, LastValue(MPKV6,Lastmode = True));//SelectedDate
Plot(SD6, "Resist6", colorBrown ,ParamStyle("ResStyle6",styleLine|styleNoTitle,maskAll));




_SECTION_END();


_SECTION_BEGIN("Support");
//SP=L > Ref(L,-1) AND Ref(L,1) < L;//Peak

Prd2=Param("Sup_Period1",2,0,200,1);
                   
test2   = TEMA ( Low , Prd2 ) ;   

SP = Ref(test2,1) > Low AND test2 < Ref(test2,-1);//Peak
SPV0 = ValueWhen(SP,haLow,0);//PeakValue0
SPV1 = ValueWhen(SP,haLow,1);//PeakValue1
SPV2 = ValueWhen(SP,haLow,2);//PeakValue2

//PKV5 = ValueWhen(PK,haHigh,5);//PeakValue5
//PKV6 = ValueWhen(PK,haHigh,6);//PeakValue6

MSP = SPV2 > SPV1 AND SPV1 < SPV0 ;//MajorPeak

MSPV = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,1);
MSPD = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),1);
SD = IIf(DateNum() < LastValue(MSPD,lastmode = True ), Null, LastValue(MSPV,Lastmode = True));
Plot(SD,"Support1",  colorPlum,ParamStyle("SupportLine1",styleLine|styleNoTitle,maskAll));



MSPV2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,2);
MSPD2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),2);
SD2 = IIf(DateNum() < LastValue(MSPD2,lastmode = True ), Null, LastValue(MSPV2,Lastmode = True));
Plot(SD2,"Support2",  colorPlum,ParamStyle("SupportLine2",styleLine|styleNoTitle,maskAll));



MSPV3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,3);
MSPD3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),3);
SD3 = IIf(DateNum() < LastValue(MSPD3,lastmode = True ), Null, LastValue(MSPV3,Lastmode = True));
Plot(SD3,"Support3",  colorPlum,ParamStyle("SupportLine3",styleLine|styleNoTitle,maskAll));


MSPV4 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,4);
MSPD4 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),4);
SD4 = IIf(DateNum() < LastValue(MSPD4,lastmode = True ), Null, LastValue(MSPV4,Lastmode = True));
Plot(SD4,"Support4",  colorPlum,ParamStyle("SupportLine4",styleLine|styleNoTitle,maskAll));


MSPV5 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,5);
MSPD5 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),5);
SD5 = IIf(DateNum() < LastValue(MSPD5,lastmode = True ), Null, LastValue(MSPV5,Lastmode = True));
Plot(SD5,"Support5",  colorPlum,ParamStyle("SupportLine5",styleLine|styleNoTitle,maskAll));


MSPV6 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,6);
MSPD6 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),6);
SD6 = IIf(DateNum() < LastValue(MSPD6,lastmode = True ), Null, LastValue(MSPV6,Lastmode = True));
Plot(SD6,"Support6",  colorPlum,ParamStyle("SupportLine6",styleLine|stylehidden|styleNoTitle,maskAll));

}

_SECTION_END();