• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 11:57pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 11:57pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

How to make EA that send Open Price of Candle for every new candle 5 replies

A little help with an end of candle alert HA indicator 2 replies

Help someone, trying to add email alert 3 replies

HELP!!! Trying to play custom alert sound file! 5 replies

5 Times Leverage, 2% Risk Per Trade Can Make You Rich 21 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 1
Attachments: Help! Trying to make alert to ring 3 times per candle
Exit Attachments
Tags: Help! Trying to make alert to ring 3 times per candle
Cancel

Help! Trying to make alert to ring 3 times per candle

  • Post #1
  • Quote
  • First Post: Edited 3:29am Nov 20, 2020 2:55am | Edited 3:29am
  •  Don_xyZ
  • | Joined Dec 2010 | Status: Member | 67 Posts
Hi,

I just started to learn about mql5 and I've tried to make an alert with little success because I am struggling with 1 probem as my learning is still incomplete. What I'm trying to do is make an alert to just ring 3 times per candle and not per on tick.

Here's what I've done so far:

Inserted Code
void OnTick()
  {
   // create Array for prices
   double myMovingAverageArray1[], myMovingAverageArray2[], myMovingAverageArray3[];
   //define the properties of the Moving Average1
   int movingAverageDefinition1 = iMA (_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE);
   //define the properties of the Moving Average2
   int movingAverageDefinition2 = iMA (_Symbol,_Period,34,0,MODE_EMA,PRICE_CLOSE);
  
   //define the properties of the Moving Average3
   int movingAverageDefinition3 = iMA (_Symbol,_Period,55,0,MODE_EMA,PRICE_CLOSE);
   //sort the price Array1 from the current candle downwards
   ArraySetAsSeries(myMovingAverageArray1,true);
   //sort the price Array2 from the current candle downwards
   ArraySetAsSeries(myMovingAverageArray2,true);
  
   //sort the price Array3 from the current candle downwards
   ArraySetAsSeries(myMovingAverageArray3,true);
   //Defined MA1, one line, current candle, 3 candles, store result
   CopyBuffer(movingAverageDefinition1,0,0,3,myMovingAverageArray1);
   //Defined MA2, one line, current candle, 3 candles, store result
   CopyBuffer(movingAverageDefinition2,0,0,3,myMovingAverageArray2);
  
   //Defined MA3, one line, current candle, 3 candles, store result
   CopyBuffer(movingAverageDefinition3,0,0,3,myMovingAverageArray3);
   if ( //Potential Buy trade alert
      (myMovingAverageArray3[0] > myMovingAverageArray2[0])
   && (myMovingAverageArray3[0] - myMovingAverageArray2[0] <0.00010)
   && (myMovingAverageArray3[0] - myMovingAverageArray2[0] >0.00000)
   && (myMovingAverageArray1[0] > myMovingAverageArray1[1])
   )
  
   PlaySound("Store_Door_Chime-Mike_Koenig-570742973.wav");
  
  
   if ( //Potential Sell trade alert
      (myMovingAverageArray2[0] > myMovingAverageArray3[0])
   && (myMovingAverageArray2[0] - myMovingAverageArray3[0] <0.00010)
   && (myMovingAverageArray2[0] - myMovingAverageArray3[0] >0.00000)
   && (myMovingAverageArray1[1] > myMovingAverageArray1[0])
   )
  
   PlaySound("decay.wav");
  
  
  }
//+------------------------------------------------------------------+

Can someone help me please?

Thanks a million!

edit: the code is for mql5
Different/opposing ideas will make us learn and understand many things.
  • Post #2
  • Quote
  • Nov 20, 2020 4:21am Nov 20, 2020 4:21am
  •  BlueRain
  • Joined Sep 2019 | Status: Member | 1,053 Posts
Not familiar with MT5 coding as I don't use MT5.
But, principle is same.

Steps:
1. You will need a alert function where you will monitor

