AI Trading Tutorial - MQL5 Ichimoku WithTrailingStops

Votre vidéo commence dans 10
Passer (5)
cash machine v4

Merci ! Partagez avec vos amis !

Vous avez aimé cette vidéo, merci de votre vote !

Ajoutées by
15 Vues
https://mql5tutorial.com/?s=ichimoku

In this video, we are going to create an Expert Advisor that utilizes the Ichimoku Cloud indicator for trading decisions. Let's see how we can do that.
We start Metaeditor by clicking a little icon or pressing F4. The first thing we do in our code is include the CTrade class from the standard library. This class provides simplified trading methods such as PositionOpen and PositionModify, which are essential for managing our trades.
Next, we instantiate a CTrade object named Trade. This object will manage all trade operations, including position management, throughout the Expert Advisor.
We then define our strategy configuration parameters. These parameters are adjustable in the EA properties. The LookbackBars parameter is set to 50, which indicates the historical range for analysis, allowing us to analyze between one and one thousand candles. The MinCandlesBack parameter is set to five, which specifies the minimum age for a valid high or low, ranging from five to fifty candles. The TrailingOffset parameter is set to 10.0, which provides a safety margin for the trailing stop in points, with a range from one to twenty.
We also define parameters specific to the Ichimoku Cloud indicator. The TenkanSen parameter is set to nine, which represents the period for the Tenkan-sen or conversion line. The KijunSen parameter is set to twenty-six, representing the period for the Kijun-sen or base line. The SenkouSpanB parameter is set to fifty-two, which indicates the period for the second leading span. The Displacement parameter is set to twenty-six, which is the offset for the cloud. Lastly, we have a boolean parameter UseChikouSpan set to true, which indicates whether to use the Chikou Span for additional confirmation.
Moving on, we declare global variables and handles to store the state between ticks and indicator data. We create an integer variable ichimokuHandle to hold the iIchimoku indicator handle, and an array of MqlRates named priceData to store the open, high, low, and close price data.
The Expert Initialization Function, OnInit, is executed once at the start of the EA for indicator setup. In this function, we create the iIchimoku indicator handle using the iIchimoku function with the correct parameter count. We pass in the symbol, the timeframe set to H1, and the parameters for TenkanSen, KijunSen, and SenkouSpanB. We also configure the price data array as a time series using the ArraySetAsSeries function, which allows us to access the most recent price data easily.
Next, we define the Position Opening Functions, which are responsible for executing market orders with the specified lot size. The OpenBuyPosition function retrieves the current ask price using the SymbolInfoDouble function with the SYMBOL ASK parameter. It then executes a buy order using the PositionOpen method of the Trade object. The parameters for this method include the symbol, order type set to ORDER TYPE BUY, volume set to 0.10, the entry price at the current ask, and both the initial stop loss and take profit set to zero, indicating they are disabled. A comment is added to the position stating iIchimoku Position.
Similarly, the OpenSellPosition function retrieves the current bid price using the SymbolInfoDouble function with the SYMBOL BID parameter. It executes a sell order using the PositionOpen method of the Trade object with similar parameters, but the order type is set to ORDER TYPE SELL.
The main price update function, OnTick, is executed on every tick and contains the core strategy logic. In this function, we first retrieve historical price data for analysis using the CopyRates function. We specify the symbol, the timeframe set to H1, the starting position set to zero, and the number of bars to copy, which is the sum of LookbackBars and Displacement. The price data is stored in the priceData array.
Next, we load the Ichimoku values from the indicator buffers into separate arrays for the Tenkan-sen, Kijun-sen, Senkou Span A, Senkou Span B, and Chikou Span. We configure these arrays as time series using the ArraySetAsSeries function and copy the indicator data to these arrays using the CopyBuffer function.
We then check the status of open positions. A boolean variable named hasOpenPosition is initialized to false, and an ENUM POSITION TYPE variable named currentPositionType is set to POSITION TYPE BUY. We scan through all open positions to find relevant ones using a for loop that iterates from the total number of positions down to zero. If a position is selected by ticket and matches the current symbol, we set hasOpenPosition to true and update currentPositionType with the type of the position.
Next, we define our trading signals. A buy signal is generated when the Tenkan-sen crosses above the Kijun-sen, while a sell signal is generated when the Tenkan-sen crosses below the Kijun-sen.
Catégories
E commerce Divers
Mots-clés
yt:cc=on

Ajouter un commentaire

Connectez-vous ou inscrivez-vous pour poster un commentaire.

Commentaires

Soyez le premier à commenter cette vidéo.