Price Alert

huangjin

Active Trader
May 19, 2015
11
1
27
Hi,Enivid, Thank for your great work ,I did like to share with everyone this TrendLine Alert,it origin Plays sound when Bid price crosses any trendline or horizontal line,i mod it to popup Alert as well , the only problem with it is it Alert every tick when it cross a line , i try to mod it to Alert only one each bar when it cross the line by add a time stamp function but it not work at all .please if you have time to look at it and point me to the right direction.Many many thank!! code i try to add
MQL4:
 static datetime lastbar;
 
   datetime curbar = Time[0];
 
   if(lastbar!=curbar)
 
   {
 
      lastbar=curbar;
 
      return (true);
 
   }
else return(false);
 

Attachments

  • TrendLine Alert-mod peter.mq4
    2.4 KB · Views: 24
  • TrendLine Alert-mod peter one alert per bar try-1.mq4
    2.6 KB · Views: 20
  • TrendLine Alert-mod peter one alert per bar try-2.mq4
    2.6 KB · Views: 23
  • TrendLine Alert-mod peter one alert per bar try-3.mq4
    2.7 KB · Views: 22
Last edited by a moderator:
  • 👍
Reactions: johnwboyd

Enivid

Administrator
Staff member
Nov 30, 2008
18,604
1,366
144
Odesa
www.earnforex.com
The code you have inserted here is correct, but you are applying it incorrectly inside your indicator code. Move it to a separate function and call it to check whether alert should be issued. If it returns true, do alert, if false - do nothing.
 

huangjin

Active Trader
May 19, 2015
11
1
27
The code you have inserted here is correct, but you are applying it incorrectly inside your indicator code. Move it to a separate function and call it to check whether alert should be issued. If it returns true, do alert, if false - do nothing.


Great done Many many thank!
 

huangjin

Active Trader
May 19, 2015
11
1
27
Thanks fly to Enivid

att are the indi that work ,I did see lot of interest out there :D Thanks fly to Enivid :)
 

Attachments

  • TrendLine Alert-mod peter one alert per bar try-7.mq4
    2.9 KB · Views: 36
  • TrendLine Alert-mod peter one alert per bar try-7.ex4
    6.7 KB · Views: 28

FXTraderTN

Trader
Nov 21, 2016
3
0
7
Hello @Enivid Could you please guide me how to modify this code to get sound alert only for each and every 2 seconds., with limitation of 100

for example if i set the alert level when it above 1.0655. it should alert 100 times (not instantly while price change., it should give bell sound only after 2 seconds).,

Kind Regards
 

FXTraderTN

Trader
Nov 21, 2016
3
0
7
You need to set up a timer with EventSetTimer() and then use OnTimer() event to check if alert condition is fulfillied, do the alerts, and advance alert counter (to stop doing alerts after it reaches 100).
Dude., I'm completely new to mt4 code. Kindly put the code in that indicator(you can just add the syntax where i can add that)., I really don't know how and where to use that code

With Regards
 

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
Wanted an alert to play a wav file of my choosing and thought I had found it with this indicator - All this one does is open the alert window and play the default sound. Could it be altered to only play sound with no alert window. I did try changing the wav file in MQ4 to no avail.
 

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
MQL4:
 Alert("Price is exactly at the alert level.");
      PlaySound("alert.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 " + SoundWhenPriceIsExactly);
      ObjectDelete("SoundWhenPriceIsExactly");
      SoundWhenPriceIsExactly = 0;

If I just changed Alert for PlaySound ????

Yes I'm guessing
 

hayseed

Master Trader
Jul 27, 2010
1,044
262
149
usa
Am now thinking totally remove
MQL4:
Alert("Price is exactly at the alert level.");
//----

hey maverick..... it is very difficult to use both playsound and alert functions together...... it's a timing issue..... metatrader will stack alerts one by one, but playsounds can get lost in the shuffle......

the beauty in the alert() function is that not only does it play a sound but allows you to write text.....

so a single ea watching every pair on every time for hundreds of different signals could alert and say "macd cross on the gbpusd 60 minute chart".....

playsounds can not be that extensive in information given..... so unless you only have 1 chart open, you'll hear the sound but might not know which chart.... you can create your own wavs.... such as one playsound() might say, 'gbpusd is above alert level' and call it but even that method is difficult.... and its almost impossible to string playsounds together to create a sentence.....

you can use text to speech, but timing becomes an issue again.....

playsound itself should accomplish your goal.....h


MQL4:
   if(Bid > alertlevel) {PlaySound("alert.wav");}
 
  • 👍
Reactions: Enivid

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
Thank you Hayseed for taking the time to reply :)

What would I need to remove and replace - (3 variations but basically the same)

Sorry but I am not really a coder :(

MQL4:
  }
   if ((Bid == SoundWhenPriceIsExactly) || (Ask == SoundWhenPriceIsExactly))
   {
      Alert("Price is exactly at the alert level.");
      PlaySound("alert.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 " + SoundWhenPriceIsExactly);
      ObjectDelete("SoundWhenPriceIsExactly");
      SoundWhenPriceIsExactly = 0;
   }

MQL4:
Alert("Price is exactly at the alert level.");
Is the Alert text

FYI i have had good results with Balabolka text to speech to create wav files
 

hayseed

Master Trader
Jul 27, 2010
1,044
262
149
usa
What would I need to remove and replace - (3 variations but basically the same)


MQL4:
  }
   if ((Bid == SoundWhenPriceIsExactly) || (Ask == SoundWhenPriceIsExactly))
   {
      //Alert("Price is exactly at the alert level.");
      PlaySound("alert.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 " + SoundWhenPriceIsExactly);
      ObjectDelete("SoundWhenPriceIsExactly");
      SoundWhenPriceIsExactly = 0;
   }

MQL4:
Alert("Price is exactly at the alert level.");
//----

hey maverick.... you can just delete the lines or use // before the line.... then recompile..... click the expand button above to see how i edited your code.....

you might want to replace SoundWhenPriceIsExactly = 0; with SoundWhenPriceIsExactly = 0.0;

rather than using == we usually say >= or <= as the case maybe.... otherwise it is quite possible for the bid and ask to jump clear over your SoundWhenPriceIsExactly value.... and you would never get an alert because of the == ......h
 

Maverick

Master Trader
Apr 3, 2014
453
6
79
Bournemouth UK
It works :) although your indicator will only play Events

I have my custom wav files in the Sounds folder how do I create a new event in the Events folder