Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 977

 
Alexey Viktorov:

It is advisable to start reading from the beginning for good advice. From where the first question was and the rest of the discussion.

 
Kamilzhan:

Well, for a complete answer it is enough to answer once, not four times


ALL, absolutely all coloured indicators, in MT4 are constructed so that if the current value is greater than the value on the previous bar, then one of the buffers is filled. If the current value is lower than the value on the previous bar, another buffer will be filled. And the type of display, line, histogram or asterisks/dots, does not matter...

 

There is a fully working EA that sends two screenshots of the chart to telegram, the first screenshot from the open window in the terminal, and the second from the same tool but with a different timeframe,

to do this a new window is opened,a template is applied, a screenshot is taken and the window is deleted. But this scheme with the second screenshot is not always stable.

I want to change it to not open a new window, and use the same all the time, but substituted the desired tool, help tweak it in the code.


//+------------------------------------------------------------------+
//|                                                          777.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#include <Telegram.mqh>
string Token="7417:AAH54X9HyFIbecqq1U1-R18tU";
int ChannelID=33722;
CCustomBot bot;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
struct TSignalInfo
  {
   string            symbol;
   ENUM_TIMEFRAMES   timeframe;
   datetime          time_last;
   //---   
   static datetime GetMinute()
     {
      MqlDateTime dt;
      TimeCurrent(dt);
      dt.sec=0;
      return(StructToTime(dt));
     }
  };
TSignalInfo signal[];
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
bool SignalIsAllowed(const string _symbol,
                     const ENUM_TIMEFRAMES _timeframe)
  {
//--- find
   int total=ArraySize(signal);
   for(int i=0;i<total;i++)
     {
      if(signal[i].symbol==_symbol && 
         signal[i].timeframe==_timeframe)
        {
         //Print("found");
         if(signal[i].time_last<TSignalInfo::GetMinute())
           {
            signal[i].time_last=TSignalInfo::GetMinute();
            return(true);
           }
         
         return(false);
        }
     }

//--- add
   ArrayResize(signal,total+1);
   signal[total].symbol=_symbol;
   signal[total].timeframe = _timeframe;
   signal[total].time_last = TSignalInfo::GetMinute();
   //Print("add");
   return(true);
  }
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   bot.Token(Token);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if(id==CHARTEVENT_CUSTOM+234)
     {
      if(!SignalIsAllowed(ChartSymbol(lparam),ChartPeriod(lparam)))
         return;
      //Print("Custom: ",lparam," ",dparam," ",sparam);   
      ChartScreenShot(lparam,"chart.gif");

      //--- первый скриншот
      string _photo_id;
      int err=bot.SendPhoto(_photo_id,ChannelID,"chart.gif",sparam);
      ChartSetSymbolPeriod(lparam,ChartSymbol(lparam),ChartPeriod(lparam));

      if(ChartPeriod(lparam)!=PERIOD_H4)
        {
         string _symbol=ChartSymbol(lparam);
         ChartScreenShot(_symbol,PERIOD_H4,"chart.gif","BollingerBands");
         string _photo_id2;
         int err2=bot.SendPhoto(_photo_id2,ChannelID,"chart.gif",sparam);
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ChartScreenShot(long chart_id,const string file_name)
  {
//--- создать скриншот
   const int chart_width=1280;
   const int chart_height=623;

   FileDelete(file_name);
//---
   if(ChartScreenShot(chart_id,file_name,chart_width,chart_height,ALIGN_RIGHT))
     {
      //---
      ChartRedraw(chart_id);
      Sleep(500);
      //--- waitng 30 sec for save screenshot
      int wait=30;
      while(!FileIsExist(file_name) && --wait>0)
        {
         printf("Waiting %d sec ...",wait);
         Sleep(1000);
         ChartRedraw(chart_id);
        }

      //--- check file
      if(!FileIsExist(file_name))
         printf("Failed to create a screenshot '%s'.",file_name);
     }
   else
     {
      Print("ChartScreenShot error ",_LastError);
      return(false);
     }
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ChartScreenShot(const string _symbol,
                     const ENUM_TIMEFRAMES _tf,
                     const string file_name,
                     const string _template)
  {

//---
   long chart_id=ChartOpen(_symbol,_tf);
   ChartRedraw(chart_id);
   Sleep(155);
//---     
   if(StringLen(_template)>0)
      if(!ChartApplyTemplate(chart_id,_template))
         Print("Apply Template error: ",_LastError);

//--- создать скриншот
   const int chart_width=1280;
   const int chart_height=623;

   FileDelete(file_name);
//---
   if(ChartScreenShot(chart_id,file_name,chart_width,chart_height,ALIGN_RIGHT))
     {
      //---
      ChartRedraw(chart_id);
      Sleep(500);

      //--- waitng 30 sec for save screenshot
      int wait=30;
      while(!FileIsExist(file_name) && --wait>0)
        {
         printf("Waiting %d sec ...",wait);
         Sleep(1000);
         ChartRedraw(chart_id);
        }

      //--- check file
      if(!FileIsExist(file_name))
         printf("Failed to create a screenshot '%s'.",file_name);
     }
   else
     {
      Print("ChartScreenShot error ",_LastError);
      ChartClose(chart_id);
      return(false);
     }

   ChartClose(chart_id);
   return(true);
  }
//+------------------------------------------------------------------+ 
 
Alexey Viktorov:

If the current value is higher than the previous value, then it's green and the buffer is different, in mql4, and if the opposite is true, then ... vice versa.))))

Thank you, it all makes sense.

 

Good day to all. I trade 50 instruments. I trade levels. I have set up my work with profiles to avoid opening 50 charts and loading the terminal. I want to write an assistant that will use levels I have drawn by hand on all symbols and give me a signal on the screen, like "Look at the Euro-dollar, something interesting is forming there". I suppose I should write a DLL, in which all levels of all symbols will be copied and the robot should be multicurrency.

Who has any idea how to implement this task?

How to pull the data from the profiles in the dll?

PS. Looked in the tool folders there are files with the extension "chr". Opened notepad and saw all the information I need. How can I use it in this way?

 
Good afternoon, I am a beginner and not good at programming, I need the Parabolic SAR indicator for MT5 to be displayed as a line, not dots, how can I do it? Please help me.
 
valeriikopp:
Good afternoon, I am a beginner and not good at programming, I need the Parabolic SAR indicator for MT5 to be displayed as a line, not dots, how can I do it? Please help me.

+

Files:
 

Hello, I'm trying to write a script that draws vertical lines on the whole chart after a series of 4 bars with increasing highs. The script ends up drawing only one line at the beginning and that's it. What is the error? Please help me to correct it.

void OnStart()
 {
double bbup0,
       bbup1,
       bbup2,
       bbup3;
       int a=0;
for(;a<Bars;a++)
{
bbup0=High[a];
bbup1=High[a+1];
bbup2=High[a+2];
bbup3=High[a+3];

if((bbup0<bbup1)&&(bbup1<bbup2)&&(bbup2<bbup3)) 
ObjectCreate(0,"Line",OBJ_VLINE,0,Time[a],0);
 } 
}
 
pvba:

Hello, I'm trying to write a script that draws vertical lines on the whole chart after a series of 4 bars with increasing highs. The script ends up drawing only one line at the beginning and that's it. What is the error? Please help me to correct it.

the name has to be original for each line

you have one name for all of them.

you can add the time of its creation to the name.

 
Iurii Tokman:

the name must be original for each line

you have one name for all of them

You can add the time of its creation to the name.

Thank you very much!

Reason: