// Downloaded From https://www.WiseStockTrader.com
_SECTION_BEGIN("ADX Systems");
SetChartOptions(0,chartShowArrows|chartShowDates);
PositionSize = 300000;

range = Optimize("period", 14, 3, 100, 1);
MinTrendStrength = 10;
ADXVal = ADX(range);
PDIVal = PDI(range);
MDIVal = MDI(range);

TrendValidity = ADXVal >= MinTrendStrength AND ADXVal > Ref(ADXVal, -1) AND (Ref(ADXVal, -1) > Ref(ADXVal, -2) OR ADXVal > Ref(ADXVal, -2));
TrendStop = IIf(ADXVal > (Ref(ADXVal, -1)) AND Ref(ADXVal,-1) > (Ref(ADXVal, -2)), 0, 1);

BuyCond1 = PDIVal > MDIVal AND TrendValidity;
BuyCond2 = ADXVal > MDIVal AND PDIVal > ADXVal;
BuyCond3 = MDIVal > ADXVal;
Buy =  BuyCond1 AND (BuyCond2 OR BuyCond3);
Sell = TrendStop OR Cross(MDIVal, PDIVal);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
BuyPrice = ValueWhen(Buy,C,1);
SellPrice = ValueWhen(Sell,C, 1);

ShortCond1 = MDIVal > PDIVal AND TrendValidity;
ShortCond2 = ADXVal > PDIVal AND MDIVal > ADXVal;
ShortCond3 = PDIVal > ADXVal;
Short = ShortCond1 AND (ShortCond2 OR ShortCond3);
Cover = TrendStop OR Cross(PDIVal, MDIVal);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
CoverPrice = ValueWhen(Cover,C,1);
ShortPrice = ValueWhen(Short, C ,1);

Filter = Buy OR Sell;

SetOption("NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );
AddColumn(Open,"Open",1);
AddColumn(High,"High",1);
AddColumn(Low,"Low",1);
AddColumn(Close,"Close",1);

GraphXSpace = 10;
Plot( C, "Close", colorBlack, styleCandle );
Shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( Shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, L, H ) );
Shape2 = Cover * shapeHollowUpArrow + Short * shapeHollowDownArrow;
PlotShapes( Shape2, IIf( Cover, colorGreen, colorRed ),0, IIf( Cover, L, H ) );

Title = EncodeColor(colorRed) +  Name() + " - " + EncodeColor(colorBlue)+ Interval(2)  + " (Advanced ADX) " + "  - " + Date() +" - " + EncodeColor(colorBlue) +
"Open-"+ O +"  "+"High-"+ H +"  "+"Low-"+ L +"  "+ "Close-"+ C +"  "+ " Volume = "+WriteVal(V,1.0) + 
EncodeColor(colorLime)+
WriteIf (Buy , "\n" + "GO LONG / Reverse Signal at " + BuyPrice + "  ", "")+
WriteIf (Sell , "\n" + "EXIT LONG / Reverse Signal at " + SellPrice + "  ", "");
_SECTION_END();