Sendmail problems..

 

Hello again folks,

I have written an indicator which looks for a pinbar after a moving average cross over and have been trying in every spare minute for the last week to reliably get it to send me an email when conditions are satisfied. I have searched and read posts and documentation and the best i can come up with is what i will post below. My drama is that it sends way too many mails. I have currently got it set to a possible solution i read on one of raptorUKs replies to a similar problem...only send emails when looking at the 1st few bars. The way i have programmed it seems to work ok sometimes but not others (still starts sending bulk emails). Any help or push in the right direction would be greatly appreciated. Thanks.

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit, i, s, t, j;
   
   int    counted_bars=IndicatorCounted();
   
   double mainLine,
          prevMainLine,
          signalLine,
          prevSignalLine,
          RSIvalue,
          prevRSIvalue,
          bar1slowMAvalue,
          bar1fastMAvalue,
          slowstochK,
          slowstochD,
          prevslowstochK,
          dailystochK,
          dailystochD,
          fourhrstochK,
          fourhrstochD,
          bar2slowMAvalue, bar2fastMAvalue,
          bar3slowMAvalue, bar3fastMAvalue,
          bar4slowMAvalue, bar4fastMAvalue,
          bar5slowMAvalue, bar5fastMAvalue,
          bar6slowMAvalue, bar6fastMAvalue,
          bar7slowMAvalue, bar7fastMAvalue,
          bar8slowMAvalue, bar8fastMAvalue,
          bar9slowMAvalue, bar9fastMAvalue,
          bar10slowMAvalue, bar10fastMAvalue,
          bar1H, bar1O, bar1C, bar1L, bar2H, bar2C, bar2O, bar2L, bar3H, bar3L, pinrange,
          RSIBuffer[2000], MAofRSIBuffer[2000]; 
          ArraySetAsSeries(RSIBuffer,true);
                   
   bool   buy,
          sell,
          buypin,
          sellpin,
          bar1xup, bar1xdn,
          bar2xup, bar2xdn,
          bar3xup, bar3xdn,
          bar4xup, bar4xdn,
          bar5xup, bar5xdn,
          bar6xup, bar6xdn,
          bar7xup, bar7xdn,
          bar8xup, bar8xdn,
          bar9xup, bar9xdn,
          bar10xup, bar10xdn,
          sellemail,
          buyemail;         
   
   //-- recount last bar  
   
 if(counted_bars>0) counted_bars--;
      
      limit=Bars-counted_bars; 
      
          
   for (s=0; s<=limit; s++)
   
   RSIBuffer[s]=iRSI(0,0,7,PRICE_CLOSE,s);
   
   for (t=0; t<=limit; t++)
   
   MAofRSIBuffer[t]=iMAOnArray(RSIBuffer,0,3,0,MODE_EMA,t);
   
           
   for (i=1; i<=limit; i++)   
   
      {   
      mainLine=iStochastic(0,0,FastK,FastD,3,MODE_EMA,0,MODE_MAIN,i);
      prevMainLine=iStochastic(0,0,FastK,FastD,3,MODE_EMA,0,MODE_MAIN,i+1);
      signalLine=iStochastic(0,0,FastK,FastD,3,MODE_EMA,0,MODE_SIGNAL,i);
      prevSignalLine=iStochastic(0,0,FastK,FastD,3,MODE_EMA,0,MODE_SIGNAL,i+1);
      RSIvalue=iRSI(0,0,RSImain,PRICE_CLOSE,i);
      prevRSIvalue=iRSI(0,0,RSImain,PRICE_CLOSE,i+1);
      bar1slowMAvalue=iMA(0,0,SlowMA,0,MODE_EMA,PRICE_CLOSE,i);
      bar1fastMAvalue=iMA(0,0,FastMA,0,MODE_EMA,PRICE_CLOSE,i);
      slowstochK=iStochastic(0,0,SlowK,SlowD,3,MODE_EMA,0,MODE_MAIN,i);
      slowstochD=iStochastic(0,0,SlowK,SlowD,3,MODE_EMA,0,MODE_SIGNAL,i);
      dailystochK=iStochastic(0,PERIOD_H4,30,3,3,MODE_EMA,0,MODE_MAIN,i);
      dailystochD=iStochastic(0,PERIOD_H4,18,3,3,MODE_EMA,0,MODE_SIGNAL,i);
      fourhrstochK=iStochastic(0,PERIOD_H4,5,3,3,MODE_EMA,0,MODE_MAIN,i);
      fourhrstochD=iStochastic(0,PERIOD_H4,5,3,3,MODE_EMA,0,MODE_SIGNAL,i);
      prevslowstochK=iStochastic(0,0,SlowK,SlowD,3,MODE_EMA,0,MODE_MAIN,i+1);
      bar3H=iHigh(0,0,i+2);
      bar3L=iLow(0,0,i+2);
      bar2H=iHigh(0,0,i+1);
      bar2C=iClose(0,0,i+1);
      bar2O=iOpen(0,0,i+1);
      bar2L=iLow(0,0,i+1);
      bar1H=iHigh(0,0,i);
      bar1L=iLow(0,0,i);
      bar1O=iOpen(0,0,i);
      bar1C=iClose(0,0,i);
      bar2fastMAvalue=iMA(0,0,FastMA,0,MODE_EMA,PRICE_CLOSE,i+1);
      bar2slowMAvalue=iMA(0,0,SlowMA,0,MODE_EMA,PRICE_CLOSE,i+1);
       bar3fastMAvalue=iMA(0,0,FastMA,0,MODE_EMA,PRICE_CLOSE,i+2);
      bar3slowMAvalue=iMA(0,0,SlowMA,0,MODE_EMA,PRICE_CLOSE,i+2);
       bar4fastMAvalue=iMA(0,0,FastMA,0,MODE_EMA,PRICE_CLOSE,i+3);
      bar4slowMAvalue=iMA(0,0,SlowMA,0,MODE_EMA,PRICE_CLOSE,i+3);
       bar5fastMAvalue=iMA(0,0,FastMA,0,MODE_EMA,PRICE_CLOSE,i+4);
      bar5slowMAvalue=iMA(0,0,SlowMA,0,MODE_EMA,PRICE_CLOSE,i+4);
       bar6fastMAvalue=iMA(0,0,FastMA,0,MODE_EMA,PRICE_CLOSE,i+5);
      bar6slowMAvalue=iMA(0,0,SlowMA,0,MODE_EMA,PRICE_CLOSE,i+5);
       bar7fastMAvalue=iMA(0,0,FastMA,0,MODE_EMA,PRICE_CLOSE,i+6);
      bar7slowMAvalue=iMA(0,0,SlowMA,0,MODE_EMA,PRICE_CLOSE,i+6);
       bar8fastMAvalue=iMA(0,0,FastMA,0,MODE_EMA,PRICE_CLOSE,i+7);
      bar8slowMAvalue=iMA(0,0,SlowMA,0,MODE_EMA,PRICE_CLOSE,i+7);
       bar9fastMAvalue=iMA(0,0,FastMA,0,MODE_EMA,PRICE_CLOSE,i+8);
      bar9slowMAvalue=iMA(0,0,SlowMA,0,MODE_EMA,PRICE_CLOSE,i+8);
       bar10fastMAvalue=iMA(0,0,FastMA,0,MODE_EMA,PRICE_CLOSE,i+9);
      bar10slowMAvalue=iMA(0,0,SlowMA,0,MODE_EMA,PRICE_CLOSE,i+9); 
      pinrange=(bar1H-bar1L);
      bar1xup=(false);
      bar2xup=(false);
      bar3xup=(false);
      bar4xup=(false);
      bar5xup=(false);
      bar6xup=(false);
      bar7xup=(false);
      bar8xup=(false);
      bar9xup=(false);
      bar10xup=(false);
      bar1xdn=(false);
      bar2xdn=(false);
      bar3xdn=(false);
      bar4xdn=(false);
      bar5xdn=(false);
      bar6xdn=(false);
      bar7xdn=(false);
      bar8xdn=(false);
      bar9xdn=(false);
      bar10xdn=(false);
      buyemail=(false);   
      sellemail=(false);
         
       // RSIBuffer[i]=iRSI(0,0,7,PRICE_CLOSE,i);
        // MAofRSIBuffer[i]=iMAOnArray(RSIBuffer[i],0,3,0,MODE_EMA,i);
         
         if(bar1C>=bar1H-pinrange/2.5 && bar1O>=bar1H-pinrange/2.5)
         buypin=(true);
         else
         buypin=(false);
         
         if(bar1C<=bar1L+pinrange/2.5 && bar1O<=bar1L+pinrange/2.5)
         sellpin=(true);
         else
         sellpin=(false);
         
         /*if(bar2H<bar3H && bar2L<bar3L && bar2H<bar1H && bar2L<bar1L)
         buy=(true);
         else
         buy=(false);
         
         if(bar2H>bar3H && bar2L>bar3L && bar2H>bar1H && bar2L>bar1L)
         sell=(true);
         else
         sell=(false); 
         */
         if(bar2fastMAvalue<bar2slowMAvalue && bar1fastMAvalue>bar1slowMAvalue)
         bar1xup=(true);
         if(bar3fastMAvalue<bar3slowMAvalue && bar2fastMAvalue>bar2slowMAvalue)
         bar2xup=(true);
         if(bar4fastMAvalue<bar4slowMAvalue && bar3fastMAvalue>bar3slowMAvalue)
         bar3xup=(true);
         if(bar5fastMAvalue<bar5slowMAvalue && bar4fastMAvalue>bar4slowMAvalue)
         bar4xup=(true);
         if(bar6fastMAvalue<bar6slowMAvalue && bar5fastMAvalue>bar5slowMAvalue)
         bar5xup=(true);
         if(bar7fastMAvalue<bar7slowMAvalue && bar6fastMAvalue>bar6slowMAvalue)
         bar6xup=(true);
         if(bar8fastMAvalue<bar8slowMAvalue && bar7fastMAvalue>bar7slowMAvalue)
         bar7xup=(true);
         if(bar9fastMAvalue<bar9slowMAvalue && bar8fastMAvalue>bar8slowMAvalue)
         bar8xup=(true);
         if(bar10fastMAvalue<bar10slowMAvalue && bar9fastMAvalue>bar9slowMAvalue)
         bar9xup=(true);
         
         
         if(buypin>0 && bar1xup>0 || bar2xup>0 || bar3xup>0 || bar4xup>0 || bar5xup>0 || bar6xup>0 || bar7xup>0 || bar8xup>0 || bar9xup>0)
         ExtMapBuffer1[i]=Low[i]-80*Point;
         else
         ExtMapBuffer1[i]=NULL;
         
         if(buypin>0 && i<5 && bar1xup>0 || bar2xup>0 || bar3xup>0 || bar4xup>0 || bar5xup>0 || bar6xup>0 || bar7xup>0 || bar8xup>0 || bar9xup>0)
         buyemail=(true);
         
         if(buyemail>0)
         SendMail("Buy Alert","Buy signal now on"+Symbol());
         
         
         if(bar2fastMAvalue>bar2slowMAvalue && bar1fastMAvalue<bar1slowMAvalue)
         bar1xdn=(true);
         if(bar3fastMAvalue>bar3slowMAvalue && bar2fastMAvalue<bar2slowMAvalue)
         bar2xdn=(true);
         if(bar4fastMAvalue>bar4slowMAvalue && bar3fastMAvalue<bar3slowMAvalue)
         bar3xdn=(true);
         if(bar5fastMAvalue>bar5slowMAvalue && bar4fastMAvalue<bar4slowMAvalue)
         bar4xdn=(true);
         if(bar6fastMAvalue>bar6slowMAvalue && bar5fastMAvalue<bar5slowMAvalue)
         bar5xdn=(true);
         if(bar7fastMAvalue>bar7slowMAvalue && bar6fastMAvalue<bar6slowMAvalue)
         bar6xdn=(true);
         if(bar8fastMAvalue>bar8slowMAvalue && bar7fastMAvalue<bar7slowMAvalue)
         bar7xdn=(true);
         if(bar9fastMAvalue>bar9slowMAvalue && bar8fastMAvalue<bar8slowMAvalue)
         bar8xdn=(true);
         if(bar10fastMAvalue>bar10slowMAvalue && bar9fastMAvalue<bar9slowMAvalue)
         bar9xdn=(true);
         
         if(sellpin>0 && bar1xdn>0 || bar2xdn>0 || bar3xdn>0 || bar4xdn>0 || bar5xdn>0 || bar6xdn>0 || bar7xdn>0 || bar8xdn>0 || bar9xdn>0)         
         ExtMapBuffer2[i]=High[i]+80*Point;
         else
         ExtMapBuffer2[i]=NULL;
         
         if(sellpin>0 && i<5 && i>=1 && bar1xdn>0 || bar2xdn>0 || bar3xdn>0 || bar4xdn>0 || bar5xdn>0 || bar6xdn>0 || bar7xdn>0 || bar8xdn>0 || bar9xdn>0)         
         sellemail=(true);
         
         if(sellemail>0)
         SendMail("Sell signal","Sell signal now on"+Symbol());
        
   }
 
