Questions from Beginners MQL5 MT5 MetaTrader 5 - page 748

 
RogozaIV:
I have recently moved from mql4 to mql5. I am testing an Expert Advisor on the RTS Index and have a problem with opening several positions, although one of the conditions for opening a position is if (...OrdersTotal()==0). Why does not this condition work? What can I do to open only one position?

OrdersTotal

OrdersTotal Returns the number of active orders.

PositionsTotal

PositionsTotal Returns the number of open positions.


Note

There should be no confusion between activepending orders and positions, which are also displayed in the "Trade" tab of the "Toolbox" panel. An order is an order to executea trade, while a position is the result of one or moretrades.

With "netting" of positions (ACCOUNT_MARGIN_MODE_RETAIL_NETTING andACCOUNT_MARGIN_MODE_EXCHANGE) only oneposition can be opened for eachsymbol at any time and it is the result of one or moredeals. Positions and activepending orders, which are also displayed in the "Trade" tab of the "Toolbox" panel, should not be confused with each other.

In case of independent representation of positions (ACCOUNT_MARGIN_MODE_RETAIL_HEDGING) several positions can be opened for each symbol simultaneously.


That is, usingOrdersTotal, you check how many RETAILED ORDERS there are at the moment:

ORDER_TYPE_BUY_LIMIT

Pending Buy Limit order

ORDER_TYPE_SELL_LIMIT

Pending Sell Limit order

ORDER_TYPE_BUY_STOP

Pending Buy Stop order

ORDER_TYPE_SELL_STOP

Pending Sell Stop order

ORDER_TYPE_BUY_STOP_LIMIT

When the order price is reached, a Buy Limit pending order is placed at StopLimit price

ORDER_TYPE_SELL_STOP_LIMIT

When the order price is reached, a pending Sell Limit order is placed at StopLimit price


and you need to check how many open positions there are at that moment:

POSITION_TYPE_BUY

Buy

POSITION_TYPE_SELL

Sell


- PositionsTotal should be used for this.

 

Vladimir Karputov Thank you!

 
Agat:
Good afternoon. After the latest MT5 update to build 1604 my indicators are no longer working correctly. I am using
So called "liquid" indicators. For example, I have several multi-period stochastics in one window. Well, now the short ones are drawn
As before, slightly longer ones draw only a few bars and the longest ones are not drawn at all.

I have the impression that they have suddenly started to lack history. Could you tell me what may be wrong?
It turns out that the glitch occurred in those MTs where the lower timeframes were not opened. I had to open charts from M1 and higher and everything was fine. The issue is now closed.
 
Yeah, you got excited too early, when you restart the terminal it's the same, you have to click through all the charts every time.
That's no good, it's impossible to work. Will someone at least say something on the merits of the issue or not? Obviously the update is glitchy.

Where do people go for such questions?
 
Hello! 2017.06.02_17:45 GMT+3. I have a question. The .mq5 program wrote its lot calculation, -- the result, -- the program in the strategy tester tries to open a trade with a prohibitively large lot. At risk percentage 1.09. The deposit size is larger than deposit (by default $10,000). I tried to use the standard OOP file from the folder Include>Expert>Money>MoneyFixedRisk.mqh . Result: The program tries to open a trade with zero lot. (0.00). I think -- it's a corporation programmers trick. Or am I missing something? Well, make your EA useless. Bend the lot on the side. Maybe, who knows what I should write, so that the Expert Advisor would open trades with the calculated lot, with the specified percentage of risk? I cannot do it myself, I am wasting my time. I hope the programmers of our corporation will not be offended. I am attaching the included file Lot.mqh . I hope that someone will answer. 18:00 GMT+3. Inserted at 18:11 GMT+3.
Files:
Lot.mqh  2 kb
 
Agat:
Good afternoon. After the latest MT5 update to build 1604 my indicators are no longer working correctly. I am using
So called "liquid" indicators. For example, I have several multi-period stochastics in one window. Well, now the short ones are drawn
As before, slightly longer ones draw only a few bars and the longest ones are not drawn at all.

I have the impression that they have suddenly started to lack history. Could you tell me what may be wrong?


How do you access the history of another period? What checks do you perform to get access? What error codes do you get?

 
Николай Никитюк:
Hello! 2017.06.02_17:45 GMT+3. I have a question. The .mq5 program wrote its lot calculation, -- the result, -- the program in the strategy tester tries to open a trade with a prohibitively large lot. At risk percentage 1.09. The deposit size is larger than deposit (by default $10,000). I tried to use the standard OOP file from the folder Include>Expert>Money>MoneyFixedRisk.mqh . Result: The program tries to open a trade with zero lot. (0.00). I think -- it's a corporation programmers trick. Or am I missing something? Well, make your EA useless. Bend the lot on the side. Maybe, who knows what I should write, so that the Expert Advisor would open trades with the calculated lot, with the specified percentage of risk? I cannot do it myself, I am wasting my time. I hope the programmers of our corporation will not be offended. I am attaching the included file Lot.mqh . I hope that someone will answer. 18:00 GMT+3. Inserted at 18:11 GMT+3.

Run this EA:Money Fixed Risk- change both input parameters and see the prints in the "Experts" tab of the terminal.
 

I can't get any indicator data in my indicator.

int OnInit()
  {  
   handle1=iMA(NULL,0,per1,0,MODE_LWMA,PRICE_CLOSE);
   handle2=iMA(NULL,0,PLength1,0,MODE_LWMA,PRICE_CLOSE);
  }
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[])
  {
   int copied1=CopyBuffer(handle1,0,0,toCount,TMP_Buf1);
   if(copied1<=0)
     {
      Sleep(50);
      for(int i=0;i<100;i++)
        {
         if(BarsCalculated(handle1)>0)
            break;
         Sleep(50);
        }
      copied1=CopyBuffer(handle1,0,0,toCount,TMP_Buf1);
      if(copied1<=0)
        {
         Print(__FUNCTION__+": copying indicator data failed. Error=",GetLastError());
         return(0);
        }
     }  
   int copied2=CopyBuffer(handle2,0,0,toCount,TMP_Buf2);
   if(copied2<=0)
     {
      Sleep(50);
      for(int i=0;i<100;i++)
        {
         if(BarsCalculated(handle2)>0)
            break;
         Sleep(50);
        }
      copied2=CopyBuffer(handle2,0,0,toCount,TMP_Buf2);
      if(copied2<=0)
        {
         Print(__FUNCTION__+": copying indicator data failed. Error=",GetLastError());
         return(0);
        }
     }
  }

Nothing is copied. Variables copied1/2 are always less than zero. In the debugger I can't get any further than this code. How to do it correctly, my head is already broken.

 
Hmm... before there was an error 4806, now it's 4807 when I moved the handle creation to OnInit(). How do you do that?
 
I think I've figured it out. The handle was not created. I didn't initialise all the data.
Reason: