У нас вы можете посмотреть бесплатно MQL5 TUTORIAL - Buy Position Count Explained (in 5 min) или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
https://mql5tutorial.com/?s=count In this video, we are going to create an Expert Advisor that opens random test positions and counts the number of buy positions. Let's see how we can do that. We start Metaeditor by clicking a little icon or pressing F4. First, we import the trade functions by including Trade/Trade.mqh. This allows us to use the trading functionalities provided by MQL5. Next, we create an instance of the CTrade class named trade. This instance will be used to execute trade operations. In the OnInit function, we call the OpenTestPositions function to open some test positions when the Expert Advisor is initialized. In the OnTick function, we display a comment on the chart showing the number of buy positions. This is done by calling the CountBuyPositions function and displaying its return value. The CountBuyPositions function initializes a local variable named NumberOfBuyPositions to zero. This variable will store the count of buy positions. We then loop through all the positions using a for loop that starts from the total number of positions minus one and decrements to zero. For each position, we get the currency pair using the PositionGetSymbol function and store it in the CurrencyPair variable. Next, we get the position type using the PositionGetInteger function with the POSITION_TYPE parameter and store it in the PositionDirection variable. If the symbol on the chart matches the position symbol and the position type is a buy position (indicated by POSITION_TYPE_BUY), we increment the NumberOfBuyPositions variable by one. After the loop ends, we return the NumberOfBuyPositions value to the main function. The OpenTestPositions function initializes the random number generator using MathSrand with the current tick count. This ensures that the random numbers generated are different each time the function is called. We then calculate a random number of test positions using MathRand modulo 10 and store it in the NumberOfTestPositions variable. Next, we calculate the Ask price using SymbolInfoDouble with the SYMBOL_ASK parameter and normalize it to the number of digits specified by _Digits. Similarly, we calculate the Bid price using SymbolInfoDouble with the SYMBOL_BID parameter and normalize it. We then open the calculated random number of test positions using a for loop. Inside the loop, we open a buy position of 0.10 lots (10 Micro Lots) without a stop loss using the trade.Buy function. The parameters for the trade.Buy function are the position size (0.10 lots), the symbol (NULL), the Ask price, the stop loss (0), the take profit (Ask + 300 * _Point), and the comment (NULL). Similarly, we open a sell position of 0.10 lots (10 Micro Lots) without a stop loss using the trade.Sell function. The parameters for the trade.Sell function are the position size (0.10 lots), the symbol (NULL), the Bid price, the stop loss (0), the take profit (Bid - 300 * _Point), and the comment (NULL). At the end, we press F7 to compile the code. If this was too fast for you or if you don't understand what all the code is doing, you may want to check out the Premium course on our website, or watch one of the basic videos first. If the compilation works, we go back to Metatrader by pressing F4 or clicking on the icon. Back in Metatrader, we press Control and R to start the strategy tester, pick the Expert Advisor that we have just created, enable the visual mode, and start a strategy test. We should see the Expert Advisor on the chart. If you are already a Premium course member and have an idea for a video like this one, you can send us an email. In this video, we have learned how to create an Expert Advisor that opens random test positions and counts the number of buy positions with a few lines of MQL code. Thanks for watching and I will see you in the next video.