Price Alert

hayseed

Master Trader
Jul 27, 2010
1,010
258
149
usa
Are you suggesting I replace ALL instances of 0 in the code with 0.0
//-----

hey maverick.... it's just a good habit to compare doubles to doubles..... you will avoid any issues arising from comparing a int to a double.... metatrader might make the correction automatically but just to be sure does not hurt to do it first.....

as example, you might code
extern double alertlevel = 1;
but later check the value in the inputs of the indicator.... metatrader automatically will change it to 1.0 .....h
 
  • 👍
Reactions: Maverick

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
Appreciate your help Hayseed :) Been looking at the code again and the O is actually an unknown quantity until you input a figure

Any suggestions about pointing the indicator in the direction of my wav files (in Sounds)
 

hayseed

Master Trader
Jul 27, 2010
1,010
258
149
usa
Any suggestions about pointing the indicator in the direction of my wav files (in Sounds)
//-----

hey maverick..... the playsounds() function knows where to look..... so you don't have to point it...... actually you can't point it ......

just make sure the file is a wav file and in metatraders sounds folder..... and be sure to spell it exactly including ""...... PlaySound("mine.wav") ....

even though metatrader could play a wav file of led zeppelins entire stairway to heaven perfectly, you should keep them short as possible......h
 

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
For whatever reason it's finding MY wav files today :)

Got there in the end . . . Thank you Hayseed and Enivid
 

johnwboyd

Trader
Jan 30, 2017
4
0
12
47
binaryoptionsindicatorsignals.com
I simplified the alert so it's less redundant with the code:
MQL4:
  if(NewBar())
             {
               PlaySound("alert.wav");Alert ("Price Level Alert ", Symbol()," ");
            }
9FIBg3.jpg


Could also say Price Level Reached. That may be better..
 
Last edited by a moderator:

johnwboyd

Trader
Jan 30, 2017
4
0
12
47
binaryoptionsindicatorsignals.com
What's that NewBar() function?

Sorry mate I don't even know I just copy and pasted. : )

hi Enivid

i've found one (futurespec) from forexfactory.com and he changed something in the code... so now the lines can be moved and the alert comes at the new price!
coool :)
here is the new indi!
regards raffi
I would like to suggest adding the input for call or put somehow. Not sure how that could be done but it'd be nice if the alert could say: AUDUSD Put etc.
 
Last edited by a moderator:

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
Been very happy with it so far :)

How could we make it even better ?

I'm thinking and hoping alerts at more than one level WHY ? as an alert when price is running away with YOUR money - Time to take action - personally I would have a Fog Horn for level 5 - to save enough wonga to start over again :)

AlertAbove_5
AlertAbove_4
AlertAbove_3
AlertAbove_2
AlertAbove_1
AlertExactly_
AlertBelow_1
AlertBelow_2
AlertBelow_3
AlertBelow_4
AlertBelow_5

No reason why they all couldn't all be the existing colours Green (up) - Yellow (exact) -Red (down) - Just different thickness (5 available)

Fortunately I have changed my O/S to Linux Mint and am now running my MT4 in a 32bit VirtualBox :) Happy Days
 

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
Lesson Learned
When I jumped Windows 7 last week I left in such a haste I forgot a lot of my indicators which were on the deck at the time and went down with the ship never to be seen again - RIP - Had to convert another PriceAlert into PriceNoAlert and remember where A lot of my favourites came from
 

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
Not really sure Hayseed if you are taking the p155 or not

Was never my intention to have ALL eleven in play at the same time - did initially think of three UP and three DOWN but then I thought better to have too many than not enough. Different sounds allocated to different line thicknesses. When I insert a line I only have 5 choices for style and 5 choices for thickness which is where I was coming from

The whole idea is NOT to be glued to the screen @|@ but to be notified when something happens - Just made another 100 :) OR A'rgh it's changed direction :(

In fact I have just missed a big re-trace / change in direction whilst sat here writing this - would have appreciated an alert
 

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
Houston we have a problem . . . I am writing this on my Linux Mint BUT my MetaEditor is in my VM so I can't copy and paste from one to the other :(

I'll be back
 

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
Well . . . I eventually decided on three UP levels and three DOWN levels . . . K.I.S.S :)

However, I have a couple of errors in the code which I can't seen to figure out

Be obliged if someone could set me straight . . . tried comparing to original but I can't see it :(

MQL4:
//+------------------------------------------------------------------+
//|                                              PriceAudioAlert.mq4 |
//|                         Copyright © 2009-2011, www.earnforex.com |
//|           Issues sound alerts when price reaches certain levels. |
//|                                                         Modded by Mn |
//|                        Extra levels added by Maverick 02.03.2017 |
//+------------------------------------------------------------------+
#property copyright "EarnForex.com"
#property link      "http://www.earnforex.com"
 
#property indicator_chart_window
 
extern double PriceAbove_3 = 0;
extern double PriceAbove_2 = 0;
extern double PriceAbove_1 = 0;
extern double PriceExact_0 = 0;
extern double PriceBelow_1 = 0;
extern double PriceBelow_2 = 0;
extern double PriceBelow_3 = 0;
 
extern bool SendEmail = false; //If true e-mail is sent to the e-mail address set in your MT4. E-mail SMTP Server settings should also be configured in your MT4
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
 