cdsmart:

Hello again folks,

I have written an indicator which looks for a pinbar after a moving average cross over and have been trying in every spare minute for the last week to reliably get it to send me an email when conditions are satisfied. I have searched and read posts and documentation and the best i can come up with is what i will post below. My drama is that it sends way too many mails. I have currently got it set to a possible solution i read on one of raptorUKs replies to a similar problem...only send emails when looking at the 1st few bars. The way i have programmed it seems to work ok sometimes but not others (still starts sending bulk emails). Any help or push in the right direction would be greatly appreciated. Thanks.

Isn't buyemail a bool ? why this ?

if(buyemail > 0)

why is this test inside your loop ?


When do you want the email ? under what conditions ? when do you want it not to repeat ? under what conditions ? when do you want it to restart sending emails ?

 
Simply your bools
         buypin=(bar1C>=bar1H-pinrange/2.5 && bar1O>=bar1H-pinrange/2.5);
//       if(bar1C>=bar1H-pinrange/2.5 && bar1O>=bar1H-pinrange/2.5)
//       buypin=(true);
//       else
//       buypin=(false);

 
RaptorUK:

Isn't buyemail a bool ? why this ?

why is this test inside your loop ?


When do you want the email ? under what conditions ? when do you want it not to repeat ? under what conditions ? when do you want it to restart sending emails ?


OK raptor, thanks for that im guessing i just have to write some code to read current time, and indicator signal time etc, etc.. i can see how that will work...ill give it a try...more learning to do! Oh yeah and i thought instead of writing buyemail=(true) that >0 would do the same thing...0 being false...that not good practice?? Could it be misinterpreted?
 
cdsmart:

OK raptor, thanks for that im guessing i just have to write some code to read current time, and indicator signal time etc, etc.. i can see how that will work...ill give it a try...more learning to do! Oh yeah and i thought instead of writing buyemail=(true) that >0 would do the same thing...0 being false...that not good practice?? Could it be misinterpreted?

You could just write . . .

if(buyemail)

. . . . and then it's clear to everyone that buyemail is a bool.

 
WHRoeder:
Simply your bools


I

Ha...yeah i am aware that the else is unnecessary..and it doesnt look great....its only there because i started with this indicator as my very 1st indicator and ive added and changed heaps to make it do different things as ive being going...thats been there since the beginning and i havent tidied it up...ill get better ..the last programming i did was basic on a zx spectrum in 1980 something!

 
RaptorUK:

You could just write . . .

. . . . and then it's clear to everyone that buyemail is a bool.


Ah simple as that ....cool thanks... so would i be correct in thinking i could also tidy up a stament such as

 if(bar2fastMAvalue>bar2slowMAvalue && bar1fastMAvalue<bar1slowMAvalue)
         bar1xdn=(true);

