[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 243

 
DimaMA:
I made a virtual trawl with horizontal lines, it works fine in the tester, but during optimization the tester probably doesn't work with these lines, why? and how to fix it?

Why do you need a horizontal line? Store the value of the line in a variable and you'll be happy!!! And the Expert Advisor will "think" faster! And you can leave the horizontal line just for visual effect.

And the reason is as follows: the tester works with graphical objects only in visual mode! When optimizing, there is no visual mode at all... Although, you can try to leave the chart with "visual" in brackets after the name of TF and pair... But I do not know if it will help or not. I have not checked it. I thought it would help, because we can see orders appearing and disappearing on this chart (that was used for visualization testing before) (even though the chart has not been activated yet)... Maybe Someone will tell us!

My advice to you - do not use extraction of parameters from graphical objects. Let these parameters be stored in variables... Don't make the graphical object a variable! :))))

 
MaxZ:

Hello.

Question: can OrderSend() return a value of "0", or less than "-1" after execution? Has anyone encountered anything like this? Or is the information given in the "documentation" correct:

P.S.: working as a telepath, looking for an error in someone else's code...

Hai!

Why not? If an order is not opened due to a requote, for example.

For this there is a loop for the real opening of orders, for example, such as this - the number of attempts to open with error handling:

int NumberOfTry = 25;
//+------------------------------------------------------------------+
//| Установка ордера                                                 |
//+------------------------------------------------------------------+

void WmOrderSend(string symbol, int cmd, double volume, double price, double stoploss, double takeprofit, string comment, int magic, datetime expiration = 0)
{
   color clr;
   datetime opentime;
   int ticket;
   int error;
  
   comment = WindowExpertName() + " " + GetNameTF(Period()) + " " + comment;
   int msl = MarketInfo(symbol, MODE_STOPLEVEL);
   clr = CLR_NONE;
   if (cmd == OP_BUY)  clr = ColorBuy;
   else if (cmd == OP_SELL)  clr = ColorSell;   
   if ((expiration > 0) && (expiration < TimeCurrent()))   expiration = 0;
  
   for (int try = 1; try <= NumberOfTry; try++)
   {
      if (!IsTesting() && (!IsExpertEnabled() || IsStopped()))      break;   
      while (!IsTradeAllowed())      Sleep(5000);
    
      RefreshRates();
      opentime = TimeCurrent();
      ticket = OrderSend(symbol, cmd, volume, price, SlipPips, stoploss, takeprofit, comment, magic, expiration, clr);
      if (ticket > 0)
         if (UseSound)      {PlaySound("ok.wav"); break;}      
      else
      {
         error = GetLastError();
         if (error == ERR_TRADE_TIMEOUT)
         {
            Sleep(1000*66);
            if (ExistOrders(symbol, cmd, magic, opentime))
            {
               if (UseSound) {PlaySound("ok.wav"); break;}
            }
         }
        
         Print("Error(", error, ") set order: ", ErrorDescription(error), ", try ", try);
         continue;
      }
      
      Print("Error(", error, ") set order: ", ErrorDescription(error), ", try ", try);
      Print("Ask=", Ask, "  Bid=", Bid, "  symbol=", symbol, "  volume=", volume, "  cmd=", GetNameOP(cmd), "  price=", price, "  stoploss=", stoploss, "  takeprofit=", stoploss, "  magic=", magic);
      if ((error == ERR_COMMON_ERROR) || (error == ERR_ACCOUNT_DISABLED) || (error == ERR_INVALID_ACCOUNT) || (error == ERR_TRADE_DISABLED))
        {
         IsExpertFailed = true;
         break;
        }      
      if ((error == ERR_SERVER_BUSY) || (ERR_INVALID_TRADE_VOLUME) || (error == ERR_MARKET_CLOSED))
        {
         Sleep(1000*300); 
         break;
        }      
      if ((error == ERR_TOO_FREQUENT_REQUESTS) || (error == ERR_TOO_MANY_REQUESTS))    Sleep(1000*100);      
      if ((error == ERR_ORDER_LOCKED) || (error == ERR_LONG_POSITIONS_ONLY_ALLOWED) || (error == ERR_TRADE_TOO_MANY_ORDERS))      break;      
      if (error == ERR_TRADE_CONTEXT_BUSY) while (IsTradeContextBusy()) Sleep(1000*11);
      
      if (error == ERR_TRADE_EXPIRATION_DENIED )  {expiration = 0; continue;}      
      if ((error != ERR_PRICE_CHANGED) && (error != ERR_REQUOTE))  Sleep(1000*7.7);
   }      
}
 
Roman.:

Hai!

Well, why not? If, for example, an order is not open on a requote...

Hi Roman.

Because usually the OrderSend() function returns "-1" on error... Not "0" and certainly not less than "-1". But still, maybe Someone had precedents?

 
MaxZ:

Hi Roman.

Because usually OrderSend() returns "-1" on error... Not "0" and certainly not less than "-1". But still, maybe Someone had precedents?

By the way, it's an interesting topic about errors. I learned that if 0 (zero) is returned, there is no error and the order is accepted by the broker. If not accepted, then an error is returned, but which is greater than zero. In the description of operator OrderSend() there is a record "...or -1 in case of failure". But what type of error should there be for the broker to return -1? Does anyone know?
 
MaxZ:

Hi Roman.

Because usually OrderSend() returns "-1" on error... Not "0" and certainly not less than "-1". But still, maybe Someone had precedents?


One would have to trade in a CONCRETE kitchen if the Ordersend() returns "0", much less < -1. :-)
 
paladin80:
By the way, interesting topic about errors. I learned that if 0 (zero) is returned, there is no error and the order is accepted by the broker. If not accepted, then an error is returned, but which is greater than zero.
Does the GetLastError() function return 0? Or you're writing about OrderSend() function?


paladin80:
In the description of the OrderSend() operator there is a note "...or -1 in case of failure". But what type of error should there be for the broker to return -1? Does anyone know?

OrderSend() returns "-1". And the error type should be checked with function GetLastError()! Don't confuse the two... There is an error code "1" which means "No error, but result unknown"... I haven't encountered an error with code "-1" and I don't think there is one! :D

 
MaxZ:
Does the GetLastError() function return 0? Or are you writing about OrderSend() function?


OrderSend() returns "-1". And the error type should be checked with GetLastError()!!! Don't confuse the two... There is an error code "1", which means "No error, but result unknown"... I haven't seen an error with code "-1" and I don't think there is one! :D


Maybe i really could have got it wrong. Once again I carefully read about OrderSend and errors. Probably, the point is that if the broker accepted the order, it returns the ticket's number and GetLastError of this operation will show 0. If it didn't, it will show -1 and GetLasError will show the error number greater than zero.
 

Good afternoon. Can you please tell me where I can get period_converter with a function that allows me to set the reference point. For example, I need to make a chart D2 of D1, when I start YYY.MMM.DDD HH.MM and from this date it starts converting candlesticks.

I have found something similar (even on this forum), but for some reason does not want to start converting from even numbers (starts with odd and all) may tell me what to change in code or change it yourself. I would be very grateful. Here's what I found.

Files:
 
Good day! Can I switch the timeframe from the indicator? Can the timeframe be switched on the platform in the window?
 

Dear All

I am new to forex and am new to forex, i would like to ask for some advice from the local gurus.

I am working with MT4 terminal.

When working with a chart for a currency pair it's convenient to switch the scale: "М1", "М5", .....

So, on M1 it displays the history for the last 38 hours as about 2000 candlesticks, while on M5 it is 270 hours but also about 2000 candlesticks.

In the first case the timeframe for a candle will be 60s, and in the second case it will be 470s. Can we pull the history for 270 hours (or more) with 60sec candlesticks?

Thanks in advance

Reason: