MT5 Indicator problem : How to only call Telgram message sending function on detecting latest condition only (Also not while getting tested in strategy tester)?

 

Hi everyone,

I have built an indicator in MT5 (MQL5)  which detects a condition and draws it out on chart for me to take a trade manually. I am planning to write a telegram message sending function too, which is  supposed to send a message to telegram (to me) on detecting that condition (which i will use to potentially take a trade). However I am unsure how to call that function via the indicator while making sure it only sends the message for condition just detected on LIVE chart only and not for historically detected conditions. My code is below :


int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]){


   if(prev_calculated>rates_total || prev_calculated<=0)
     {
      
      copyBars = rates_total;
      startBar = 25;
       CleanChart();
     }
   else
     {
      copyBars = rates_total - prev_calculated;
      if(prev_calculated>0)
         copyBars++;
      startBar = prev_calculated - 1;
     }

   if(IsStopped())
      return(0);     
  
   for(int i = startBar; i<rates_total-1 && !IsStopped(); i++)
     {

        if(checkCondition(i,OtherParameters)){
                        drawSomethingOnChart();
                        if(i==(rates_total-2)){ // Unsure about this part
                                sendTelegramMessage();
                        }
                }
        }
 return(rates_total);
}
        

What i want is for this indicator to only send a telegram message when it has detected a newly developed condition on Live chart. It should not send telegram message  for the previously occured conditions in the chart. This is so that I will not be flooded with messages on Telegram about historical conditions which i will not take any action on. 

Also I don't want to be sent a message on testing this indicator in strategy tester.

In the above code I thought of using  :

if(i==(rates_total-2)){}

statement for this purpose, but i am inexperienced, so I am not sure if this is the correct way. There may be a better way of doing this that i am not aware of.

Also, I don't want it to be triggered by strategy tester but not sure how to enforce that in code.

Can anyone provide any guidance.

Much appreciated!

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
Reason: