BbMacd_nrp_mtf+alerts 2.mq4

bbmacd_nrp_mtfalerts-2-mq4

BbMacd_nrp_mtf+alerts 2.mq4 source code
free download page

//+——————————————————————+
//| BBMacd.mq4 |
//| BBMacd by Mladen |
//| mrtools added arrows and alerts |
//+——————————————————————+
#property copyright “www.forex-tsd.com”
#property link “www.forex-tsd.com”

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 clrSandyBrown
#property indicator_color2 clrDeepSkyBlue
#property indicator_color3 clrDeepSkyBlue
#property indicator_color4 clrSandyBrown
#property indicator_color5 clrSandyBrown
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_level1 0

//
//
//
//
//

extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT;
extern int FastLen = 12;
extern int FastMaMode = MODE_LWMA;
extern int FastMaPrice = PRICE_CLOSE;
extern int SlowLen = 26;
extern int SlowMaMode = MODE_LWMA;
extern int SlowMaPrice = PRICE_CLOSE;
extern int Length = 10;
extern double StDv = 1.0;
extern bool drawDots = true;

extern bool alertsOn = true;
extern bool alertsOnSlope = true;
extern bool alertsOnBandBreakout = true;
extern bool alertsOnCurrent = true;
extern bool alertsMessage = true;
extern bool alertsSound = false;
extern bool alertsNotify = false;
extern bool alertsEmail = false;

extern bool arrowsVisible = true;
extern string arrowsIdentifier = “bbmacd Arrows1″;
extern double arrowsDisplacement = 1.0;

extern bool arrowsOnSlope = false;
extern color arrowsOnSlopeUpColor = clrDeepSkyBlue;
extern color arrowsOnSlopeDnColor = clrSandyBrown;
extern int arrowsOnSlopeUpCode = 241;
extern int arrowsOnSlopeDnCode = 242;
extern int arrowsOnSlopeUpSize = 1;
extern int arrowsOnSlopeDnSize = 1;

extern bool arrowsOnBandBreakout = true;
extern color arrowsOnBandBreakoutUpColor = clrDeepSkyBlue;
extern color arrowsOnBandBreakoutDnColor = clrSandyBrown;
extern int arrowsOnBandBreakoutUpCode = 119;
extern int arrowsOnBandBreakoutDnCode = 119;
extern int arrowsOnBandBreakoutUpSize = 3;
extern int arrowsOnBandBreakoutDnSize = 3;

//
//
//
//
//

double buffer1[];
double buffer2[];
double bbMacd[];
double buffer4[];
double buffer5[];
double buffer6[];
double slope[];
double trend[];

//
//
//
//
//

string indicatorFileName;
bool returnBars;

//+——————————————————————+
//| |
//+——————————————————————+
//
//

int init()
{
IndicatorBuffers(8);
SetIndexBuffer(0,buffer1);
SetIndexBuffer(1,buffer2);
SetIndexBuffer(2,bbMacd);
SetIndexBuffer(3,buffer4);
SetIndexBuffer(4,buffer5);
SetIndexBuffer(5,buffer6);
SetIndexBuffer(6,slope);
SetIndexBuffer(7,trend);

if (drawDots)
{
SetIndexStyle(2, DRAW_ARROW,0); SetIndexArrow(2, 159);
SetIndexStyle(3, DRAW_ARROW,0); SetIndexArrow(3, 159);
SetIndexStyle(4, DRAW_NONE);
}
else
{
SetIndexStyle(2, DRAW_LINE);
SetIndexStyle(3, DRAW_LINE);
SetIndexStyle(4, DRAW_LINE);
}

//
//
//
//
//

indicatorFileName = WindowExpertName();
returnBars = (TimeFrame==-99);
TimeFrame = MathMax(TimeFrame,_Period);

//
//
//
//
//

IndicatorDigits(5);
IndicatorShortName(timeFrameToString(TimeFrame)+” BB Macd (“+FastLen+ “,” +SlowLen+ “,” +Length+”)”);
SetIndexLabel(0, “Upperband”);
SetIndexLabel(1, “Lowerband”);
SetIndexLabel(2, “BB Macd”);
SetIndexLabel(3, NULL);
SetIndexLabel(4, NULL);
return(0);
}

