does anyone have time to put an alert in this indicator?
I have no clue about coding
Thank you so much!
dynel14
I can probably talk you through it. What did you want to trigger the alert? Also, it looks like it may repaint the last 6 bars based on this snippet of code. If so would you want an alert that triggers on bars in the past?dynel14 wrote:HI coders,
does anyone have time to put an alert in this indicator?
I have no clue about coding![]()
:
Thank you so much!
dynel14
Code: Select all
if(Pos<6) Pos=6;
while(Pos>=0)
{
Mart[Pos]=iTma(SnakePrice(Pos),11,Pos);
Drawing(Pos);
Pos--;
}
return;
Hi George,gaheitman wrote:I can probably talk you through it. What did you want to trigger the alert? Also, it looks like it may repaint the last 6 bars based on this snippet of code. If so would you want an alert that triggers on bars in the past?dynel14 wrote:HI coders,
does anyone have time to put an alert in this indicator?
I have no clue about coding![]()
:
Thank you so much!
dynel14
GeorgeCode: Select all
if(Pos<6) Pos=6; while(Pos>=0) { Mart[Pos]=iTma(SnakePrice(Pos),11,Pos); Drawing(Pos); Pos--; } return;
Instead of doing a one-off to modify this indicator I decided to take a shot at writing a reusable alerting procedure. This is what I came up with.dynel14 wrote:
Hi George,
I have not seen the indicator was repainting!? I need an alert for color change.
regards
dynel14
Code: Select all
//+-------------------------------------------------------------------------------------+
//uAlert(int AlertIdx, int Frequency, bool AlertDestination,
// string Msg, bool Condition1, bool Condition2=true,bool Condition3=true)
//+-------------------------------------------------------------------------------------+
//int AlertIdx -- use a unique index for each alert you want.
// I recommend you use #define statements
//int Frequency -- how often do you want to display/evaluate the alert. this way it
// doesn't ping you on every tick. Use standard PERIOD defines in
// Empty4 or uAlertEveryTick for every tick
//bool AlertDestination -- one of uALERT_SCREEN, uALERT_EMAIL or the combination
// uALERT_SCREEN|uALERT_EMAIL for both
//string Msg -- the message you would like to display
//bool Condition1 -- the condition you want evaluated. should result in a true or false
//bool Condition2=true -- optional additional conditions. not really necessary but
//bool Condition3=true could help make code readable. all conditions must be true
//+-------------------------------------------------------------------------------------+
//following defines are required
#define uAlertEveryTick -1 //evaluate alerts each time the routine is called
#define uALERT_SCREEN 2 //display alerts to screen
#define uALERT_EMAIL 4 //send alerts as emails
#define uALERT_EXTERNAL 8 //future use - run an external program
void uAlert(int AlertIdx, int Frequency, int AlertDestination, string Msg, bool Condition1, bool Condition2=true,bool Condition3=true) {
static int AlertCheck[10]; //assume there will be multiple alerts -- mostly so we save time on resizing
if (IsTesting()) return; //no alerts in testing
if (AlertDestination == 0) return; //hmmm, don't want to alert right now.
if (ArraySize(AlertCheck) < AlertIdx + 1)
ArrayResize(AlertCheck, AlertIdx+10); //try to make sure there is enough to keep adding
//now, do nothing unless it is a new bar or frequency = everytick
int CurrentBarTime = iTime(Symbol(),Frequency,0);
if (CurrentBarTime != AlertCheck[AlertIdx] || Frequency == uAlertEveryTick) {
//update the array to make sure we don't alert again until new bar
AlertCheck[AlertIdx] = CurrentBarTime;
//send a copy to the log
Print(WindowExpertName()," ",Symbol()," ",Msg);
//send to screen if requested
if (AlertDestination & uALERT_SCREEN == uALERT_SCREEN) {
Alert(WindowExpertName()," ",Symbol()," ",Msg);
}//(AlertDestination & uALERT_SCREEN == uALERT_SCREEN)
//send to EMAIL if requested
if (AlertDestination & uALERT_SCREEN == uALERT_SCREEN) {
SendMail("Alert from " + WindowExpertName(),Symbol()+" "+Msg);
}//(AlertDestination & uALERT_SCREEN == uALERT_SCREEN)
}//(CurrentBarTime != AlertCheck[AlertIdx] || Frequency == uAlertEveryTick)
}//uAlert(int AlertIdx, int Frequency, int AlertDestination, string Msg, bool Condition1, bool Condition2=true,bool Condition3=true)
Code: Select all
//use defines to assign meaningful names to the different alerts in your program. make sure the numbers are different!
#define CrossAlert 0
#define NewHourAlert 1
#define OrderPlacedAlert 3
//Alert the user if price is above daily open, but only once an hour
uAlert(CrossAlert,PERIOD_H1,uALERT_SCREEN,"Price is above daily open",Bid > iOpen(Symbol(),PERIOD_D1,0));
//Alert at the start of a new hour, checking every 5 minutes
uAlert(NewHourAlert ,PERIOD_M5,uALERT_SCREEN,"New Hour",TimeHour(Time[0]) !=TimeHour(Time[1]));
//Alert as soon as an order is placed
uAlert(OrderPlacedAlert,uAlertEveryTick,uALERT_SCREEN,"New order placed",OrdersTotal() != SavedOrdersTotal);
Code: Select all
static int alertbars=0;
if (alertbars != iBars(Symbol(),0)) {
alertbars = iBars(Symbol(),0);
if ((ForceUp[0]==0 && ForceUp[1]!=0) || (ForceUp[0] != 0 && ForceUp[1] == 0))
Alert(Symbol()+" color change");
}