* is this new candle?
* is this new msg?

typically, in MT4, this is done this way


void doAlert(int forBar, string doWhat)
{
static string previousAlert="nothing";
static datetime previousTime;


if (previousAlert != doWhat && previousTime != Time[forBar])
{
previousAlert = doWhat;
previousTime = Time[forBar];

//
// message = StringConcatenate(Symbol(),", ",timeFrameToString(_Period)," HP ",doWhat," @ ",TimeToStr(TimeLocal(),TIME_SECONDS));
if (alertsMessage) Alert(doWhat);
if (alertsEmail) SendMail(StringConcatenate(Symbol(),"Pman Cross over "),doWhat);
if (alertsNotification) SendNotification(doWhat);
if (alertsSound) PlaySound("alert.wav");
}
}

Basically, you create an static variable and when it is called, you update previoustime with Time[0] which current bar time.

if ( previoustime == Time[0]), that means it is still in same candle and we don't send a new alerts.



Extra:
Seach MT5 Alert in internet and you should have few samples also.
https://www.mql5.com/en/articles/1371

there is func isNewBar()...

using that, you can also do
if ( isNewBar() == true) { DoAlert() }

hope this helps.
 
2
  • Post #3
  • Quote
  • Nov 20, 2020 6:37am Nov 20, 2020 6:37am
  •  ganztrade
  • Joined Oct 2020 | Status: Member | 334 Posts
