//-------------------------------------------------------------------
// original : ANG3110
// this version : mladen
//-------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 LightSlateGray
#property indicator_color2 DodgerBlue
#property indicator_color3 SandyBrown
#property indicator_color4 SandyBrown
#property indicator_style1 STYLE_DOT
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
extern int period = 14;
extern int Level = 25;
extern double Smooth = 15;
extern bool alertsOn = true;
extern bool alertsOnCurrent = false;
extern bool alertsMessage = false;
extern bool alertsSound = false;
extern bool alertsEmail = false;
extern bool alertsNotify = false;
extern string soundFile = "alert2.wav";
double ADX[],ADXLa[],ADXLb[],DI[],slope[];
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//
int init()
{
IndicatorBuffers(5);
SetIndexBuffer(0,DI);
SetIndexBuffer(1,ADX);
SetIndexBuffer(2,ADXLa);
SetIndexBuffer(3,ADXLb);
SetIndexBuffer(4,slope);
SetLevelValue(0,0);
SetLevelValue(1, Level);
SetLevelValue(2,-Level);
IndicatorShortName("ADXm "+"("+period+","+DoubleToStr(Smooth,2)+")");
return(0);
}
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//
double work[][3];
#define zdh 0
#define zdl 1
#define zdx 2
int start()
{
int i,r,counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
double alpha = 2.0/(period+1);
int limit = MathMin(Bars-counted_bars,Bars-1);
if (ArrayRange(work,0)!=Bars) ArrayResize(work,Bars);
//
//
//
//
//
if (slope[limit]==-1) CleanPoint(limit,ADXLa,ADXLb);
for (i=limit,r=Bars-i-1; i>=0; i--,r++)
{
if (i==Bars-1) { work[r][zdh] = 0; work[r][zdl] = 0; work[r][zdx] = 0; continue; }
double hc = iSsm(High[i] ,Smooth,i,0);
double lc = iSsm(Low[i] ,Smooth,i,1);
double cp = iSsm(Close[i+1],Smooth,i,2);
double hp = iSsm(High[i+1] ,Smooth,i,3);
double lp = iSsm(Low[i+1] ,Smooth,i,4);
double dh = MathMax(hc-hp,0);
double dl = MathMax(lp-lc,0);
if(dh==dl) {dh=0; dl=0;} else if(dh
ADX[i+1]) slope[i] = 1;
if (ADX[i]=Bars-3) return;
if ((second[i] != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))
second[i+1] = EMPTY_VALUE;
else
if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))
first[i+1] = EMPTY_VALUE;
}
void PlotPoint(int i,double& first[],double& second[],double& from[])
{
if (i>=Bars-2) return;
if (first[i+1] == EMPTY_VALUE)
if (first[i+2] == EMPTY_VALUE)
{ first[i] = from[i]; first[i+1] = from[i+1]; second[i] = EMPTY_VALUE; }
else { second[i] = from[i]; second[i+1] = from[i+1]; first[i] = EMPTY_VALUE; }
else { first[i] = from[i]; second[i] = EMPTY_VALUE; }
}
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//
#define Pi 3.14159265358979323846264338327950288
double workSsm[][10];
#define _tprice 0
#define _ssm 1
double workSsmCoeffs[][4];
#define _period 0
#define _c1 1
#define _c2 2
#define _c3 3
//
//
//
//
//
double iSsm(double tprice, double tperiod, int i, int instanceNo=0)
{
if (tperiod<=1) return(tprice); i = Bars-i-1;
if (ArrayRange(workSsm,0) !=Bars) ArrayResize(workSsm,Bars);
if (ArrayRange(workSsmCoeffs,0) < (instanceNo+1)) ArrayResize(workSsmCoeffs,instanceNo+1);
if (workSsmCoeffs[instanceNo][_period] != tperiod)
{
workSsmCoeffs[instanceNo][_period] = tperiod;
double a1 = MathExp(-1.414*Pi/tperiod);
double b1 = 2.0*a1*MathCos(1.414*Pi/tperiod);
workSsmCoeffs[instanceNo][_c2] = b1;
workSsmCoeffs[instanceNo][_c3] = -a1*a1;
workSsmCoeffs[instanceNo][_c1] = 1.0 - workSsmCoeffs[instanceNo][_c2] - workSsmCoeffs[instanceNo][_c3];
}
//
//
//
//
//
int s = instanceNo*2;
workSsm[i][s+_tprice] = tprice;
if (i>1)
workSsm[i][s+_ssm] = workSsmCoeffs[instanceNo][_c1]*(workSsm[i][s+_tprice]+workSsm[i-1][s+_tprice])/2.0 +
workSsmCoeffs[instanceNo][_c2]*workSsm[i-1][s+_ssm] +
workSsmCoeffs[instanceNo][_c3]*workSsm[i-2][s+_ssm];
else workSsm[i][s+_ssm] = tprice;
return(workSsm[i][s+_ssm]);
}
//+------------------------------------------------------------------+
//
//
//
//
void doAlert(string doWhat)
{
static string previousAlert="nothing";
static datetime previousTime;
string message;
if (previousAlert != doWhat || previousTime != Time[0]) {
previousAlert = doWhat;
previousTime = Time[0];
//
//
//
//
//
message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," ADXm ",doWhat);
if (alertsMessage) Alert(message);
if (alertsNotify) SendNotification(message);
if (alertsEmail) SendMail(StringConcatenate(Symbol()," ADXm "),message);
if (alertsSound) PlaySound(soundFile);
}
}