Something Interesting in Financial Video - page 30

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:36

Templates MetaTrader 5 live trading using Python - part 1: import broker's data



Templates MetaTrader 5 live trading using Python - part 1: import broker's data

In this video, Lucas demonstrates how to use Python and MetaTrader 5 to import a broker's data by extracting candle data and transforming it into a readable data frame format. He notes that the MetaTrader 5 platform only works on Windows devices and not on Mac systems without additional applications. He creates a function called "get_rate" that allows for easy automation by changing its parameters, and by using the set index function, he sets the time column as the index of the data frame, allowing historical data to be imported to Python.

  • 00:00:00 In this section, Lucas from Control demonstrates how to import broker's data using Python and MetaTrader 5. First, he imports necessary libraries including MetaTrader 5, pandas, numpy, and datetime. Then, he connects the Python sheet to the MetaTrader 5 platform using the initialize function of mt5. Lucas shows how to extract candle data, including open, high, low, close, and volume, using the copy rates from function, and transforms the extracted data into a readable data frame format. Lucas notes that the MetaTrader 5 platform only works on Windows and not on Mac devices without additional applications such as parallel desktop or VPS.

  • 00:05:00 In this section, the video introduces how to import data from your broker using the MetaTrader5 platform to Python. The code is used to create a function called "get_rate" and the function takes "symbol" and "number of data" as input. The function makes it easy to change its parameters, such as selecting the time frame, and allows for easy automation of the process. By using the set index function and setting the time column as the index of the data frame, the historical data can be imported to Python.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:37

Templates MetaTrader 5 live trading using Python - part 2: Place order on MetaTrader 5 using Python



Templates MetaTrader 5 live trading using Python - part 2: Place order on MetaTrader 5 using Python

Lucas from explains the process of sending orders on MetaTrader 5 using Python. This involves initializing the symbol and deviation in pip, choosing the filling mode, creating a request to be sent to MetaTrader 5, specifying the action wanted, and executing the orders. He emphasizes the importance of extracting all necessary information like position ID into variables, as they would not be available after the Python sheet is shut down. The video also details the process involved in closing an open position for which a similar but reverse code of buying and selling orders needs to be applied while using the bid price instead of the ask price.

  • 00:00:00 In this section, Lucas explains how to send orders on MetaTrader 5 using Python, which can be very useful for creating trading bots. Before starting on the code, however, it is vital to activate algorithmic trading on the MetaTrader 5 platform by first allowing it under 'Expert Adviser' in the 'Tools' option. Then, users can start by initializing the symbol and deviation in pip. After choosing the filling mode, which is crucial for creating a robust trading algorithm, users can create a request to send to MT5, specify the action they want, and use the order send function to execute the orders.

  • 00:05:00 In this section, the speaker demonstrates how to close an open position on MetaTrader5 using Python. To close a position, the same code used to open would be applied, but with the buying and selling orders reversed and the bid price used instead of the ask price. The speaker emphasizes the importance of extracting all relevant information, including the position ID, into variables as they will not be available in memory after the Python sheet is shut down. The determination of the filling mode is also discussed, with the speaker highlighting the need to search for each asset's filling mode as it can vary depending on the broker and asset.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:38

Templates MetaTrader 5 live trading using Python - part 3: Money management with MetaTrader 5/Python



Templates MetaTrader 5 live trading using Python - part 3: Money management with MetaTrader 5 / Python

Lucas demonstrates how to use MetaTrader5 and Python to create a money management function that places a take profit and stop loss order in a request. The function considers risk management to determine optimal values for stop loss and take profit. He shows how to use a function called "tradeSize" to adjust risk for a long position in EUR/USD and determine the best volume based on account capital and leverage. Lucas emphasizes the importance of being careful in adjusting the volume of orders to maintain appropriate risk exposure.

  • 00:00:00 In this section, Lucas shows how to create a money management function using MetaTrader5 and Python. He demonstrates how to place a take profit and stop loss in a request order and explains how to find optimal values for the stop loss and take profit depending on risk management. Lucas also introduces a risk reward threshold function that takes the symbol, position type, and risk and reward levels, which helps in finding the optimal take profit and stop loss. The function extracts leverage and price to find the number of decimal places, computes variation in percentage discounted by leverage, and finally rounds the price to the number of decimal places of the asset.

  • 00:05:00 In this section, the speaker explains how to use a function for money management in MetaTrader 5 when trading using Python. The speaker demonstrates how to adjust the risk of a long position in EUR/USD depending on the leverage and how to find the best volume to take based on the capital and leverage of the account. The function named "tradeSize" can be found in the description of the MetaTrader 5 tutorial that the speaker mentions. The speaker also highlights the importance of adjusting the volume of the orders to be placed carefully to ensure that the risk exposure is appropriate.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:39

Templates MetaTrader 5 live trading using Python - part 4: Trading signal creation



Templates MetaTrader 5 live trading using Python - part 4: Trading signal creation

The YouTuber demonstrated the creation of a trading signal using MetaTrader 5 and Python by initializing the connection between the two platforms, creating a class "mt5" that is used to put the strategy into live trading, and importing data using the "get rates" function. They then went on to create a basic 30 and 60-day SMA signal using the rolling function and based the buy and sell conditions on the fast-moving average being above or below the slow-moving average. This process showcased a simple way to create a trading signal for live trading using MetaTrader 5 and Python.


 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:39

Templates MetaTrader 5 live trading using Python - part 5: Live trading template (MetaTrader 5/Python)



Templates MetaTrader 5 live trading using Python - part 5: Live trading template (MetaTrader5/Python)

The "Templates MetaTrader 5 live trading using Python - part 5:Live trading template (MetaTrader5/Python)" video demonstrates how to use the live trading template to execute a trading strategy. Users can select a specific time to run the algorithm and choose a symbol list with a default strategy of a random signal. Orders can be placed using the template, and users can change the random signal. The video cautions that stop loss and take profit percentages do not account for the spread and advises using a time slip of one second to avoid processing multiple signals within the same second. Viewers are invited to like and subscribe to the channel and join the Discord community.

  • 00:00:00 We go ahead and execute the trading strategy. It's important to choose the time metric carefully so that you don't end up opening and closing too many positions too quickly and losing money on transactions. This particular template allows users to choose a specific time to run the algorithm and select the symbol list, with a default strategy of a random signal. Overall, this is a great introduction to putting your trading strategy into live trading using MetaTrader 5 and Python.

  • 00:05:00 In this section of the video, the presenter demonstrates how to place orders using the live trading template. The template has a random signal, which can be changed according to user preference. It is important to note that stop loss and take profit percentages do not account for the spread, which could lead to undesirable outcomes if users take excessive leverage. The presenter advises putting a time slip of one second to ensure that multiple signals are not processed within the same second. Finally, the presenter urges viewers to like and subscribe to the channel and to join the Discord community.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:40

Templates MetaTrader 5 live trading using Python - part 6: Machine learning (MetaTrader 5/Python)



Templates MetaTrader 5 live trading using Python - part 6: Machine learning (MetaTrader5/Python)

Lucas shows how to put a trading strategy based on machine learning in live trading. The process involves importing libraries, using feature engineering to transform open, high, low, close, and volume data to understand the relationship between features to create a machine learning algorithm, standardizing data, converting data using principal component analysis (PCA), fitting and predicting variations, and ultimately deciding whether to buy or sell assets. He also provides an hour-based time condition and day condition to choose the best time to trade. The code works during market hours and signals when to buy or sell assets.


 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 14:38

Build Your Own MetaTrader 5 Trading Bot : Part 1



Build Your Own MetaTrader 5 Trading Bot

The video tutorial discusses the components needed and requirements to build an automated trading bot using MetaTrader 5, including Windows 10, Python 3.10, an IDE like PyCharm or Visual Studio Code, a MetaTrader 5 download, and a trading account. The presenter emphasizes the importance of a settings.json file for storing sensitive information and demonstrates creating an example settings file using the Json and OS libraries. He also emphasizes code commenting and advises against opening too many file handles at once. The video concludes by showing how to import sensitive information and error handling before promising to demonstrate connecting to MetaTrader in the next episode.
  • 00:00:00 In this section of the video, the presenter discusses the requirements for building an automated trading bot using MetaTrader 5. The necessary components needed include Windows 10, Python 3.10, an integrated development environment (IDE) such as PyCharm or Visual Studio Code, a MetaTrader 5 download from a broker, and a trading account. Next, the presenter introduces the first piece of code, "main.py," which acts as the main function of the Python code, allowing for easy iteration and improvement of the code. The presenter also discusses the importance of a settings.json file for storing sensitive information, such as login credentials and server information, and how it can be used to avoid putting this information directly into the code. Finally, the presenter includes a list of symbols to trade, with USDJPY as an example.

  • 00:05:00 In this section, the speaker discusses creating an example settings file that will turn into a settings.json file to be used in the program. He notes the importance of importing the Json and OS libraries to read and locate files, respectively. He also emphasizes the significance of commenting one's code to understand its purpose and parameters when returning to it later. The speaker then outlines his function for getting project settings, which includes checking if the file path exists and closing the file once it's done with. He warns against opening too many file handles at once and provides a method to avoid this problem. Finally, he sets up the import file path for the settings.json file, allowing for flexibility in file location while ensuring the program can find the correct file.

  • 00:10:00 In this section, the video tutorial shows how to import sensitive information such as username and password into the settings.json file. The narrator highlights the importance of securely importing this information and demonstrates error handling by intentionally creating an error in the settings2.json file. Finally, the video concludes by promising to show viewers how to connect to MetaTrader 5 in the next episode.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 14:41

Build Your Own MetaTrader 5 Trading Bot - Part 2

Get the code at GitHub: https://github.com/jimtin/algorithmic_trading_bot



Build Your Own MetaTrader 5 Trading Bot - Pt 2

This video continues the process of building an automated trading bot using MetaTrader 5, focusing on error handling and refactoring the code to simplify its appearance. The instructor emphasizes the importance of utilizing a practice account to avoid any unnecessary financial losses and walks viewers through the process of initializing and logging into MetaTrader 5 while commenting on the code and defining parameters. They demonstrate using try and except statements to handle any errors that may arise and show how to print out exceptions to the screen to troubleshoot issues in the future. Additionally, they create a separate function called "start_up" to simplify the code and handle the startup process more efficiently. Finally, they import the new function into main.py and print out the outcome on the screen.

  • 00:00:00 In this section, the instructor recommends completing the setup 101 episode before diving into the process of building an automated trading bot using MetaTrader 5. The necessary tools for this episode include the Python package installer called pip and the official Metatrader5 Python library. It's crucial to have a trading account, and the instructor highly recommends using a practice account to avoid losing money. The instructor walks viewers through initializing and logging into Metatrader5 using a function called start_mt5, commenting on code and defining parameters. The code employs a try and except statement to handle any errors that may arise, ensuring the code remains robust.

  • 00:05:00 In this section, the video creator discusses error handling in their trading bot program. They explain that if an error occurs, the program will throw an exception and print it to the screen, which will help users troubleshoot any issues that arise in the future. Additionally, they demonstrate the use of the try and accept statements in conjunction with if statements to handle both initialization and login errors separately. Finally, they return a boolean value to indicate success or failure of the functions. The video then ends with a demonstration of the program running in main.pi.

  • 00:10:00 In this section, the instructor discusses how to simplify code by creating a separate function to pull out the functionality of a start-up procedure. This is done by creating a new function called "start_up", which is passed the variable project settings. The new function will repeat the same functionality that was placed in main but with a few extra features such as a message for the user if the startup was successful. The new function can also return an error message if something went wrong during the start-up process. Finally, the instructor shows how to import the new function into main.pi and print the outcome to the screen.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 14:46

Build Your Own MetaTrader 5 Trading Bot - Get 50,000 Candlesticks

Get the code at GitHub: https://github.com/jimtin/algorithmic_trading_bot



Build Your Own MetaTrader 5 Trading Bot - Get 50,000 Candlesticks