Quoting Don_xyZ
Disliked
Hi, I just started to learn about mql5 and I've tried to make an alert with little success because I am struggling with 1 probem as my learning is still incomplete. What I'm trying to do is make an alert to just ring 3 times per candle and not per on tick. Here's what I've done so far: void OnTick() { // create Array for prices double myMovingAverageArray1[], myMovingAverageArray2[], myMovingAverageArray3[]; //define the properties of the Moving Average1 int movingAverageDefinition1 = iMA (_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE); //define the...
Ignored

Hello Don,

I'm just new to learn mq4 code, my mq5 knowledge is Zero

Sorry can't help you for code, but sometimes I use MT5 and I have a indicator that have alert.

Maybe if you look these indicator, you got some clue/idea

Regards
Attached File(s)
File Type: mq5 MA-Crossover_Alert.mq5   26 KB | 65 downloads
Margin Call again and again...
 
 
  • Post #4
  • Quote
  • Nov 22, 2020 7:35am Nov 22, 2020 7:35am
  •  Don_xyZ
  • | Joined Dec 2010 | Status: Member | 67 Posts
Quoting BlueRain
Disliked
{quote} Not familiar with MT5 coding as I don't use MT5. But, principle is same. Steps: 1. You will need a alert function where you will monitor * is this new candle? * is this new msg? typically, in MT4, this is done this way void doAlert(int forBar, string doWhat) { static string previousAlert="nothing"; static datetime previousTime; if (previousAlert != doWhat && previousTime != Time[forBar]) { previousAlert = doWhat; previousTime = Time[forBar]; // // message = StringConcatenate(Symbol(),", ",timeFrameToString(_Period)," HP ",doWhat," @ ",TimeToStr(TimeLocal(),TIME_SECONDS));...
Ignored
Hmmmm.... I'm green to this mql5, those are the things that I can picked up by watching some vids on YT.

I purchased a course on mql4 after I read your reply on Friday to have some basics on how things work.

Thanks for the pointers!
Different/opposing ideas will make us learn and understand many things.
 
 
  • Post #5
  • Quote
  • Nov 22, 2020 7:38am Nov 22, 2020 7:38am
  •  Don_xyZ
  • | Joined Dec 2010 | Status: Member | 67 Posts
Quoting ganztrade
Disliked
{quote} Hello Don, I'm just new to learn mq4 code, my mq5 knowledge is Zero Sorry can't help you for code, but sometimes I use MT5 and I have a indicator that have alert. Maybe if you look these indicator, you got some clue/idea Regards {file}
Ignored
Yes, I have that indicator but it's for doing other things.
I'm trying to get an alert before the MAs touch each other.
I also have 0 knowledge on mql5 or coding in general, those codes are scraps that I gathered from YT vids and some online short instructions on mql5.

Thanks for the pointer anyway!
Different/opposing ideas will make us learn and understand many things.
 
 
  • Post #6
  • Quote
  • Nov 22, 2020 2:36pm Nov 22, 2020 2:36pm
  •  ganztrade
  • Joined Oct 2020 | Status: Member | 334 Posts
Quoting Don_xyZ
Disliked
{quote} Yes, I have that indicator but it's for doing other things. I'm trying to get an alert before the MAs touch each other. I also have 0 knowledge on mql5 or coding in general, those codes are scraps that I gathered from YT vids and some online short instructions on mql5. Thanks for the pointer anyway!
Ignored

so do i, a month ago , have 0 knowledge mql4 code , now you ask mq5, hmmm maybe -20 knowledge
Margin Call again and again...
 
 
  • Post #7
  • Quote
  • Last Post: Nov 26, 2020 9:20am Nov 26, 2020 9:20am
  •  Don_xyZ
  • | Joined Dec 2010 | Status: Member | 67 Posts
I already have this thing working but I drop the "3 times" element as it is redundant and instead, I make the alert to ring only once per bar.

Here's the full code if anyone need it:

Inserted Code
void OnTick()
  {
   // create Array for prices
   double myMovingAverageArray1[], myMovingAverageArray2[];
      //define the properties of the Moving Average1
   int movingAverageDefinition1 = iMA (_Symbol,_Period,8,0,MODE_EMA,PRICE_CLOSE); 
   
   //define the properties of the Moving Average2
   int movingAverageDefinition2 = iMA (_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE); 
   //sort the price Array1 from the current candle downwards
   ArraySetAsSeries(myMovingAverageArray1,true);
   //sort the price Array2 from the current candle downwards
   ArraySetAsSeries(myMovingAverageArray2,true);
   
   
   //Defined MA1, one line, current candle, 3 candles, store result
   CopyBuffer(movingAverageDefinition1,0,0,3,myMovingAverageArray1);
   //Defined MA2, one line, current candle, 3 candles, store result
   CopyBuffer(movingAverageDefinition2,0,0,3,myMovingAverageArray2);
   
   if(IsNewCandle())
   
   {
   if ( //Potential Buy trade alert
      (myMovingAverageArray2[0] > myMovingAverageArray1[0])
   && (myMovingAverageArray2[0] - myMovingAverageArray1[0] <0.00010)
      )
   
   
   {
   PlaySound("Store_Door_Chime-Mike_Koenig-570742973.wav");
   }
;
   
  
   if ( //Potential Sell trade alert 
      (myMovingAverageArray1[0] > myMovingAverageArray2[0])
   && (myMovingAverageArray1[0] - myMovingAverageArray2[0] <0.00010)
      )
   
   
   {
   PlaySound("decay.wav");
   }
   }
  
  }
//+------------------------------------------------------------------+
   bool IsNewCandle()
   {
   static datetime saved_candle_time;
   if(iTime(_Symbol,_Period,0)==saved_candle_time)
      return false;
   else
      saved_candle_time=iTime(_Symbol,_Period,0);
   return true;
   }

The purpose of this code is to help notify you when the EMAs are getting close to each other. MA cross has its merits and downsides so I don't like using crossover EA because you need human judgement before entering a trade and this is the true purpose of this code. When the market is going fast and you rely on crossover you might miss the golden entry so this thing will put you on alert before it happens. So sorry, if my code is still very simple, I'm still trying to learn (still haven't finished the short coding course yet).

I hope it's useful.
Different/opposing ideas will make us learn and understand many things.
 
1
  • Platform Tech
  • /
  • Help! Trying to make alert to ring 3 times per candle
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023