Alert only on certain periods

 

Hello,

I'm writing a sound alert, but would like it only to appear on certain periods. I have the following:

PlaySound("MACD cross on ",Symbol()," ",Period()); 

I would like it to appear only on the period M30 and H1. Do I write 2 consecutive lines where I each specify the period 30 and 60? How can I write this in one single line so that the sound works one single time?

Thank you. 

 

Hi,


you can do an array like this for period()

int TF[] = { 30, 60};

  for (int i=0; i<ArraySize(TF); i++)
  {
     PlaySound("MACD cross on ",Symbol()," ",TF[i]());
  }

But maybe it's better to write two line cause this code is longer than yours.


But you can.

 
Kane59:

Hi,


you can do an array like this for period()

But maybe it's better to write two line cause this code is longer than yours.


But you can.


Thank you Kane59.

I put in 2 lines, but receive the following message when compiling:

')' - wrong parameters count C:\Program Files (x86)\Tradeview MetaTrader 4 Terminal\experts\indicators\[i] MACD Crossover Signal.mq4 (75, 51)

This is one of the lines:

PlaySound("MACD cross on ",Symbol()," ",30);

I tested putting the number in brackets () or {} but still the same message 'wrong parameters count'. Why is that?

Thank you. 

 
zeno1:


Thank you Kane59.

I put in 2 lines, but receive the following message when compiling:

')' - wrong parameters count C:\Program Files (x86)\Tradeview MetaTrader 4 Terminal\experts\indicators\[i] MACD Crossover Signal.mq4 (75, 51)

This is one of the lines:

I tested putting the number in brackets () or {} but still the same message 'wrong parameters count'. Why is that?

Thank you. 


ohh i didn't see that like that !

In Playsound you have to put a wave sound like this

PlaySound("Alarm.wav");

I think you want + one alert message?

int tf[] {30,60}
string TfToStr[] = {"M30", "H1"};

if (Condition)
{
        PlaySound(.......);
        for(int z=0; z<ArraySize(tf); z++)
          {      
              Alert("MACD cross on"| Symbol()| "TfToStr[z]");
          }
}

You will have message and sound in same time.

 
Kane59:

ohh i didn't see that like that !

In Playsound you have to put a wave sound like this

I think you want + one alert message?

You will have message and sound in same time.


Thank you for your suggestion Kane59.

I send you attached my mq4 file, but in compilation I receive error messages?

 

ok 2 errors:

take the 2 arraysize in Top with your external variable.

in one of the arraysize, you forgot a "=" search you will find...

you have define 2 or more time the "z" variable, change letter or code to have unique "z"


and change this:


Alert("MACD cross on"+ Symbol()+ "TfToStr[z]");
Error from me.
 
zeno1:


Thank you for your suggestion Kane59.

I send you attached my mq4 file, but in compilation I receive error messages?

So fix them . . .  I have,  it took me 5 mins.
 

I think your "i" variable won't do anything. You have to include this with your crossdown/Up[i].


You closed the cycle i before use your Crossdown/Up. CrossUp and down have to be on the "i" cycle.

 

Kane59, thank you. I made your suggested changes and so compilation worked.

You're also right that my last bar counted 'function' (?) is not working, so I get alerts a few times per second.

My objective is to receive only one alert (sound) per newly bar formed, with the message using the string of charts.

How can I include this in the "i" cycle?

Thank you. 

The code to be modified so that alert only runs once at start of formation of bar:

int tf[] = {30,60};
string TfToStr[] = {"M30", "H1"}; 

      if ((MACD_Signal < MACD_Main) && (MACD_SignalPrevious > MACD_MainPrevious)) {
         CrossUp[i] = Low[i] - Range*0.5;

    
        for(int z=0; z<ArraySize(tf); z++)
          {      
              Alert("MACD cross on "+ Symbol()+ " " + TfToStr[z]);
          }
      }
      else if ((MACD_Signal > MACD_Main) && (MACD_SignalPrevious < MACD_MainPrevious)) {
         CrossDown[i] = High[i] + Range*0.5;

  
        for(int y=0; y<ArraySize(tf); y++)
          {      
              Alert("MACD cross on "+ Symbol()+ " " + TfToStr[y]);
          }
 

hi,

I really want a MACD alert that signals the trend reversal but, that works on certain periods (M1, M5 ... H1) of specific crosses.

Have any of you completed the design of what we are discussing here?