The video provides a step-by-step guide to build a MetaTrader5 automated trading bot. The crucial first step is to make sure that you have completed the MetaTrader Connect episode and installed the python pandas library. The tutorial shows how to initialize the symbol and expand the startup function to include initializing symbols. It demonstrates how to retrieve up to 50,000 candlesticks using the 'get candlesticks' function, which requires symbol, timeframe, and candlestick number inputs. The video emphasizes ensuring that all necessary columns are present in the candlestick chart data and shows how to retrieve the tick volume data. The creator promises to demonstrate how to calculate an EMA indicator in the next episode.

  • 00:00:00 In this section, the video provides steps on how to build your own MetaTrader5 automated trading bot. The first step is to ensure that you have completed the MetaTrader Connect episode that shows how to connect and retrieve data from MetaTrader, and installed the python pandas library. Initializing the symbol is crucial, which is done by adding the initialize symbol function in your mt5_lib.py file. The function checks if the symbol exists to save troubleshooting time, and if it does exist, it will attempt to initialize it with a try and accept approach for fault tolerance. It is essential to note that symbol names differ across brokers, so it is necessary to check with your broker how they denote their different types of symbols.

  • 00:05:00 In this section, the video discusses expanding the startup function to include initializing symbols. The function allows for a separate startup function to extract things that need to happen at startup into their own function. The function is updated to comply with settings.py and includes iterating through a list of symbols and enabling them individually while notifying the user of any errors or exceptions. Finally, the double underscore main double underscore is updated to remove complexity and make it more straightforward.

  • 00:10:00 In this section, the tutorial shows how to retrieve 50,000 candlesticks using a new function called "get candlesticks." This function requires three pieces of information: the symbol, the timeframe, and the number of candles to retrieve. The tutorial explains how to set the boundaries on this function to 50,000 candlesticks, though it's possible to get millions of rows of data through Metatrader5. The function checks to ensure that there are no more than 50,000 candlesticks and, if not, continues to retrieve the desired data. A function is also provided to convert time frames into a Metatrader5 object to make the process easier. The returned dataframe will be used to get the exponential moving average in the next episode.

  • 00:15:00 In this section, the creator of the video notes that for users with more programming experience, they might have noticed he used if and else statements instead of switch statements in order to maintain backwards compatibility for Python 3.9. He also provides the code for the different time frames utilized by MetaTrader 5. Moving on, the video discusses how to retrieve candlesticks using the MetaTrader5 python API and how to convert the data into a Pandas dataframe for data analysis. The video then demonstrates how to bring all of the previously discussed functions into "Main" and use the symbols array to retrieve candlesticks for each symbol listed. Finally, the video shows how to retrieve 1,000 candlesticks initially and provides a "top tip" for how to increase this number to 50,000.

  • 00:20:00 In this section, the speaker emphasizes the importance of ensuring that all columns are present in the candlestick chart data for implementing trading strategies such as EMA crosses. They use a pandas call to display all columns and show that the tick volume data is also present. They then explain that obtaining 50,000 candles is as simple as adjusting the candles variable before promising to demonstrate how to calculate an EMA indicator in the next episode.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 14:48

Build Your Own MetaTrader 5 Python Trading Bot: EMA Indicator

Get the code at GitHub: https://github.com/jimtin/algorithmic_trading_bot



Build Your Own MetaTrader 5 Python Trading Bot: EMA Indicator

This section of the video demonstrates how to create a function for calculating exponential moving average (EMA) indicator in Python. The video provides step-by-step instructions for creating the function, which calculates the average value of previous trades with a multiplier applied to the most recent trade, and how to add a column for the EMA to each row of the data frame. The video also emphasizes the importance of commenting functions and using a pseudo-library to make the code reusable and conform to the "don't repeat yourself" principle. The video concludes by demonstrating how to calculate different types of EMAs that will be used in the upcoming EMA crossover strategy.

  • 00:00:00 In this section, the video discusses the process of building an EMA indicator for your algorithmic trading bot. The exponential moving average (EMA) calculates the average value of previous trades with a multiplier applied to the most recent trade. The multiplier weighs the most recent trades to have a greater impact on the EMA value, making it more sensitive to price movements. The video provides the pseudocode and step-by-step instructions for creating the function that calculates the EMA value, as well as how to add a column for the EMA to each row of the data frame. The video emphasizes the importance of commenting functions and using a pseudo-library to make the code re-usable and conform to the "don't repeat yourself" principle.

  • 00:05:00 In this section, the video explains how to create a function for calculating the Exponential Moving Average (EMA) indicator in Python. The function can be used to add a new EMA to a data frame, which is important for the EMA cross strategy that will be discussed in the next episode. The function sets up a multiplier which can be adjusted based on the desired weighting of the EMA, and iterates through the data frame row by row to unpack and calculate the EMA. The video advises against using this method on large data frames and recommends using the TA lib function instead for faster computation. The section ends by returning to main.py and demonstrating how to calculate different types of EMAs which will be used in the upcoming EMA crossover strategy.

  • 00:10:00 In this section of the video on building a MetaTrader 5 Python Trading Bot, the speaker explains how to calculate and print EMA 50, EMA 20, and EMA 200 by passing the candlestick dataframe to the iterative method, and setting values accordingly. Removing the print statement can be done, as per the speaker, to check for the EMA 50 and EMA 20 rows, while calculating EMA 200. All three values can then be viewed separately.

Reason: