У нас вы можете посмотреть бесплатно MQL5 TUTORIAL - SMA Buy Trailing Stop explained или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
https://mql5tutorial.com/?s=trailing+... In this video, we are going to create an Expert Advisor that utilizes a simple moving average for trailing stop management. Let's see how we can do that. We start Metaeditor by clicking a little icon or pressing F4. The code begins with including the Trade library using the #include directive, which provides functions for trading operations. We then create an instance of the CTrade class, which allows us to execute trade operations. Inside the OnTick function, we declare a static variable called LastStopMovingAverageValue to hold the last calculated moving average value. We calculate the Ask price using the NormalizeDouble function with parameters SymbolInfoDouble for the symbol and SYMBOL_ASK for the price type, ensuring that the price is formatted correctly according to the number of decimal places for the symbol. Similarly, we calculate the Bid price using NormalizeDouble with SYMBOL_BID. Next, we check if there are no open positions using the PositionsTotal function. If there are no positions, we execute a buy order for 10 Micro Lots, which is equivalent to 0.10 Lots. The parameters for the Buy function include the lot size of 0.10, a NULL value for the order comment, the Ask price for the entry price, a NULL value for the expiration, and a calculated take profit price, which is set 150 points above the Ask price. After placing the order, we reset the LastStopMovingAverageValue to zero. We then create an array called myMovingAverageArray to store the moving average values. We use the ArraySetAsSeries function to sort the array from the current candle downwards. The moving average is defined using the iMA function, which calculates the moving average based on the specified parameters: the symbol, the period, the number of periods for the moving average, the shift, the type of moving average, and the price type. The parameters for iMA include _Symbol for the symbol, _Period for the time frame, 500 for the number of periods, 0 for the shift, MODE_SMA for the type of moving average, and PRICE_CLOSE for the price type. We copy the moving average values into our array using the CopyBuffer function, which retrieves the moving average values for the current candle and the previous two candles. We then calculate the StopMovingAverageValue for candle 1. Next, we check if the StopMovingAverageValue is below the Bid price. If it is, we then check if it is greater than the LastStopMovingAverageValue. If both conditions are met, we call the CheckSMABuyTrailingStop function, passing in the Ask price and the StopMovingAverageValue. We also update the LastStopMovingAverageValue to the current StopMovingAverageValue. Inside the CheckSMABuyTrailingStop function, we loop through all open positions using a for loop. For each position, we retrieve the symbol of the position using PositionGetSymbol. If the symbol matches the current symbol, we get the ticket number of the position using PositionGetInteger with POSITION_TICKET and calculate the current stop loss using PositionGetDouble with POSITION_SL. We then check if the current stop loss is below the StopMovingAverageValue. If it is, we modify the position's stop loss to the StopMovingAverageValue using the PositionModify function, which takes the position ticket and the new stop loss value as parameters. Finally, we press F7 to compile the code.