how can i make alert line only one time?

 

Hello!

good afternoon.

i want to modify attached source to suit what i want style.

this is trend line alert and if price line cross then alert fire but it every bar fire alert but

i want to make it only one times alert not per bar or not tick per since i enable trend line alert indicator but no luck.

i was used

static datetime Time0;

if(Time0 == Time[0] ) return;

but it continue alert per bar.

any help much appreciate

//------------------------------------------------------------------
//
//------------------------------------------------------------------
#property indicator_chart_window

extern string LineName = "Line1";
extern color LineColor = Red;
extern int LineStyle = STYLE_SOLID;
extern bool alertsOn = true;
extern bool alertsOnCurrent = false;
extern bool alertsMessage = true;
extern bool alertsSound = false;
extern bool alertsEmail = false;

int AlertCount ;
Print("top");
//
//------------------------------------------------------------------
datetime gOldTime=0;
bool NewBar()
{
bool new = Time[0] != gOldTime;
gOldTime = Time[0];
return (new);
}

int init() {
Print("Alert count 1 ");

static datetime Time0 ;
return(0);
}
int deinit() {
ObjectDelete("Label_Obj_MACD");
return(0); }



int start()
{


Print("alertcount start around:" + AlertCount);
static datetime Time0 ;
int Sit;
double MACD_M_0,MACD_M_1, // Main line, 0 and 1st bar
MACD_S_0,MACD_S_1; // Signal line, 0 and 1st bar
string Text[4]; // Declaring a string array
color Color[4]; // Declaring an array of colors

Text[0]= "Active Order Close"; // Text for different situations
Text[1]= "Disabled Order Close";
Text[2]= "Holding of Buy";
Text[3]= "Holding of Sell";

Color[0]= DeepSkyBlue; // Object color ..
Color[1]= LightPink; // .. for different situations
Color[2]= Yellow;
Color[3]= Yellow;
//--------------------------------------------------------------- 2 --
ObjectCreate("Label_Obj_MACD", OBJ_LABEL, 0, 0, 0);// Creating obj.
ObjectSet("Label_Obj_MACD", OBJPROP_CORNER, 1); // Reference corner
ObjectSet("Label_Obj_MACD", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Label_Obj_MACD", OBJPROP_YDISTANCE, 15);// Y coordinate
//--------------------------------------------------------------- 3 --
MACD_M_0 =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); // 0 bar
MACD_S_0 =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);// 0 bar
MACD_M_1 =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1); // 1 bar
MACD_S_1 =iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);// 1 bar
//--------------------------------------------------------------- 4 --


if (ObjectFind(LineName)==-1)
{
ObjectCreate(LineName, OBJ_TREND, 0, Time[25], Close[25], Time[0], Close[0]);
ObjectSet(LineName,OBJPROP_YDISTANCE, 44);
ObjectSet(LineName,OBJPROP_XDISTANCE, 10);
ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
ObjectSet(LineName, OBJPROP_COLOR, LineColor);
Sit= 0;
ObjectSetText("Label_Obj_MACD",Text[Sit],20,"Arial",Color[Sit]);


}



if (alertsOn)
{
int testbar = 1; if (alertsOnCurrent) testbar = 0;
double valc = ObjectGetValueByShift(LineName,testbar);
double valp = ObjectGetValueByShift(LineName,testbar+1);

//

//
if(AlertCount < 3) {
if(NewBar() ) {
if ( Close[1] > valc )
{
Print("close[0] :" + Close[0]);
Print("valc :" + valc);
Print("valp :" + valp);

doAlert(0," trend Up line crossed 1");
Sit= 1;
ObjectSetText("Label_Obj_MACD",Text[Sit],20,"Arial",Color[Sit]);
SendNotification("Trend UP Line Crossed 1!");
Sleep(5000);
SendNotification("Trend Line Crossed! 1");
Time0 = Time[0]; // no more alert
}
}


if(NewBar()) {
if( Close[1] < valc )
{
doAlert(0," trend Down line crossed 2");
Sit= 1;
ObjectSetText("Label_Obj_MACD",Text[Sit],20,"Arial",Color[Sit]);
SendNotification("Trend Down Line Crossed! 2");
Sleep(5000);
SendNotification("Trend Line Crossed! 2");
Time0 = Time[0]; // no more alert

}
}
AlertCount++;
Print("alertcount:" + AlertCount);
}


}
return(0);
}


//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

void doAlert(int forBar, string doWhat)
{
static string previousAlert="nothing";
static datetime previousTime;
string message;

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

//
//
//
//
//

message = Symbol()+" at "+TimeToStr(TimeLocal(),TIME_SECONDS)+" "+LineName+doWhat;

if (alertsMessage) Alert(message);
if (alertsEmail) SendMail(Symbol()+"trendLine alerts",message);
if (alertsSound) PlaySound("alert2.wav");

}

}

 

a moderator would better be able to solve up the issues well here, contact him now to get a reliable solution now on

Reason: