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

 
Ivan Butko:

If you know what condition to add or how to implement (if it's easy), please share.

I can, but it's not interesting to check how it works, so here's an outline

void OnTick()
{  static int ticket = -1;
   while(!IsStopped() &&ticket<0)
   {  if(TerminalInfoInteger(TERMINAL_CONNECTED) && TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && !IsTradeContextBusy())
      {  
         RefreshRates();
         ticket = OrderSend("EURUSD", OP_SELL, 0.01, Bid, 3, 0, 0, "", 0, 0, clrRed);
         if(ticket > 0) break; 
      }
   Sleep(123); 
   }
}
 
Igor Makanu:

I can, but it's not interesting to check how it works, so I just sketched it out.

Igor, thank you. And no need to check, I'll do it myself, of course.

Is there any way to do it without waiting for a tick?

So that the request for opening went immediately when the "push" is pressed.

It is like a standard "buy/sell" button of quick opening of deals in the terminal (on the left-top of the chart). You press it and the sell opens instantly. All you need is to open a basket of orders instead of a single trade, without waiting for the tick.

There are two implementations (as I see it):
1) either a button (similar) on the chart that opens the basket,
2) or an Expert Advisor. The advisor seems more convenient to me, as it can repeat the request to open (if there are problems) faster than I can.



UPD

Your code works, opens on a new tick, cool, thanks)


UPD

I also remembered: copyers have parameter "ms", where you can set the check time. And if the master has an open deal, it can send a request for opening a deal from 1 ms slave. I.e., instant opening is feasible

 
Igor Makanu:

I can, but it's not interesting to check how it works, so here's a sketch

Igor, please check by eye, is this opening instantaneous, without waiting for a new tick?

int OnInit()

{

//---

static int ticket = -1;

while(!IsStopped() &&ticket<0)

{ if(TerminalInfoInteger(TERMINAL_CONNECTED) && TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && !IsTradeContextBusy())

{

RefreshRates();

ticket = OrderSend("EURUSD", OP_SELL, 0.01, Bid, 3, 0, 0, "", 0, 0, clrRed);

if(ticket > 0) break;

}

Sleep(1);

}

//---

return(INIT_SUCCEEDED);

}

------------------

And it seems to work as intended...
 
Ivan Butko:



Otherwise, it seems to work as intended...

not the best option.... then at least write it that way

#property strict
int ticket = -1;
int OnInit()
{  if(ticket < 0) SendMyOrder();
   return(INIT_SUCCEEDED); 
}
//+------------------------------------------------------------------+
void OnTick()
{
   if(ticket < 0) SendMyOrder();
}
//+------------------------------------------------------------------+
void SendMyOrder()
{  while(!IsStopped() && ticket < 0)
   {  if(TerminalInfoInteger(TERMINAL_CONNECTED) && TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && !IsTradeContextBusy())
      {  RefreshRates();
         ticket = OrderSend("EURUSD", OP_SELL, 0.01, Bid, 3, 0, 0, "", 0, 0, clrRed);
         if(ticket > 0) break; 
      }
      Sleep(123); 
   } 
}
//+------------------------------------------------------------------+

but the first option should work clearly if you have thrown on a chart and pressed the autotrade button when you consider it necessary to "standby".

If you want to make a trade, then you should write it that way:

void OnTick()
{
   if(ticket < 0) SendMyOrder();
   if(ticket > 0) ExpertRemove();
}
 
Igor Makanu:

not the best option.... then at least write it that way

but the first option should work clearly if you have thrown on a chart and pressed the autotrade button when you consider it necessary to "standby".

If you want to make a trade, then you should write it that way:

many thanks
 

Great! The testing of the variants continues. Vladimir and Igor's variant turned out to be quite fast. In practice, it turned out that trades opened faster when clicking the quick buy button than when using the Expert Advisor. Both variants have advantages and disadvantages. Another curious thing is that if we prescribe in the Expert Advisor which pairs to open one by one, they open one by one and very slowly... and if we set 7 Expert Advisors for each chart (more like no load), then on the contrary - all deals open instantly, NOT in sequence, without delays between orders (but there is still some gap of half a second or a second in the beginning).

I want to try the button on the chart, found the manual, but it only describes the coordinates and stuff. Please advise, where in the "button" script should I write the code to open deal? To click on it on the chart and the deal opened. As in the standard MT quick buy/sell button.

Or how to upgrade the Trade Panel to open a basket of orders?

 
Please help with this
Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
  • 2019.10.14
  • www.mql5.com
В этой ветке я хочу начать свою помощь тем, кто действительно хочет разобраться и научиться программированию на новом MQL4 и желает легко перейти н...
 
Ivan Butko:

I want to try the button on the chart, found the manual,

I did not look for the manual, but drew the button )))

#property copyright "IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#property strict
input string   sym1 = "EURUSD";
input string   sym2 = "GBPUSD";
input string   sym3 = "USDCAD";
input string   sym4 = "USDJPY";
input string   sym5 = "AUDUSD";
#include <Controls\Button.mqh>
CButton ButtonSend;

string sym[5];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   sym[0] = sym1;
   sym[1] = sym2;
   sym[2] = sym3;
   sym[3] = sym4;
   sym[4] = sym5;
   ButtonSend.Create(0, "ButtonSend" + _Symbol, 0, 10, 50, 100, 90);
   ButtonSend.Color(clrRed);
   ButtonSend.Text("Kill Forex!");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   static int ticket[5] = {-1, -1, -1, -1, -1 };
   if(ticket[0] > 0 && ticket[1] > 0 && ticket[2] > 0 && ticket[3] > 0 && ticket[4] > 0) return;
   if(ButtonSend.Pressed())
     {
      ButtonSend.Pressed(false);
      Print("Start OrderSend()");
      while(!IsStopped())
        {
         if(TerminalInfoInteger(TERMINAL_CONNECTED) && TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && !IsTradeContextBusy())
           {
            RefreshRates();
            for(int i = 0; i < 5; i++)
              {
               if(sym[i] == "") ticket[i] = INT_MAX;
               if(ticket[i] > 0) continue;
               ticket[i] = OrderSend(sym[i], OP_SELL, 0.01, SymbolInfoDouble(sym[i],SYMBOL_BID), 3, 0, 0, "", 0, 0, clrRed);
              }
           }
         if(ticket[0] > 0 && ticket[1] > 0 && ticket[2] > 0 && ticket[3] > 0 && ticket[4] > 0)  break;
         Sleep(123);
        }
     }
  }
//+------------------------------------------------------------------+

If the settings for the symbol will be "", then do not open 0.01 lot on this symbol, lot setting has not done, for as the topic about how to learn, not to look who will do, try to attach yourself if necessary ;)

 
Igor Makanu:

I did not look for a manual, but drew the button ))))

if the symbol is set to "", then do not open 0.01 lot for this symbol, lot setting has not done, for as the topic about how to learn, not to look who will do, try to attach yourself if necessary ;)

Thank you very much, Igor! Quick and to the point!

will try

 
Igor Makanu:

Strange, if in one EA, it opens trades one after the other on each specified currency pair... with a time lag. And when you put it on 5 different charts with different currency pair (symbol(0)), all 5 trades open simultaneously and instantly when you press autotrade.

Can you suggest what it may be and how to fix it? To have everything in one EA and on one chart (so that the button on the chart opens all pairs as fast as when activating "autotrade" with several EAs, as in the original version)

Reason: