non lag ma mtf histo alerts arrows
//------------------------------------------------------------------
#property copyright "www.forex-station.com"
#property link "www.forex-station.com"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_minimum 0
#property indicator_maximum 1
#property strict
//
//
//
//
//
enum enPrices
{
pr_close, // Close
pr_open, // Open
pr_high, // High
pr_low, // Low
pr_median, // Median
pr_typical, // Typical
pr_weighted, // Weighted
pr_average, // Average (high+low+open+close)/4
pr_medianb, // Average median body (open+close)/2
pr_tbiased, // Trend biased price
pr_tbiased2, // Trend biased (extreme) price
pr_haclose, // Heiken ashi close
pr_haopen , // Heiken ashi open
pr_hahigh, // Heiken ashi high
pr_halow, // Heiken ashi low
pr_hamedian, // Heiken ashi median
pr_hatypical,// Heiken ashi typical
pr_haweighted, // Heiken ashi weighted
pr_haaverage,// Heiken ashi average
pr_hamedianb,// Heiken ashi median body
pr_hatbiased,// Heiken ashi trend biased price
pr_hatbiased2// Heiken ashi trend biased (extreme) price
};
enum enFilterWhat
{
flt_prc,// Filter the price
flt_val,// Filter the non lag ma value
flt_both// Filter both
};
extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame to use
extern int NlmPeriod = 25; // Non lag ma period
extern enPrices NlmPrice = pr_close; // Price to use
extern double Filter =0; // Filter to use (<=0 no filter)
extern int FilterPeriod =0; // Filter period (<=0 use Non lag ma period)
extern enFilterWhat FilterOn = flt_prc; // Apply filter to:
extern int Shift = 0; // Shift
extern int HistoWidth = 3; // Histogram bars width
extern color UpHistoColor = clrLimeGreen; // Up Histogram color
extern color DnHistoColor = clrRed; // Down histogram color
extern bool alertsOn = true; // Turn alerts on?
extern bool alertsOnCurrent = false; // Alerts on current (still opened) bar?
extern bool alertsMessage = true; // Alerts should display a message?
extern bool alertsSound = false; // Alerts should play a sound?
extern bool alertsEmail = false; // Alerts should send an email?
extern bool alertsNotify = false; // Alerts should send notification?
extern bool arrowsVisible = false; // Arrows visible?
extern bool arrowsOnNewest = false; // Arrows drawn on newst bar of higher time frame bar?
extern string arrowsIdentifier= "nlm Arrows1"; // Unique ID for arrows
extern double arrowsUpperGap = 1.0; // Upper arrow gap
extern double arrowsLowerGap = 1.0; // Lower arrow gap
extern color arrowsUpColor = clrLimeGreen; // Up arrow color
extern color arrowsDnColor = clrOrange; // Down arrow color
extern int arrowsUpCode = 241; // Up arrow code
extern int arrowsDnCode = 242; // Down arrow code
extern int arrowsSize = 2; // Arrows size
//
//
//
//
//
double nlmDa[];
double nlmDb[];
double trend[];
double nlm[];
string indicatorFileName;
bool returnBars;
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int init()
{
IndicatorBuffers(4);
SetIndexBuffer(0,nlmDa);SetIndexStyle(0, DRAW_HISTOGRAM,EMPTY,HistoWidth,UpHistoColor);
SetIndexBuffer(1,nlmDb);SetIndexStyle(1, DRAW_HISTOGRAM,EMPTY,HistoWidth,DnHistoColor);
SetIndexBuffer(2,nlm);
SetIndexBuffer(3,trend);
//
//
//
//
//
indicatorFileName = WindowExpertName();
returnBars = TimeFrame==-99;
TimeFrame = fmax(TimeFrame,_Period);
for (int i=0; i<7; i++) SetIndexShift(i,Shift*TimeFrame/Period());
//
//
//
//
//
return(0);
}
int deinit()
{
string lookFor = arrowsIdentifier+":";
int lookForLength = StringLen(lookFor);
for (int i=ObjectsTotal()-1; i>=0; i--)
{
string objectName = ObjectName(i);
if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName);
}
return(0);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int start()
{
int i,limit,counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = fmin(Bars-counted_bars,Bars-1);
if (returnBars) { nlmDa = limit+1; return(0); }
//
//
//
//
//
if (TimeFrame == Period())
{
for(i=limit; i>=0; i--)
{
int tperiod = FilterPeriod; if (tperiod<=0)tperiod=(int)NlmPeriod;
double pfilter = Filter; if (FilterOn==flt_val) pfilter=0;
double vfilter = Filter; if (FilterOn==flt_prc) vfilter=0;
double price = iFilter(getPrice(NlmPrice,Open,Close,High,Low,i),pfilter,tperiod,i,0);
nlm = iFilter(iNoLagMa(price,NlmPeriod,i),vfilter,tperiod,i,1);
nlmDa = EMPTY_VALUE;
nlmDb = EMPTY_VALUE;
trend = (i<Bars-1) ? (nlm>nlm) ? 1 : (nlm<nlm) ? -1 : trend : 0;
if (trend == 1) nlmDa = 1;
if (trend ==-1) nlmDb = 1;
//
//
//
//
//
if (arrowsVisible)
{
string lookFor = arrowsIdentifier+":"+(string)Time; ObjectDelete(lookFor);
if (i<(Bars-1) && trend != trend)
{
if (trend == 1) drawArrow(i,arrowsUpColor,arrowsUpCode,false);
if (trend ==-1) drawArrow(i,arrowsDnColor,arrowsDnCode, true);
}
}
}
manageAlerts();
return(0);
}
//
//
//
//
//
limit = (int)fmax(limit,fmin(Bars-1,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period()));
for (i=limit; i>=0; i--)
{
int y = iBarShift(NULL,TimeFrame,Time);
nlmDa = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,NlmPeriod,NlmPrice,Filter,FilterPeriod,FilterOn,0,HistoWidth,UpHistoColor,DnHistoColor,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,alertsNotify,arrowsVisible,arrowsOnNewest,arrowsIdentifier,arrowsUpperGap,arrowsLowerGap,arrowsUpColor,arrowsDnColor,arrowsUpCode,arrowsDnCode,arrowsSize,0,y);
nlmDb = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,NlmPeriod,NlmPrice,Filter,FilterPeriod,FilterOn,0,HistoWidth,UpHistoColor,DnHistoColor,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,alertsNotify,arrowsVisible,arrowsOnNewest,arrowsIdentifier,arrowsUpperGap,arrowsLowerGap,arrowsUpColor,arrowsDnColor,arrowsUpCode,arrowsDnCode,arrowsSize,1,y);
}
return(0);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
#define _length0
#define _len 1
#define _weight2
#define numOfSeparateCalculations 3
doublenlm_values;
doublenlm_prices[ ];
doublenlm_alphas[ ];
double iNoLagMa(double price, int length, int r, int instanceNo=0)
{
r = Bars-r-1;
if (ArrayRange(nlm_prices,0) != Bars(Symbol(),0)) ArrayResize(nlm_prices,Bars(Symbol(),0));
nlm_prices=price;
if (length<3 || r<3) return(nlm_prices);
//
//
//
//
//
if (nlm_values != length)
{
double Cycle = 4.0;
double Coeff = 3.0*M_PI;
int Phase = length-1;
nlm_values = length;
nlm_values = length*4 + Phase;
nlm_values = 0;
if (ArrayRange(nlm_alphas,0) < nlm_values) ArrayResize(nlm_alphas,(int)nlm_values);
for (int k=0; k<nlm_values; k++)
{
double t;
if (k<=Phase-1)
t = 1.0 * k/(Phase-1);
else t = 1.0 + (k-Phase+1)*(2.0*Cycle-1.0)/(Cycle*length-1.0);
double beta = MathCos(M_PI*t);
double g = 1.0/(Coeff*t+1); if (t <= 0.5 ) g = 1;
nlm_alphas = g * beta;
nlm_values += nlm_alphas;
}
}
//
//
//
//
//
if (nlm_values>0)
{
double sum = 0;
for (int k=0; k < nlm_values && (r-k)>=0; k++) sum += nlm_alphas*nlm_prices;
return( sum / nlm_values);
}
else return(0);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
#define filterInstances 2
double workFil[];
#define _fchange 0
#define _fachang 1
#define _fprice2
double iFilter(double tprice, double filter, int period, int i, int instanceNo=0)
{
if (filter<=0 || period<=0) return(tprice);
if (ArrayRange(workFil,0)!= Bars) ArrayResize(workFil,Bars); i = Bars-i-1; instanceNo*=3;
//
//
//
//
//
workFil= tprice; if (i<1) return(tprice);
workFil = fabs(workFil-workFil);
workFil = workFil;
for (int k=1; k<period && (i-k)>=0; k++) workFil += workFil;
workFil /= period;
double stddev = 0; for (int k=0;k<period && (i-k)>=0; k++) stddev += MathPow(workFil-workFil,2);
stddev = MathSqrt(stddev/(double)period);
double filtev = filter * stddev;
if( MathAbs(workFil-workFil) < filtev ) workFil=workFil;
return(workFil);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
//
#define priceInstances 1
double workHa[];
double getPrice(int tprice, const double& open[], const double& close[], const double& high[], const double& low[], int i, int instanceNo=0)
{
if (tprice>=pr_haclose)
{
if (ArrayRange(workHa,0)!= Bars) ArrayResize(workHa,Bars); instanceNo*=4;
int r = Bars-i-1;
//
//
//
//
//
double haOpen;
if (r>0)
haOpen= (workHa + workHa)/2.0;
else haOpen= (open+close)/2;
double haClose = (open + high + low + close) / 4.0;
double haHigh= fmax(high,fmax(haOpen,haClose));
double haLow = fmin(low ,fmin(haOpen,haClose));
if(haOpen<haClose) { workHa = haLow;workHa = haHigh; }
else { workHa = haHigh; workHa = haLow;}
workHa = haOpen;
workHa = haClose;
//
//
//
//
//
switch (tprice)
{
case pr_haclose: return(haClose);
case pr_haopen: return(haOpen);
case pr_hahigh: return(haHigh);
case pr_halow: return(haLow);
case pr_hamedian: return((haHigh+haLow)/2.0);
case pr_hamedianb: return((haOpen+haClose)/2.0);
case pr_hatypical: return((haHigh+haLow+haClose)/3.0);
case pr_haweighted:return((haHigh+haLow+haClose+haClose)/4.0);
case pr_haaverage: return((haHigh+haLow+haClose+haOpen)/4.0);
case pr_hatbiased:
if (haClose>haOpen)
return((haHigh+haClose)/2.0);
elsereturn((haLow+haClose)/2.0);
case pr_hatbiased2:
if (haClose>haOpen)return(haHigh);
if (haClose<haOpen)return(haLow);
return(haClose);
}
}
//
//
//
//
//
switch (tprice)
{
case pr_close: return(close);
case pr_open: return(open);
case pr_high: return(high);
case pr_low: return(low);
case pr_median: return((high+low)/2.0);
case pr_medianb: return((open+close)/2.0);
case pr_typical: return((high+low+close)/3.0);
case pr_weighted:return((high+low+close+close)/4.0);
case pr_average: return((high+low+close+open)/4.0);
case pr_tbiased:
if (close>open)
return((high+close)/2.0);
elsereturn((low+close)/2.0);
case pr_tbiased2:
if (close>open) return(high);
if (close<open) return(low);
return(close);
}
return(0);
}
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//
string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};
string timeFrameToString(int tf)
{
for (int i=ArraySize(iTfTable)-1; i>=0; i--)
if (tf==iTfTable) return(sTfTable);
return("");
}
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//
void manageAlerts()
{
if (alertsOn)
{
int whichBar = 1; if (alertsOnCurrent) whichBar = 0;
if (trend != trend)
{
if (trend ==1) doAlert(whichBar,"up");
if (trend == -1) doAlert(whichBar,"down");
}
}
}
//
//
//
//
//
void doAlert(int forBar, string doWhat)
{
static string previousAlert="nothing";
static datetime previousTime;
string message;
if (previousAlert != doWhat || previousTime != Time) {
previousAlert= doWhat;
previousTime = Time;
//
//
//
//
//
message =StringConcatenate(Symbol()," ",timeFrameToString(_Period)," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," NonLag MA slope changed to ",doWhat);
if (alertsMessage) Alert(message);
if (alertsSound) PlaySound("alert2.wav");
if (alertsEmail) SendMail(StringConcatenate(Symbol(),"NonLag MA"),message);
if (alertsNotify)SendNotification(message);
}
}
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//
void drawArrow(int i,color theColor,int theCode,bool up)
{
string name = arrowsIdentifier+":"+(string)Time;
double gap= iATR(NULL,0,20,i);
//
//
//
//
//
datetime time = Time; if (arrowsOnNewest) time += _Period*60-1;
ObjectCreate(name,OBJ_ARROW,0,time,0);
ObjectSet(name,OBJPROP_ARROWCODE,theCode);
ObjectSet(name,OBJPROP_WIDTH,arrowsSize);
ObjectSet(name,OBJPROP_COLOR,theColor);
if (up)
ObjectSet(name,OBJPROP_PRICE1,High + arrowsUpperGap * gap);
elseObjectSet(name,OBJPROP_PRICE1,Low- arrowsLowerGap * gap);
}
1111111111111111 22222222222222222222222 谢谢分享谢谢分享谢谢分享谢谢分享谢谢分享谢谢分享谢谢分享谢谢分享谢谢分享 吃饭都是高峰的高峰的海景房卡和见了客户来客家罗湖绿林豪客 享谢谢分享谢谢分享谢谢 前排支持下 谢谢楼主分享 顶下
页:
[1]