Hi All, good to see you all here i got this one made by none other than mladen himself - titled DMX Simple 1.1 - code below as i dont see the upload
Code: Select all
//+------------------------------------------------------------------+
//| dmx.mq4 |
//| mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 clrDeepSkyBlue
#property indicator_color2 clrRed
#property indicator_color3 clrDimGray
#property strict
//
//
//
//
//
enum enMaTypes
{
ma_sma, // Simple moving average
ma_ema, // Exponential moving average
ma_smma, // Smoothed MA
ma_lwma // Linear weighted MA
};
extern int Length = 32; // DMX period
extern int Smooth = 5; // DMX smoothing
extern enMaTypes SmoothMode = ma_sma; // DMX smoothing mode
extern bool ShowHistogram = true; // Display histogram?
double dmx[],dmxU[],dmxD[];
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int init()
{
int hstyle = (ShowHistogram) ? DRAW_HISTOGRAM : DRAW_NONE;
SetIndexBuffer(0,dmxU); SetIndexStyle(0,hstyle); SetIndexLabel(0,"Dmx");
SetIndexBuffer(1,dmxD); SetIndexStyle(1,hstyle); SetIndexLabel(1,"DmX");
SetIndexBuffer(2,dmx); SetIndexLabel(2,"Dmx");
IndicatorShortName("Dmx ("+(string)Length+")");
return(0);
}
int deinit() { return(0); }
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int start()
{
int counted_bars = IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int limit = MathMin(Bars-counted_bars,Bars-1);
//
//
//
//
//
for(int i=limit; i>=0; i--)
{
double currTR = (i<Bars-1) ? MathMax(High[i],Close[i+1])-MathMin(Low[i],Close[i+1]) : High[i]-Low[i];
double DeltaHi = (i<Bars-1) ? High[i] - High[i+1] : 0;
double DeltaLo = (i<Bars-1) ? Low[i+1] - Low[i] : 0;
double plusDM = 0.00;
double minusDM = 0.00;
if ((DeltaHi>DeltaLo) && (DeltaHi>0)) plusDM = DeltaHi;
if ((DeltaLo>DeltaHi) && (DeltaLo>0)) minusDM = DeltaLo;
double DIp = (currTR>0) ? 100.0*iCustomMa(SmoothMode,plusDM ,Length,i,0)/currTR : iCustomMa(SmoothMode,0,Length,i,0);
double DIm = (currTR>0) ? 100.0*iCustomMa(SmoothMode,minusDM,Length,i,1)/currTR : iCustomMa(SmoothMode,0,Length,i,1);
dmx[i] = ((DIp+DIm) != 0) ? 100.0*iCustomMa(SmoothMode,(DIp-DIm)/(DIp+DIm),Smooth,i,2) : iCustomMa(SmoothMode,0,Smooth,i,2);
//
//
//
//
//
if (ShowHistogram)
{
dmxU[i] = (i<Bars-1) ? (dmx[i]>dmx[i+1]) ? dmx[i] : EMPTY_VALUE : EMPTY_VALUE;
dmxD[i] = (i<Bars-1) ? (dmx[i]<dmx[i+1]) ? dmx[i] : EMPTY_VALUE : EMPTY_VALUE;
}
}
return(0);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
#define _maInstances 3
#define _maWorkBufferx1 1*_maInstances
#define _maWorkBufferx2 2*_maInstances
string averageName(int mode)
{
switch (mode)
{
case ma_sma : return("SMA");
case ma_ema : return("EMA");
case ma_smma : return("SMMA");
case ma_lwma : return("LWMA");
}
return("");
}
double iCustomMa(int mode, double price, double length, int r, int instanceNo=0)
{
r = Bars-r-1;
switch (mode)
{
case ma_sma : return(iSma(price,(int)length,r,instanceNo));
case ma_ema : return(iEma(price,length,r,instanceNo));
case ma_smma : return(iSmma(price,length,r,instanceNo));
case ma_lwma : return(iLwma(price,(int)length,r,instanceNo));
default : return(price);
}
}
//
//
//
//
//
double workSma[][_maWorkBufferx2];
double iSma(double price, int period, int r, int instanceNo=0)
{
if (period<=1) return(price);
if (ArrayRange(workSma,0)!= Bars) ArrayResize(workSma,Bars); instanceNo *= 2; int k;
//
//
//
//
//
workSma[r][instanceNo+0] = price;
workSma[r][instanceNo+1] = price; for(k=1; k<period && (r-k)>=0; k++) workSma[r][instanceNo+1] += workSma[r-k][instanceNo+0];
workSma[r][instanceNo+1] /= 1.0*k;
return(workSma[r][instanceNo+1]);
}
//
//
//
//
//
double workEma[][_maWorkBufferx1];
double iEma(double price, double period, int r, int instanceNo=0)
{
if (ArrayRange(workEma,0)!= Bars) ArrayResize(workEma,Bars);
//
//
//
//
//
workEma[r][instanceNo] = price;
if (r>0 && period>1)
workEma[r][instanceNo] = workEma[r-1][instanceNo]+(2.0 / (1.0+period))*(price-workEma[r-1][instanceNo]);
return(workEma[r][instanceNo]);
}
//
//
//
//
//
double workSmma[][_maWorkBufferx1];
double iSmma(double price, double period, int r, int instanceNo=0)
{
if (period<=1) return(price);
if (ArrayRange(workSmma,0)!= Bars) ArrayResize(workSmma,Bars);
//
//
//
//
//
workSmma[r][instanceNo] = price;
if (r>0 && period>1)
workSmma[r][instanceNo] = workSmma[r-1][instanceNo]+(price-workSmma[r-1][instanceNo])/period;
return(workSmma[r][instanceNo]);
}
//
//
//
//
//
double workLwma[][_maWorkBufferx1];
double iLwma(double price, double period, int r, int instanceNo=0)
{
if (ArrayRange(workLwma,0)!= Bars) ArrayResize(workLwma,Bars);
//
//
//
//
//
period = MathMax(period,1);
workLwma[r][instanceNo] = price;
double sumw = period;
double sum = period*price;
for(int k=1; k<period && (r-k)>=0; k++)
{
double weight = period-k;
sumw += weight;
sum += weight*workLwma[r-k][instanceNo];
}
return(sum/sumw);
}