if (PriceAbove_3 > 0)
   {
      ObjectCreate("PriceAbove_3", OBJ_HLINE, 0, Time[0], PriceAbove_3);
      ObjectSet("PriceAbove_3", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("PriceAbove_3", OBJPROP_COLOR, Green);
      ObjectSet("PriceAbove_3", OBJPROP_WIDTH, 1);
   }
 
   if (PriceAbove_2 > 0)
   {
      ObjectCreate("PriceAbove_2", OBJ_HLINE, 0, Time[0], PriceAbove_2);
      ObjectSet("PriceAbove_2", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("PriceAbove_2", OBJPROP_COLOR, Green);
      ObjectSet("PriceAbove_2", OBJPROP_WIDTH, 1);
   }
 
   if (PriceAbove_1 > 0)
   {
      ObjectCreate("PriceAbove_1", OBJ_HLINE, 0, Time[0], PriceAbove_1);
      ObjectSet("PriceAbove_1", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("PriceAbove_1", OBJPROP_COLOR, Green);
      ObjectSet("PriceAbove_1", OBJPROP_WIDTH, 1);
   }
 
   if (PriceExact_0 > 0)
   {
      ObjectCreate("PriceExact_0", OBJ_HLINE, 0, Time[0], PriceExact_0);
      ObjectSet("PriceExact_0", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("PriceExact_0", OBJPROP_COLOR, Aqua);
      ObjectSet("PriceExact_0", OBJPROP_WIDTH, 1);
   }
 
   if (PriceBelow_1 > 0)
   {
      ObjectCreate("PriceBelow_1 ", OBJ_HLINE, 0, Time[0], PriceBelow_1);
      ObjectSet("PriceBelow_1 ", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("PriceBelow_1 ", OBJPROP_COLOR, Red);
      ObjectSet("PriceBelow_1 ", OBJPROP_WIDTH, 1);
   }
   if (PriceBelow_2 > 0)
   {
      ObjectCreate("PriceBelow_2 ", OBJ_HLINE, 0, Time[0], PriceBelow_2);
      ObjectSet("PriceBelow_2 ", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("PriceBelow_2 ", OBJPROP_COLOR, Red);
      ObjectSet("PriceBelow_2 ", OBJPROP_WIDTH, 1);
   }
 
   if (PriceBelow_3 > 0)
   {
      ObjectCreate("PriceBelow_3 ", OBJ_HLINE, 0, Time[0], PriceBelow_3);
      ObjectSet("PriceBelow_3 ", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("PriceBelow_3 ", OBJPROP_COLOR, Red);
      ObjectSet("PriceBelow_3 ", OBJPROP_WIDTH, 1);
   }
 
   return(0);
 
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
 
int deinit()
 
    ObjectDelete("PriceAbove_3");
    ObjectDelete("PriceAbove_2");
    ObjectDelete("PriceAbove_1");
{   ObjectDelete("PriceExact_0");
    ObjectDelete("PriceBelow_1");
    ObjectDelete("PriceBelow_2");
    ObjectDelete("PriceBelow_3");
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
// added by Mn -----------------------------------------------------------
 
   if (ObjectGet("PriceAbove_3", 1) != PriceAbove_3)
     PriceAbove_3= ObjectGet("PriceAbove_3", 1);
 
   if (ObjectGet("PriceAbove_2", 1) != PriceAbove_2)
     PriceAbove_2= ObjectGet("PriceAbove_2", 1);
 
   if (ObjectGet("PriceAbove_1", 1) != PriceAbove_1)
     PriceAbove_1= ObjectGet("PriceAbove_1", 1);
 
   if (ObjectGet("PriceExact_0", 1) != PriceExact_0)
     PriceExact_0 = ObjectGet("PriceExact_0", 1);
 
   if (ObjectGet("PriceBelow_1", 1) != PriceBelow_1)
     PriceBelow_1 = ObjectGet("PriceBelow_1", 1);
 
   if (ObjectGet("PriceBelow_2", 1) != PriceBelow_2)
     PriceBelow_2 = ObjectGet("PriceBelow_2", 1);
 
   if (ObjectGet("PriceBelow_3", 1) != PriceBelow_3)
     PriceBelow_3 = ObjectGet("PriceBelow_3", 1);
 
// added by Mn -----------------------------------------------------------
 
   if ((Ask > PriceAbove_3) && (PriceAbove_3 > 0))
   {
      Alert("Price above the alert level 3.");
      PlaySound("ring-ring-ring.wav");
      SendMail("Price for " + Symbol() +  " above the alert level 3 " + Ask, "Price for " + Symbol() +  " reached " + Ask + " level, which is above your alert level of " + PriceAbove_3);
      ObjectDelete("PriceAbove_3");
      PriceAbove_3 = 0
 
   if ((Ask > PriceAbove_2) && (PriceAbove_2 > 0))
   {
      Alert("Price above the alert level 2.");
      PlaySound("ring-ring.wav");
      SendMail("Price for " + Symbol() +  " above the alert level 2 " + Ask, "Price for " + Symbol() +  " reached " + Ask + " level, which is above your alert level of " + PriceAbove_2);
      ObjectDelete("PriceAbove_2");
      PriceAbove_2 = 0
 
   if ((Ask > PriceAbove_1) && (PriceAbove_1 > 0))
   {
      Alert("Price above the alert level 1.");
      PlaySound("ring.wav");
      SendMail("Price for " + Symbol() +  " above the alert level 1 " + Ask, "Price for " + Symbol() +  " reached " + Ask + " level, which is above your alert level of 1 " + PriceAbove_1);
      ObjectDelete("PriceAbove_1");
      PriceAbove_1= 0
 
   if ((Bid == PriceExact_0) || (Ask == PriceExact_0))
   {
      Alert("Price is exactly at the alert level.");
      PlaySound("glass-ping.wav");
      SendMail("Price for " + Symbol() +  " exactly at the alert level " + Ask, "Price for " + Symbol() +  " reached " + Ask + "/" + Bid + " level, which is exactly your alert level of " + PriceExact_0);
      ObjectDelete("PriceExact_0");
      PriceExact_0 = 0;
 
   if ((Bid < PriceBelow_1) && (PriceBelow_1 > 0))
   {
      Alert("PriceBelow_1");
      PlaySound("phone.wav");
      SendMail("Price for " + Symbol() +  " below the alert level " + Bid, "Price for " + Symbol() +  " reached " + Bid + " level, which is below your alert level of " + PriceBelow_1);
      ObjectDelete("PriceBelow_1");
      PriceBelow_1 = 0;
 
   if ((Bid < PriceBelow_1) && (PriceBelow_1 > 0))
   {
      Alert("PriceBelow_2");
      PlaySound("phone-phone.wav");
      SendMail("Price for " + Symbol() +  " below the alert level " + Bid, "Price for " + Symbol() +  " reached " + Bid + " level, which is below your alert level of " + PriceBelow_1);
      ObjectDelete("PriceBelow_2");
      PriceBelow_2 = 0;
 
   if ((Bid < PriceBelow_1) && (PriceBelow_1 > 0))
   {
      Alert("PriceBelow_3");
      PlaySound("phone-phone-phone.wav");
      SendMail("Price for " + Symbol() +  " below the alert level " + Bid, "Price for " + Symbol() +  " reached " + Bid + " level, which is below your alert level of " + PriceBelow_3);
      ObjectDelete("PriceBelow_3");
      PriceBelow_3 = 0;
 
   }
 
   }
   return(0);
}
//+------------------------------------------------------------------+

And another thing . . . how do I make this code box smaller ?

.
 

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
H'mmm . . . might have at least spotted one error

5 lines up from the bottom } should not be there me thinks

*************************************************
No it still doesn't work :(

.
 

hayseed

Master Trader
Jul 27, 2010
1,010
258
149
usa
However, I have a couple of errors in the code which I can't seen to figure out
//----

hey maverick..... yes there were a few..... added linewidth to the inputs so you can see what i meant about unlimited sizes..... now sky's the limit......h
//------

MQL4:
//+------------------------------------------------------------------+
//|                                              PriceAudioAlert.mq4 |
//|                         Copyright © 2009-2011, www.earnforex.com |
//|           Issues sound alerts when price reaches certain levels. |
//|                                                         Modded by Mn |
//|                        Extra levels added by Maverick 02.03.2017 |
//+------------------------------------------------------------------+
#property copyright "EarnForex.com"
#property link      "http://www.earnforex.com"
 
#property indicator_chart_window
 
extern double PriceAbove_3 = 0;
extern double PriceAbove_2 = 0;
extern double PriceAbove_1 = 0;
extern double PriceExact_0 = 0;
extern double PriceBelow_1 = 0;
extern double PriceBelow_2 = 0;
extern double PriceBelow_3 = 0;
 
extern int    linewidth    = 1;
 
extern bool SendEmail = false; //If true e-mail is sent to the e-mail address set in your MT4. E-mail SMTP Server settings should also be configured in your MT4
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
 
if (PriceAbove_3 > 0)
    {
       ObjectCreate("PriceAbove_3", OBJ_HLINE, 0, Time[0], PriceAbove_3);
       ObjectSet("PriceAbove_3", OBJPROP_STYLE, STYLE_SOLID);
       ObjectSet("PriceAbove_3", OBJPROP_COLOR, Green);
       ObjectSet("PriceAbove_3", OBJPROP_WIDTH, linewidth);
    }
 
    if (PriceAbove_2 > 0)
    {
       ObjectCreate("PriceAbove_2", OBJ_HLINE, 0, Time[0], PriceAbove_2);
       ObjectSet("PriceAbove_2", OBJPROP_STYLE, STYLE_SOLID);
       ObjectSet("PriceAbove_2", OBJPROP_COLOR, Green);
       ObjectSet("PriceAbove_2", OBJPROP_WIDTH, linewidth);
    }
 
    if (PriceAbove_1 > 0)
    {
       ObjectCreate("PriceAbove_1", OBJ_HLINE, 0, Time[0], PriceAbove_1);
       ObjectSet("PriceAbove_1", OBJPROP_STYLE, STYLE_SOLID);
       ObjectSet("PriceAbove_1", OBJPROP_COLOR, Green);
       ObjectSet("PriceAbove_1", OBJPROP_WIDTH, linewidth);
    }
 
    if (PriceExact_0 > 0)
    {
       ObjectCreate("PriceExact_0", OBJ_HLINE, 0, Time[0], PriceExact_0);
       ObjectSet("PriceExact_0", OBJPROP_STYLE, STYLE_SOLID);
       ObjectSet("PriceExact_0", OBJPROP_COLOR, Aqua);
       ObjectSet("PriceExact_0", OBJPROP_WIDTH, linewidth);
    }
 
    if (PriceBelow_1 > 0)
    {
       ObjectCreate("PriceBelow_1 ", OBJ_HLINE, 0, Time[0], PriceBelow_1);
       ObjectSet("PriceBelow_1 ", OBJPROP_STYLE, STYLE_SOLID);
       ObjectSet("PriceBelow_1 ", OBJPROP_COLOR, Red);
       ObjectSet("PriceBelow_1 ", OBJPROP_WIDTH, linewidth);
    }
    if (PriceBelow_2 > 0)
    {
       ObjectCreate("PriceBelow_2 ", OBJ_HLINE, 0, Time[0], PriceBelow_2);
       ObjectSet("PriceBelow_2 ", OBJPROP_STYLE, STYLE_SOLID);
       ObjectSet("PriceBelow_2 ", OBJPROP_COLOR, Red);
       ObjectSet("PriceBelow_2 ", OBJPROP_WIDTH, linewidth);
    }
 
    if (PriceBelow_3 > 0)
    {
       ObjectCreate("PriceBelow_3 ", OBJ_HLINE, 0, Time[0], PriceBelow_3);
       ObjectSet("PriceBelow_3 ", OBJPROP_STYLE, STYLE_SOLID);
       ObjectSet("PriceBelow_3 ", OBJPROP_COLOR, Red);
       ObjectSet("PriceBelow_3 ", OBJPROP_WIDTH, linewidth);
    }
 
    return(0);
    }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
 
int deinit()
    {
     ObjectDelete("PriceAbove_3");
     ObjectDelete("PriceAbove_2");
     ObjectDelete("PriceAbove_1");
     ObjectDelete("PriceExact_0");
     ObjectDelete("PriceBelow_1");
     ObjectDelete("PriceBelow_2");
     ObjectDelete("PriceBelow_3");
    return(0);
    }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
// added by Mn -----------------------------------------------------------
 
    if (ObjectGet("PriceAbove_3", 1) != PriceAbove_3)
      PriceAbove_3= ObjectGet("PriceAbove_3", 1);
 
    if (ObjectGet("PriceAbove_2", 1) != PriceAbove_2)
      PriceAbove_2= ObjectGet("PriceAbove_2", 1);
 
    if (ObjectGet("PriceAbove_1", 1) != PriceAbove_1)
      PriceAbove_1= ObjectGet("PriceAbove_1", 1);
 
    if (ObjectGet("PriceExact_0", 1) != PriceExact_0)
      PriceExact_0 = ObjectGet("PriceExact_0", 1);
 
    if (ObjectGet("PriceBelow_1", 1) != PriceBelow_1)
      PriceBelow_1 = ObjectGet("PriceBelow_1", 1);
 
    if (ObjectGet("PriceBelow_2", 1) != PriceBelow_2)
      PriceBelow_2 = ObjectGet("PriceBelow_2", 1);
 
    if (ObjectGet("PriceBelow_3", 1) != PriceBelow_3)
      PriceBelow_3 = ObjectGet("PriceBelow_3", 1);
 
// added by Mn -----------------------------------------------------------
 
    if ((Ask > PriceAbove_3) && (PriceAbove_3 > 0))
    {
       Alert("Price above the alert level 3.");
       PlaySound("ring-ring-ring.wav");
       SendMail("Price for " + Symbol() +  " above the alert level 3 " + Ask, "Price for " + Symbol() +  " reached " + Ask + " level, which is above your alert level of " + PriceAbove_3);
       ObjectDelete("PriceAbove_3");
       PriceAbove_3 = 0;
    }
//----
    if ((Ask > PriceAbove_2) && (PriceAbove_2 > 0))
    {
       Alert("Price above the alert level 2.");
       PlaySound("ring-ring.wav");
       SendMail("Price for " + Symbol() +  " above the alert level 2 " + Ask, "Price for " + Symbol() +  " reached " + Ask + " level, which is above your alert level of " + PriceAbove_2);
       ObjectDelete("PriceAbove_2");
       PriceAbove_2 = 0;
    }
//---   
    if ((Ask > PriceAbove_1) && (PriceAbove_1 > 0))
    {
       Alert("Price above the alert level 1.");
       PlaySound("ring.wav");
       SendMail("Price for " + Symbol() +  " above the alert level 1 " + Ask, "Price for " + Symbol() +  " reached " + Ask + " level, which is above your alert level of 1 " + PriceAbove_1);
       ObjectDelete("PriceAbove_1");
       PriceAbove_1= 0;
    }
//----
    if ((Bid == PriceExact_0) || (Ask == PriceExact_0))
    {
       Alert("Price is exactly at the alert level.");
       PlaySound("glass-ping.wav");
       SendMail("Price for " + Symbol() +  " exactly at the alert level " + Ask, "Price for " + Symbol() +  " reached " + Ask + "/" + Bid + " level, which is exactly your alert level of " + PriceExact_0);
       ObjectDelete("PriceExact_0");
       PriceExact_0 = 0;
    }
//----
    if ((Bid < PriceBelow_1) && (PriceBelow_1 > 0))
    {
       Alert("PriceBelow_1");
       PlaySound("phone.wav");
       SendMail("Price for " + Symbol() +  " below the alert level " + Bid, "Price for " + Symbol() +  " reached " + Bid + " level, which is below your alert level of " + PriceBelow_1);
       ObjectDelete("PriceBelow_1");
       PriceBelow_1 = 0;
    }
//----
    if ((Bid < PriceBelow_1) && (PriceBelow_1 > 0))
    {
       Alert("PriceBelow_2");
       PlaySound("phone-phone.wav");
       SendMail("Price for " + Symbol() +  " below the alert level " + Bid, "Price for " + Symbol() +  " reached " + Bid + " level, which is below your alert level of " + PriceBelow_1);
       ObjectDelete("PriceBelow_2");
       PriceBelow_2 = 0;
    }
//----
 
    if ((Bid < PriceBelow_1) && (PriceBelow_1 > 0))
    {
       Alert("PriceBelow_3");
       PlaySound("phone-phone-phone.wav");
       SendMail("Price for " + Symbol() +  " below the alert level " + Bid, "Price for " + Symbol() +  " reached " + Bid + " level, which is below your alert level of " + PriceBelow_3);
       ObjectDelete("PriceBelow_3");
       PriceBelow_3 = 0;
    }
//----
 
 
    return(0);
}
//+------------------------------------------------------------------+
 

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
I suppose to cover all bases could also add

MQL4:
extern int    linestyle    = 1;

But it would need a legend for the different styles

You never actually indicated where I had gone wrong - for future coding :)
 

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
PAA_zps3movf1jf.png


Minor details:

1. The linewidth needs to be for each line if it's going to be in inputs
2. The line style doesn't work

Might be easier to forget about linestyle - can only be used with width 1 anyway :(

And revert back to line width in editor

H'mmm ... choice of width or choice of style ?

After some thought ... decided to go with choice of style for each line ... Thick lines WILL make it messy

I honestly thought from my previous encounters that editor used numbers for linestyle ... what am I missing ?