//+——————————————————————+
//| |
//+——————————————————————+
//
//

int deinit()
{
if (arrowsVisible) deleteArrows();

return(0);
}

//+——————————————————————+
//| |
//+——————————————————————+
//
//

int start()
{
int limit,i,counted_bars = IndicatorCounted();

if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars–;
limit = MathMin(Bars – counted_bars,Bars-1);
if (returnBars) { buffer1[0] = limit+1; return(0); }

//
//
//
//
//

if (TimeFrame == Period())
{
if (!drawDots) if (slope[limit]==-1) CleanPoint(limit,buffer4,buffer5);
double alpha = 2.0 / (Length + 1.0);
for(i = limit; i >= 0 ; i–)
{
bbMacd[i] = iMA(NULL,0,FastLen,0,FastMaMode,FastMaPrice,i) – iMA(NULL,0,SlowLen,0,SlowMaMode,SlowMaPrice,i);
buffer6[i] = buffer6[i+1] + alpha*(bbMacd[i] – buffer6[i+1]);
double sDev = iDeviation(bbMacd, buffer6[i], Length, i);
buffer1[i] = buffer6[i] + (StDv * sDev);
buffer2[i] = buffer6[i] – (StDv * sDev);
buffer4[i] = EMPTY_VALUE;
buffer5[i] = EMPTY_VALUE;

//
//
//
//
//

slope[i] = slope[i+1];
trend[i] = trend[i+1];
if (bbMacd[i] > bbMacd[i+1]) slope[i] = 1;
if (bbMacd[i] < bbMacd[i+1]) slope[i] = -1; if (bbMacd[i] > buffer1[i]) trend[i] = 1;
if (bbMacd[i] < buffer2[i]) trend[i] = -1; if (slope[i]==-1) if (drawDots) buffer4[i] = bbMacd[i]; else PlotPoint(i,buffer4,buffer5,bbMacd); manageArrow(i); } manageAlerts(); return(0); } // // // // // limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period())); if (!drawDots) if (slope[limit]==-1) CleanPoint(limit,buffer4,buffer5); for(i=limit; i>=0; i–)
{
int y = iBarShift(NULL,TimeFrame,Time[i]);
buffer1[i]= iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,FastLen,FastMaMode,FastMaPrice,SlowLen,SlowMaMode,SlowMaPrice,Length,StDv,false,alertsOn,alertsOnSlope,alertsOnBandBreakout,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,0,y);
buffer2[i]= iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,FastLen,FastMaMode,FastMaPrice,SlowLen,SlowMaMode,SlowMaPrice,Length,StDv,false,alertsOn,alertsOnSlope,alertsOnBandBreakout,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,1,y);
bbMacd[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,FastLen,FastMaMode,FastMaPrice,SlowLen,SlowMaMode,SlowMaPrice,Length,StDv,false,alertsOn,alertsOnSlope,alertsOnBandBreakout,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,2,y);
buffer4[i]= EMPTY_VALUE;
buffer5[i]= EMPTY_VALUE;
slope[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,FastLen,FastMaMode,FastMaPrice,SlowLen,SlowMaMode,SlowMaPrice,Length,StDv,false,alertsOn,alertsOnSlope,alertsOnBandBreakout,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,6,y);
trend[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,FastLen,FastMaMode,FastMaPrice,SlowLen,SlowMaMode,SlowMaPrice,Length,StDv,false,alertsOn,alertsOnSlope,alertsOnBandBreakout,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,7,y);

if (drawDots && slope[i]==-1) buffer4[i] = bbMacd[i];
manageArrow(i);
}
if (!drawDots) for (i=limit;i>=0;i–) if (slope[i]==-1) PlotPoint(i,buffer4,buffer5,bbMacd);
return(0);
}

//+——————————————————————+
//| |
//+——————————————————————+
//
//
//
//
//

