Hi all, just wondering if anyone knows what I need to add for code so I only get one SMS or Alert sent for each signal generated. Right now it's repeating multiple times. I know I have it inside a loop but not sure how else to write it. Not the greatest coder that's for sure. Anyone with ideas or input would be appreciated. Here the code below:
QuoteDisliked//+------------------------------------------------------------------+
//| Strength Weakness Alerts.mq4 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 Red
extern bool Show_Alert = true;
extern bool Display_S = true;
extern bool Display_W = true;
extern int SignalSize = 0.5;
extern double Offset = 4;
extern int NumberOfBars = 20;
int ExtCountedBars=0;
double MA[];
double Spread[];
double Range;
double SprMovAvg = 4;
string spreadtype, spreadtype1, volumetype, volumetype1 ,updnbar, updnbar1, closebar, closebar1, VSAType, newVSA;
int MAPeriod = 4;
double Strength[],Weakness[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
Offset = Offset*Point;
IndicatorShortName("Strength Weakness Alerts");
SetIndexBuffer(0,Strength);
SetIndexStyle(0,DRAW_ARROW,0,SignalSize);
SetIndexArrow(0, 120);
SetIndexLabel(0,"Strength");
SetIndexBuffer(1,Weakness);
SetIndexStyle(1,DRAW_ARROW,0,SignalSize);
SetIndexArrow(1, 120);
SetIndexLabel(1,"Weakness");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//--------Calculation------------------------------------------+
int counted_bars=IndicatorCounted();
int counter, setalert;
static datetime prevtime = 0;
int shift;
string pattern, period;
int setPattern = 0;
int alert = 0;
if(prevtime == Time[0]) {
return(0);
}
prevtime = Time[0];
switch (Period()) {
case 1:
period = "M1";
break;
case 5:
period = "M5";
break;
case 15:
period = "M15";
break;
case 30:
period = "M30";
break;
case 60:
period = "H1";
break;
case 240:
period = "H4";
break;
case 1440:
period = "D1";
break;
case 10080:
period = "W1";
break;
case 43200:
period = "MN";
break;
}
for (shift = 0; shift < Bars; shift++) {
if(Close[shift+1]>Close[shift+2])
{
updnbar="UP BAR";
}
if(Close[shift+1]<Close[shift+2])
{
updnbar="DOWN BAR";
}
//--------
if(Close[shift+1]<=(((High[shift+1]-Low[shift+1])*0.30)+Low[shift+1]))
{
closebar="DOWN CLOSE";
}
else if(Close[shift+1]>=(High[shift+1]-((High[shift+1]-Low[shift+1])*0.30)))
{
closebar="UP CLOSE";
}
else
{
closebar="MID CLOSE";
}
//-------------Copy------------------------------------------+
if(Close[shift+2]>Close[shift+3])
{
updnbar1="UP BAR";
}
if(Close[shift+2]<Close[shift+3])
{
updnbar1="DOWN BAR";
}
//--------
if(Close[shift+2]<=(((High[shift+2]-Low[shift+2])*0.30)+Low[shift+2]))
{
closebar1="DOWN CLOSE";
}
else if(Close[shift+2]>=(High[shift+2]-((High[shift+2]-Low[shift+2])*0.30)))
{
closebar1="UP CLOSE";
}
else
{
closebar1="MID CLOSE";
}
setalert = 0;
counter=shift;
double main = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,shift+1);
double signal = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,shift+1);
double upper = iBands(NULL,0,20,2,0,PRICE_HIGH,MODE_UPPER,shift+1);
double lower = iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,shift+1);
// Check for Strength
if (updnbar1=="DOWN BAR" && closebar1=="DOWN CLOSE" || closebar1=="MID CLOSE" && (updnbar=="UP BAR" && closebar=="UP CLOSE")
&& Low[shift+1]< Open[shift] && Open[shift+1]<Close[shift]
&& main > signal && (main >=10 /*&& main <90*/)) {
if (Display_S == true)
{
Strength[shift+1]=Low[shift+1] - Offset;
}
if (setalert == 0 && Show_Alert == true) {
Alert("Strength");
setalert = 1;
}
}
else
// Check for Weakness
if (updnbar1=="UP BAR" && closebar1=="UP CLOSE" || closebar1=="MID CLOSE" && (updnbar=="DOWN BAR" && closebar=="DOWN CLOSE")
&& High[shift+1]>Open[shift] && Open[shift+1]>Close[shift]
&& main < signal && (main <90 /*&& main >10*/)) {
if (Display_W == true) {
{
Weakness[shift+1]=High[shift+1] + Offset;
}
if (setalert == 0 && Show_Alert == true) {
Alert("Weakness");
setalert = 1;
}
}
}
} // End of for loop
//----
return(0);
}
//+------------------------------------------------------------------+