stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

SnakeForce - simple TMA with alert?
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=119
Page 1 of 1
Author:  dynel14 [ Fri Dec 02, 2011 12:20 pm ]
Post subject:  SnakeForce - simple TMA with alert?

HI coders,

does anyone have time to put an alert in this indicator?
I have no clue about coding :oops: :?:

Thank you so much!
dynel14
Author:  gaheitman [ Fri Dec 02, 2011 12:44 pm ]
Post subject:  Re: SnakeForce - simple TMA with alert?

dynel14 wrote:HI coders,

does anyone have time to put an alert in this indicator?
I have no clue about coding :oops: :?:

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?

Code: Select all

   if(Pos<6) Pos=6;
   while(Pos>=0)
   {
      Mart[Pos]=iTma(SnakePrice(Pos),11,Pos);
      Drawing(Pos);
      Pos--;
   }
   return;
George
Author:  dynel14 [ Fri Dec 02, 2011 12:50 pm ]
Post subject:  Re: SnakeForce - simple TMA with alert?

gaheitman wrote:
dynel14 wrote:HI coders,

does anyone have time to put an alert in this indicator?
I have no clue about coding :oops: :?:

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?

Code: Select all

   if(Pos<6) Pos=6;
   while(Pos>=0)
   {
      Mart[Pos]=iTma(SnakePrice(Pos),11,Pos);
      Drawing(Pos);
      Pos--;
   }
   return;
George
Hi George,

I have not seen the indicator was repainting!? I need an alert for color change.

regards
dynel14
Author:  gaheitman [ Sat Dec 03, 2011 9:21 am ]
Post subject:  Re: SnakeForce - simple TMA with alert?

dynel14 wrote:
Hi George,

I have not seen the indicator was repainting!? I need an alert for color change.

regards
dynel14
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.

First of all, to be a good alerting procedure you have to:
  • Send alerts to screen or email or both
    Keep track of when the last alert was sent so that it doesn't send them with every tick
    Allow for sending them every tick if you really want to :)
    Keep track of individual alerts so that you can have one alert every tick, one only every 5 minutes, another only once a day, etc.
I think this addresses the above.

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) 
Usage examples:

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);
Hopefully you get the idea. For this indicator, I think you want to do something like this... At the end of the start() procedure call (right before the return statement):

uAlert(CrossAlert,0,uALERT_SCREEN,Symbol()+" color change",(ForceUp[0]==0 && ForceUp[1]!=0) || (ForceUp[0] != 1 && ForceUp[1] == 0));

In retrospect, this seems a lot like overkill. You could also just do this:

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");
   }      

It goes in the same spot. :D

George
Author:  dynel14 [ Sat Dec 03, 2011 10:59 pm ]
Post subject:  Re: SnakeForce - simple TMA with alert?

ImageImage

:D

Thank you! Will try to work with it.

dynel14
All times are UTC Page 1 of 1