double iDeviation(double& array[],double dMA, int period,int shift)
{
double dSum = 0.00;
int i;

for(i=0; i=0; i–)
if (tf==iTfTable[i]) return(sTfTable[i]);
return(“”);
}

//+——————————————————————-
//|
//+——————————————————————-
//
//
//
//
//

void manageAlerts()
{
if (alertsOn)
{
if (alertsOnCurrent)
int whichBar = 0;
else whichBar = 1;

//
//
//
//
//

static datetime time1 = 0;
static string mess1 = “”;
if (alertsOnSlope && slope[whichBar] != slope[whichBar+1])
{
if (slope[whichBar] == 1) doAlert(time1,mess1,whichBar,”sloping up”);
if (slope[whichBar] == -1) doAlert(time1,mess1,whichBar,”sloping down”);
}

static datetime time2 = 0;
static string mess2 = “”;
if (alertsOnBandBreakout && trend[whichBar]!= trend[whichBar+1])
{
if (trend[whichBar] == 1) doAlert(time2,mess2,whichBar,”breaking upper band”);
if (trend[whichBar] == -1) doAlert(time2,mess2,whichBar,”breaking lower band”);
}
}
}

//
//
//
//
//

void doAlert(datetime& previousTime, string& previousAlert, int forBar, string doWhat)
{
string message;

if (previousAlert != doWhat || previousTime != Time[forBar]) {
previousAlert = doWhat;
previousTime = Time[forBar];

//
//
//
//
//

message = StringConcatenate(Symbol(),” “,timeFrameToString(_Period),” at “,TimeToStr(TimeLocal(),TIME_SECONDS),” BBMacd “,doWhat);
if (alertsMessage) Alert(message);
if (alertsNotify) SendNotification(StringConcatenate(Symbol(), Period() ,” BBMacd ” +” “+message));
if (alertsEmail) SendMail(StringConcatenate(Symbol(),” BBMacd “),message);
if (alertsSound) PlaySound(“alert2.wav”);
}
}

//+——————————————————————+
//| |
//+——————————————————————+
//
//
//
//
//

void manageArrow(int i)
{
if (arrowsVisible)
{
deleteArrow(Time[i]);
if (arrowsOnSlope && slope[i] != slope[i+1])
{
if (slope[i] == 1) drawArrow(i,arrowsOnSlopeUpColor,arrowsOnSlopeUpCode,arrowsOnSlopeUpSize,false);
if (slope[i] ==-1) drawArrow(i,arrowsOnSlopeDnColor,arrowsOnSlopeDnCode,arrowsOnSlopeDnSize,true);
}

if (arrowsOnBandBreakout && trend[i]!= trend[i+1])
{
if (trend[i] == 1) drawArrow(i,arrowsOnBandBreakoutUpColor,arrowsOnBandBreakoutUpCode,arrowsOnBandBreakoutUpSize,false);
if (trend[i] ==-1) drawArrow(i,arrowsOnBandBreakoutDnColor,arrowsOnBandBreakoutDnCode,arrowsOnBandBreakoutDnSize,true);
}
}
}

//
//
//
//
//

void drawArrow(int i,color theColor,int theCode,int theSize,bool up)
{
string name = arrowsIdentifier+”:”+Time[i];
double gap = iATR(NULL,0,20,i);

//
//
//
//
//

ObjectCreate(name,OBJ_ARROW,0,Time[i],0);
ObjectSet(name,OBJPROP_ARROWCODE,theCode);
ObjectSet(name,OBJPROP_COLOR,theColor);
ObjectSet(name,OBJPROP_WIDTH,theSize );
if (up)
ObjectSet(name,OBJPROP_PRICE1,High[i] + arrowsDisplacement * gap);
else ObjectSet(name,OBJPROP_PRICE1,Low[i] – arrowsDisplacement * gap);
}

//
//
//
//
//

void deleteArrows()
{
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);
}
}

//
//
//
//
//

void deleteArrow(datetime time)
{
string lookFor = arrowsIdentifier+”:”+time; ObjectDelete(lookFor);
}

Leave a Reply

Your email address will not be published.