Jump to content

(REQ) Plese teach me how to add audibl alert to inditcators


Recommended Posts

I don't know whether you have any programming experience so I don't know how detailed to explain it.

 

Basically, this line will do the alert:

 

Alert("Insert the text in these speech marks"); 

 

But it is not as simple as placing that anywhere, or else it will alert for either no reason or for the wrong reason.

 

You need a condition to be satisfied for the alert. So maybe, MACD crossed or a color change on an indicator. This is how you find out if the condition is satisfied:

 

Each external value in an indicator has a buffer. E.g. you will see these lines. The first one will be at the top of the code and the second one in the init() function.

 

double buffer1[];
SetIndexBuffer(0,buffer1);

 

To find out which indicator value these buffers hold, open MT4 and load up the indicator. Then click on DATA WINDOW in the toolbar. Hover over a candle and there should be values of the indicator. Next, go somewhere where your condition is satisfied and check for a pattern when it is satisfied and when it isn't. E.g. For a MACD cross, it could be that buffer1 is higher buffer2 in the previous bar, but buffer2 is higher than buffer1 in the next bar or the bar after. For a color change, it could be that buffer 3 is 0.005 when there is a red bar and buffer4 has no value, and vice versa for if its green.

 

Once you find this out, you can create the logic for when the condition is satisfied using if statements or other constructs. For colour change it could be:

 

if(buffer3[1]==EMPTY_VALUE && buffer4[1]>0)

Using the example above this would mean that bar was green.

 

I mentioned before that how to alert is just to type Alert("Color Change"); This is true but just inserting this into the if statement would cause millions of alerts. So when we create the alert we need something to say what the time was when the alert happened and then something to tell it not to alert again within the current bar. So we declare these internal parameters at the top of the code:

 

datetime TOAL1, TOAS1, TOAL2, TOAS2;

 

TOAL1 means time of alert long 1. So I would use this as the time of the color change to green. TOAS1 means time of alert short 1, used for red color change. The second ones are for a different condition, just to show you that you can have many different conditions, this one could be the cross.

 

Now the alert logic. This can be done many ways, but this is how I do it:

 

void AlertColor()
{
  if(ShowAlert) 
  {
      if(buffer4[1]>0 && buffer3[1]==EMPTY_VALUE && TOAL1!=Time[0]) //Checks that TOAL1 is not equal to current bar time
     {
        //long signal alert
        Alert("LONG: " + Symbol()); //If on GBPUSD the alert would be: LONG: GBPUSD
        TOAL1 = Time[0]; // TOA
     }
     
     if(buffer3[1]>0 && buffer4[1]==EMPTY_VALUE && TOAS1!=Time[0])
     {
        //long signal alert
        Alert("SHORT: " + Symbol());
        TOAS1 = Time[0];
     }
  }
}

 

I use a separate function for the alert. I would also use a separate function for each alert condition, e.g. color or cross, etc. This should all be familiar from above except the if(ShowAlert) . This is just an external parameter on whether to use alerts or not. To do this you would just type this somewhere near where you typed datetime TOAL1...

 

extern bool ShowAlert = true;

 

True means the alerts are on. Now you are almost done. You need to run the alert function. Do this by typing the name of the function inside the start function but right at the top. I would type:

 

AlertColor();

 

Now you are done.

 

Btw, buffer1[1] means the previous bar, buffer1[0] means the current bar.

 

Chris

Edited by chrisbenjy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...