In this video, we are going to create an expert advisor that calculates the historical profit for a specific currency pair and displays it on the chart. Let’s see how we can do that. To begin, start the MetaEditor by clicking on the little icon or pressing F4 on your keyboard. The code starts by including the Trade.mqh library, which provides functions and methods for performing trade operations. We then create an instance of the CTrade class called trade to execute trade operations like buying and selling. Inside the OnTick function, we calculate the current Ask and Bid prices for the symbol. These prices are essential for executing buy and sell orders. The code checks if there are less than two open positions. If true, it executes both a buy and a sell order. This is just for demonstration purposes. The historical profit for the currency pair is calculated using the GetCurrencyPairHistoryProfit function and then displayed on the chart. The GetCurrencyPairHistoryProfit function calculates the total historical profit for the specific currency pair. Several variables are initialized to store information like the total number of deals, ticket numbers, order types, and profits. The HistorySelect function is used to fetch historical deal data. A for loop iterates through all the historical deals. For each deal, the profit and swap for the deal are obtained, the type of order (buy or sell) is determined, and the currency pair for the deal is checked to ensure it matches the current symbol. Once you’ve written the code, press F7 to compile it. 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. After compiling, go back to MetaTrader by pressing F4 or clicking on the icon. In MetaTrader, 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. You should then see the expert advisor on the chart. If you’re already a premium course member and have an idea for a video like this one, please send us an email. In conclusion, you’ve now learned how to calculate and display the historical profit for a specific currency pair using MQL5. With just a few lines of MQL code, you’ve created a functional expert advisor. Thanks for watching, and I’ll see you in the next video! Not sure what to do? Click on the automated trading assistant below MQL5 Tutorial - Advanced Library Expert Advisor MQL5 TUTORIAL - SIMPLE SAR STOCHASTIC STANDALONE EXPERT… MQL5 TUTORIAL BASICS 97 - SIMPLE REVERSE POSITION MQL5 TUTORIAL BASICS - 118 SIMPLE LAST ORDER TYPE MQL5 Tutorial: How to get the Order History Profit The post MQL5 TUTORIAL – HOW TO CALCULATE THE HISTORY PROFIT appeared first on MQL5 Tutorial.
In this video, we are going to create an expert advisor that calculates the historical profit for a specific currency pair and displays it on the chart. Let’s see how we can do that. To begin, start the MetaEditor by clicking on the little icon or pressing F4 on your keyboard. The code starts by including the Trade.mqh library, which provides functions and methods for performing trade operations. We then create an instance of the CTrade class called trade to execute trade operations like buying and selling. Inside the OnTick function, we calculate the current Ask and Bid prices for the symbol. These prices are essential for executing buy and sell orders. The code checks if there are less than two open positions. If true, it executes both a buy and a sell order. This is just for demonstration purposes. The historical profit for the currency pair is calculated using the GetCurrencyPairHistoryProfit function and then displayed on the chart. The GetCurrencyPairHistoryProfit function calculates the total historical profit for the specific currency pair. Several variables are initialized to store information like the total number of deals, ticket numbers, order types, and profits. The HistorySelect function is used to fetch historical deal data. A for loop iterates through all the historical deals. For each deal, the profit and swap for the deal are obtained, the type of order (buy or sell) is determined, and the currency pair for the deal is checked to ensure it matches the current symbol. Once you’ve written the code, press F7 to compile it. 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. After compiling, go back to MetaTrader by pressing F4 or clicking on the icon. In MetaTrader, 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. You should then see the expert advisor on the chart. If you’re already a premium course member and have an idea for a video like this one, please send us an email. In conclusion, you’ve now learned how to calculate and display the historical profit for a specific currency pair using MQL5. With just a few lines of MQL code, you’ve created a functional expert advisor. Thanks for watching, and I’ll see you in the next video!
In this video, we are going to create an expert advisor that calculates the historical profit for a specific currency pair and displays it on the chart. Let’s see how we can do that. To begin, start the MetaEditor by clicking on the little icon or pressing F4 on your keyboard. The code starts by including the Trade.mqh library, which provides functions and methods for performing trade operations.
We then create an instance of the CTrade class called trade to execute trade operations like buying and selling. Inside the OnTick function, we calculate the current Ask and Bid prices for the symbol. These prices are essential for executing buy and sell orders. The code checks if there are less than two open positions. If true, it executes both a buy and a sell order.
This is just for demonstration purposes. The historical profit for the currency pair is calculated using the GetCurrencyPairHistoryProfit function and then displayed on the chart. The GetCurrencyPairHistoryProfit function calculates the total historical profit for the specific currency pair. Several variables are initialized to store information like the total number of deals, ticket numbers, order types, and profits. The HistorySelect function is used to fetch historical deal data. A for loop iterates through all the historical deals.
For each deal, the profit and swap for the deal are obtained, the type of order (buy or sell) is determined, and the currency pair for the deal is checked to ensure it matches the current symbol. Once you’ve written the code, press F7 to compile it. 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. After compiling, go back to MetaTrader by pressing F4 or clicking on the icon. In MetaTrader, 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. You should then see the expert advisor on the chart. If you’re already a premium course member and have an idea for a video like this one, please send us an email. In conclusion, you’ve now learned how to calculate and display the historical profit for a specific currency pair using MQL5. With just a few lines of MQL code, you’ve created a functional expert advisor. Thanks for watching, and I’ll see you in the next video!
Not sure what to do? Click on the automated trading assistant belowThe post MQL5 TUTORIAL – HOW TO CALCULATE THE HISTORY PROFIT appeared first on MQL5 Tutorial.