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

 
Konstantin Seredkin:

I was just giving an example, there are a lot of other algorithms that would be good to have on this button, spread widened, the button was pressed, a text message came to my phone saying that the robot is stopped or there are 4 robots trading on the account, the 5th one controls the account margin, when the margin drops to the set value, we cut off auto-trading and all robots suck until I come and see what and where is going into a drawdown.But the removal of a robot from the chart is a cannon against a rabbit... The button is a complex solution that allows you to kill all the robots by a predetermined algorithm.

I've seen a solution for mql5 somewhere, but I can't find it.

That's what I said - it's a radical solution. The correct solution is to change the code of the Expert Advisor so that in the case of certain circumstances, it will not perform trading actions and everything connected with them. For example, spread control is elementary:

void OnTick()
{
    double fPoint = Point();
    if (fPoint <= 0.0)
      return;

    int nSpread = int(MathRound((Ask - Bid) / fPoint));
    if (nSpread > 50)
      return;

   ... Действия советника при нормальном спреде
}
 

Well, the AutoTrade button can be pressed/unpressed by emulating Ctrl+E. But, as I said, this is with the help of WinAPI:

#include <WinUser32.mqh>

#define  VK_CONTROL 0x11 
#define  KEY_CODE   'E'


void PressOrReleaseAutotrade()
{
   keybd_event(VK_CONTROL, 0, 0, 0);
   keybd_event(KEY_CODE, 0, 0, 0);
   keybd_event(KEY_CODE, 0, 2, 0);
   keybd_event(VK_CONTROL, 0, 2, 0);   
}
 
Ihor Herasko:

Well, the AutoTrade button can be pressed/unpressed by emulating Ctrl+E. But, as I said, this is already using WinAPI:

Thank you! And how can you make a smiley face sad?)

 
Ihor Herasko:

Well, the AutoTrade button can be pressed/unpressed by emulating Ctrl+E. But, as I said, this is with WinAPI:

Exactly, and I thought it's a painfully simple method and I forgot about this library. Thanks, now we can do what we want

 

Made MQL4 script (code below) that draws rectangles (pic below), but here's the problem. For dashed line STYLE_DOT only width 1 works, and with 2 or more a solid line is drawn. Can you tell me where my mistake is or is there something being hidden from us?

#property strict
void OnStart()
  {
//---
   RectCreate("rect1",Time[1],Low[1],Time[10],High[10],clrYellow,STYLE_DOT,  1,  false);
   RectCreate("rect2",Time[11],Low[11],Time[20],High[20],clrRed, STYLE_DOT,  2,  false);
//---
   Sleep(20*1000);
   ObjectsDeleteAll(0);
  }
//--- Function creates rectangle
void RectCreate(const string           f_name,     // rectangle name
                datetime               f_time1,    // first point time
                double                 f_price1,   // first point price
                datetime               f_time2,    // second point time
                double                 f_price2,   // second point price
                const color            f_color,    // rectangle color
                const ENUM_LINE_STYLE  f_style,    // style of rectangle lines
                const int              f_width,    // width of rectangle lines
                const bool             f_fill)     // filling rectangle with color

  {
   if(ObjectCreate(0,f_name,OBJ_RECTANGLE,0,f_time1,f_price1,f_time2,f_price2))
     {
      ObjectSetInteger(0,f_name,OBJPROP_COLOR,f_color);
      ObjectSetInteger(0,f_name,OBJPROP_STYLE,f_style);
      ObjectSetInteger(0,f_name,OBJPROP_WIDTH,f_width);
      ObjectSetInteger(0,f_name,OBJPROP_FILL,f_fill);
      ObjectSetInteger(0,f_name,OBJPROP_BACK,false);
      ObjectSetInteger(0,f_name,OBJPROP_SELECTABLE,false);
      ObjectSetInteger(0,f_name,OBJPROP_SELECTED,false);
     }
  }

 
Maxim Khrolenko:

Made MQL4 script (code below) that draws rectangles (pic below), but here's the problem. For dashed line STYLE_DOT only width 1 works, and with 2 or more a solid line is drawn. Can you tell me where my mistake is or is there something being hidden from us?

And manually draw and change the style and thickness tried? And what conclusion can be drawn from these experiments?
 
Artyom Trishkin:
Have you tried manually drawing and changing the style and thickness? And what conclusion can be drawn from these experiments?

I think I've found the answer. It says here that "Line style. It is only used when line thickness is 0 or 1". This must be the reason why lines of width 2 and more do not work with lines other than solid.

 
Maxim Khrolenko:

I think I've found the answer. It says here that "Line style. Only used when line thickness is 0 or 1". This must be the reason why lines other than solid lines don't work with a thickness of 2 or thicker.

Exactly right. I've been there too.

 

Gentlemen, please advise, I took a function from Kim which returns the bar number of the last position opened or -1.

int NumberOfBarOpenLastPos(string sym="",int tf=0,int op=-1,int mn=-1)
  {
   datetime oot;
   int      i,k=OrdersTotal();

   if(sym=="") sym=Symbol();
   for(i=0; i<k; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==sym)
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT)
              {
               if(op<0 || OrderType()==op)
                 {
                  if(mn<0 || OrderMagicNumber()==mn)
                    {
                     if(oot<OrderOpenTime()) oot=OrderOpenTime();
                    }
                 }
              }
           }
        }
     }
   return(iBarShift(sym, tf, oot, True));
  }

I call this function and write a condition

if(Open[2]>Close[2] && Open[1]>Close[1] && Close[1]<Low[2])
     {

      Comment("цена входа = ",DoubleToStr(Low[2],Digits));
      if(NumberOfBarOpenLastPos("",0,-1,-1)!=0)//вызвал здесь

         ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.1,Low[2],2,0,0,magic,0);
      if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

         TP=NormalizeDouble(OrderOpenPrice()-tp*Point,Digits);
      SL=NormalizeDouble(OrderOpenPrice()+sl*Point,Digits);
      modify=OrderModify(ticket,OrderOpenPrice(),SL,TP,0);
      }

I have looked through Print and see that this function return -1, at first I thought there was no order but after a while the order reappeared and on the same bar a deal was opened after the stop.

 
Good afternoon. Do you know if it is possible in MT4 and MT5 to overlay the charts of one instrument with different TF, as well as indicators for these TFs? For example, I want to display in one window 3 charts of EUR/USD pair with TFs: day, 4hour and hour, and also overlay the sliding indicators of these TFs. Is it possible? I am looking forward to any help.
Reason: