Python in algorithmic trading - page 3

 

The data importance in Trading - Garbage in, Garbage out! (an MT5 broker vs Yahoo finance)



The data importance in Trading - Garbage in, Garbage out! (an MT5 broker vs Yahoo finance)

The importance of using the same data source to train and deploy a trading algorithm is emphasized in this video. By comparing returns generated by the same trading signal using different data sources, such as Yahoo Finance and a broker's data, the speaker highlights the significance of the quality and relevance of the data used. The video advises traders to conduct their own experiments and use relevant data sources from the broker being traded on to train their algorithms for better returns.

The data importance in Trading - Garbage in, Garbage out! (an MT5 broker vs Yahoo finance)
The data importance in Trading - Garbage in, Garbage out! (an MT5 broker vs Yahoo finance)
  • 2022.06.17
  • www.youtube.com
Today, I will show you the importance of data in trading. I will import the data from MT5 (MetaTrader5)and Yahoo finance then I will show you the difference ...
 

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.
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
  • 2022.07.15
  • www.youtube.com
Today, we will see how to put your own trading algorithm in MetaTrader 5 live trading with Python in 2021. You will have a template included to run your own ...
 

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.
Templates MetaTrader 5 live trading using Python - part 2: Place order on MetaTrader5 using Python
Templates MetaTrader 5 live trading using Python - part 2: Place order on MetaTrader5 using Python
  • 2022.07.22
  • www.youtube.com
Today, we will see how to put your own trading algorithm in MetaTrader 5 live trading with Python in 2022. You will have a template included to run your own ...
 

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.
Templates MetaTrader 5 live trading using Python - part 3:Money management with MetaTrader5 / Python
Templates MetaTrader 5 live trading using Python - part 3:Money management with MetaTrader5 / Python
  • 2022.07.29
  • www.youtube.com
Today, we will see how to put your own trading algorithm in MetaTrader 5 live trading with Python in 2022. You will have a template included to run your own ...
 

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.

Templates MetaTrader 5 live trading using Python - part 4: Trading signal creation
Templates MetaTrader 5 live trading using Python - part 4: Trading signal creation
  • 2022.08.05
  • www.youtube.com
Today, we will see how to put your own trading algorithm in MetaTrader 5 live trading with Python in 2022. You will have a template included to run your own ...
 

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.
Templates MetaTrader 5 live trading using Python - part 5:Live trading template (MetaTrader5/Python)
Templates MetaTrader 5 live trading using Python - part 5:Live trading template (MetaTrader5/Python)
  • 2022.08.12
  • www.youtube.com
Today, we will see how to put your own trading algorithm in MetaTrader 5 live trading with Python in 2022. You will have a template included to run your own ...
 

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.

Templates MetaTrader 5 live trading using Python - part 6: Machine learning (MetaTrader5/Python)
Templates MetaTrader 5 live trading using Python - part 6: Machine learning (MetaTrader5/Python)
  • 2022.08.19
  • www.youtube.com
Today, we will see how to put your own machine learning trading algorithm in MetaTrader 5 live trading with Python in 2022. You will have a template included...
 

Build Your Own MetaTrader 5 Trading Bot : Part 1

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



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.
Build Your Own MetaTrader 5 Trading Bot
Build Your Own MetaTrader 5 Trading Bot
  • 2023.02.15
  • www.youtube.com
In this series, I'm going to show you how to build your own MetaTrader 5 Python Trading Bot from scratch! Are you interested in trading and want to grow your...
 

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.
Build Your Own MetaTrader 5 Trading Bot - Pt 2
Build Your Own MetaTrader 5 Trading Bot - Pt 2
  • 2023.02.16
  • www.youtube.com
In this series, I'm going to show you how to build your own MetaTrader 5 Python Trading Bot from scratch! Are you interested in trading and want to grow your...
 

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.
Build Your Own MetaTrader Trading Bot - Get 50,000 Candlesticks
Build Your Own MetaTrader Trading Bot - Get 50,000 Candlesticks
  • 2023.02.19
  • www.youtube.com
This Episode: Retrieve 50000 Candlesticks from MetaTraderAre you ready to take your trading to the next level? Then join me and learn how to build your own a...