to

 if(bar2fastMAvalue>bar2slowMAvalue && bar1fastMAvalue<bar1slowMAvalue)
         bar1xdn;

...simple basic stuff i know but once i know for definite i wont forget...

 
cdsmart:


Ah simple as that ....cool thanks... so would i be correct in thinking i could also tidy up a stament such as

to

...simple basic stuff i know but once i know for definite i wont forget...

Not quite . . . you could do this . . .

bar1xdn = (bar2fastMAvalue > bar2slowMAvalue && bar1fastMAvalue < bar1slowMAvalue);

. . . and it would be set to true or false, if you didn't want it to take a false value then you would do this . . .

if(bar2fastMAvalue > bar2slowMAvalue && bar1fastMAvalue < bar1slowMAvalue)
   bar1xdn = true;
 
RaptorUK:

Not quite . . . you could do this . . .

. . . and it would be set to true or false, if you didn't want it to take a false value then you would do this . . .


Ha yeah of course why didnt i think of that!? Just one more query on the subject of if statements raptor, after the test line can i tell it to do more than one thing eg some how make the following just one test line with multiple assignments after...do i use curly brackets or something like that...?

 if(buypin>0 && bar1xup>0 || bar2xup>0 || bar3xup>0 || bar4xup>0 || bar5xup>0 || bar6xup>0 || bar7xup>0 || bar8xup>0 || bar9xup>0)
         ExtMapBuffer1[i]=Low[i]-80*Point;

if(buypin>0  && bar1xup>0 || bar2xup>0 || bar3xup>0 || bar4xup>0 || bar5xup>0 || bar6xup>0 || bar7xup>0 || bar8xup>0 || bar9xup>0)
         buyemail=(true);
 
cdsmart:


Ha yeah of course why didnt i think of that!? Just one more query on the subject of if statements raptor, after the test line can i tell it to do more than one thing eg some how make the following just one test line with multiple assignments after...do i use curly brackets or something like that...?

Yep, curly braces is exactly what you need . . .

if(buypin > 0 && bar1xup > 0 || bar2xup > 0 || bar3xup > 0 || bar4xup > 0 || bar5xup > 0 || bar6xup > 0 || bar7xup > 0 || bar8xup > 0 || bar9xup > 0)
   {
   ExtMapBuffer1[i] = Low[i] - 80 * Point;
   buyemail = true;
   }


One other thing to note, be careful with your precedence, to avoid misunderstanding use ( ) brackets . . . some things are changing currently with MetaEditor and the Terminal with AND and OR precedence. Also, be consistent with your indenting, you can see my preference, pick your favoured style and apply it consistently.

Reason: