Something Interesting in Financial Video - page 29

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:05

Trading with Python. GET PAID for holding your Trades open



GET PAID for holding your Trades open | Trading with Python #8

The video discusses carry trading, which involves brokers paying traders a small amount every day for holding open positions on their account, also known as positive stock trading. The purpose is to identify symbols that offer positive swaps in order to decide whether or not it is worth trading them. The video provides tables showing symbols with positive swaps on both the long and short sides. Carrying trading is recommended for long-term trades lasting days or weeks, and traders should monitor the swap values as brokers can update them at any time.


 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:06

Trading with Python. Analyze Broker Spreads with Pandas



Analyze Broker Spreads with Pandas | Trading with Python

In this video, the presenter uses pandas in Python to analyze broker spreads. Tick data exported from broker history using MetaTrader 5 is passed into a pandas dataframe, and spread and hourly-based data analyzed to plot changes in spreads over time. Spreads were found to be generally tight but could spike during news events or low liquidity periods, particularly around midnight broker time. The analysis advises traders to optimize their trading costs by considering the data presented for different symbols.

  • 00:00:00 In this section, the video explores how to use pandas to analyze broker spreads. The video demonstrates how to export tick data from the broker history using MetaTrader 5 and analyzes the spread data using pandas. The tick data is then passed into a pandas dataframe and converted from a unix timestamp format to a datetime format. The spread column is then calculated using the difference between the ask and bid price. The time column is also converted to hourly-based data to analyze spreads hour by hour. The data is plotted using the 'plotline' library to analyze changes in spreads over time. The analysis shows that spreads are generally tight but can spike during news events or periods of low liquidity. During midnight broker time, liquidity is low, and spreads can be high.

  • 00:05:00 In this section, the speaker shows how to analyze broker spreads using pandas in Python. The function groups rows with the same hour and calculates the average spread and max spread for each hour. The resulting table and bar chart reveal that spreads are usually high at midnight and 1 am, while they are very tight throughout the day on the EUR/USD pair. For the XAU/USD pair, the spreads are a bit wider, and there are bigger spikes in the afternoon during the American session. The speaker advises traders to consider such data to optimize their trading costs and use the Jupyter notebook to connect their platform and analyze different symbols.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:07

Trading with Python. Code a Bollinger Band Trading Strategy in Python



Code a Bollinger Band Trading Strategy in Python

In this video, the presenter explains the Bollinger Bands trading strategy in Python where a simple moving average, a lower band, and an upper band are used to contain 95% of all prices within the bands. The strategy involves buying when the price reaches the lower Bollinger Band and selling when the price reaches the upper Bollinger Band. A stop loss is set to three standard deviations below the mean, while take profit is set to two standard deviations above. The presenter shows the implementation in Python using Pandas and MetaTrader5 platforms and provides test results, explaining each trade outcome. However, he advises against blindly deploying this strategy in trending markets and stresses the importance of analyzing market conditions.

  • 00:00:00 In this section of the video, we learn about Bollinger Bands and how to trade using them. Bollinger Bands consist of a simple moving average, a lower band, and an upper band. The simple moving average is calculated by taking the average value of recent prices. In Bollinger Bands, two standard deviations are usually used, which contain 95% of all prices within the bands. We can buy when the price is low and sell when the price is high above the mean. The strategy is that we buy when the price closes below the lower band and sell when the price closes above the upper band. A stop loss is set to three standard deviations and take profit to two standard deviations. The position size is only one allowed at the same time.

  • 00:05:00 In this section, the speaker explains how to calculate the Bollinger Bands using pandas in Python. To calculate the simple moving average, they defined df sma. The standard deviation is calculated similarly but using std instead of mean. The lower band is defined as two standard deviations below the SMA, while the upper band is defined as the FSMA plus two times the FSD. To start the backtesting, a signal column is created, and a buy or sell signal is generated based on whether the close price is below the lower band or above the upper band. The speaker also introduced classes position and strategy, which are created to run the backtest and evaluate profits based on historical data.

  • 00:10:00 In this section of the video, the presenter shows the backtest results of the Bollinger Band trading strategy in Python. The results show a list of positions opened and closed, along with the profit of each position and the P&L of the initial balance. The chart shows that the strategy was profitable, making around $7,500 by trading throughout the year. The presenter then explains each trade that was made and how it resulted in either profit or loss. He also mentions that the volume specified in the backtest is a bit high and risky, so it might need to be tuned down. Finally, he explains how to code the strategy in Python using the MetaTrader 5 trading platform.

  • 00:15:00 In this section, the speaker explains how to create a Signal function in Python to generate signals for a trading strategy using Bollinger Bands. The function requests bars from the MetaTrader5 platform, calculates the mean and standard deviation, and uses them to compute the upper and lower bands. The last bar's closing price is used to compare to the upper and lower bands to generate a buy or sell signal. The strategy loop inside the function checks for signals, then sends a market order with specific parameters, like stop-loss and take-profit, when a signal is triggered. The speaker tests the strategy using the MetaTrader5 platform, showing how the code works in real-time, and advises adjusting the symbol and time-frame for users' preference.

  • 00:20:00 In this section, the speaker discusses a trading strategy based on Bollinger Bands. He explains that this strategy involves buying when the price reaches the lower Bollinger Band and taking profits at two standard deviations above the buying price. He notes that this strategy works well in ranging markets but performs poorly in trending markets and advises against deploying strategies blindly, stressing the importance of analyzing market conditions before deploying them. The speaker also provides links for downloading the Jupyter Notebook and Python code used in the strategy and asks viewers to like and subscribe if they enjoyed the video.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:07

Trading with Python. Code a Simple Moving Average (SMA) Crossover Trading Strategy in Python



Code a Simple Moving Average (SMA) Crossover Trading Strategy in Python

In this YouTube video, the presenter explains how to code a simple moving average (SMA) crossover trading strategy in Python. The strategy uses the crossover of two SMA as a signal for buying and selling assets. The presenter demonstrates how to visualize the historical price data using Pandas and Plotly libraries, defines the fast and slow SMAs, finds crossovers, calculates the crossover column and plots the bullish crossovers. The video then goes on to show how to backtest the SMA crossover trading strategy using previously created classes, and discusses the results using a line chart of profit and loss over time. Overall, the video provides a step-by-step guide to creating and testing a simple and effective trading strategy using Python.

  • 00:00:00 In this section of the video, the presenter introduces a trading strategy that uses the crossover of two simple moving averages as a signal for buying and selling assets. This trend following strategy allows for capturing big moves in the market without any limit on profits. The presenter then proceeds to show how to code this simple moving average crossover strategy on the Jupiter notebook environment and backtest it on the DAX index using historical price data. The presenter uses Pandas and Plotly libraries to organize and visualize the data obtained from the MetaTrader 5 platform, and converts the time column into a datetime format.

  • 00:05:00 In this section of the video, the instructor begins by visualizing close prices to see how the prices have moved over time by using px.line. We also see that the DAX has been moving around 13 to ten and a half thousand at the beginning, there was a major drop during the COVID crisis, but prices are now returning back up to all-time highs. Moving averages are added to the chart to help generate signals, and a slow sma and fast sma are defined. The slow sma is set to 100, and a fast sma is set to 10, and both are added to the plot. Finally, the instructor defines some variables in another cell to make it easier to adjust settings in the future.

  • 00:10:00 In this section of the video, the presenter explains how to find crossovers in a Simple Moving Average (SMA) crossover trading strategy using Python and Pandas. The presenter sets the period for the fast and slow SMAs to 10 and 100, respectively. To find crossovers, the previous fast SMA values are compared with the slow SMA values, and if the previous fast SMA value is lower and the current fast SMA value is higher, it is considered a bullish crossover. On the other hand, if the previous fast SMA value is higher and the current fast SMA value is lower, it is considered a bearish crossover. The presenter creates a function called "find_crossover" to automate this process.

  • 00:15:00 In this section, the video explains how to calculate a crossover column using the fast and slow SMA values previously calculated. The function np.vectorize is used to pass in the function and the columns representing the inputs, and then the results are eliminated of the None values. After the crossover column is created, the video shows how to find the bullish crossovers and plot them as vertical lines on the chart using pick.dot at v line with x equal to row.time.

  • 00:20:00 In this section, the instructor walks through the process of backtesting the SMA crossover trading strategy by buying when the red line crosses above the green line, and selling when it crosses below the slow-moving average. The instructor uses previously created classes, class position and class strategy, to create a backtest. The class position has methods to open and close positions, as well as a method to return the results as a dictionary. While in the class strategy, the instructor initializes the starting balance of the trading account, specifies the volume of trading and adds the data frame with the historical data and signal columns. In the run method of the class strategy, the logic of the strategy is defined using if statements to open and close positions based on cross-over values. Finally, the class is instantiated and run to get the results.

  • 00:25:00 In this section, the presenter discusses the results of the backtest of the simple moving average (SMA) crossover trading strategy that we coded using Python. They show the line chart of the profit and loss over time using Plotly Express and the Figure object to visually analyze the performance. They mention that the strategy has mostly small profits and losses, but eventually, a big profit comes with a big trend. The presenter then thanks the viewers for watching and invites them to ask questions if they have any, and if they enjoy the video, to like and subscribe.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:08

Trading with Python. Code a Buy-Hold Trading Strategy for Stock Indices in Python



Code a Buy-Hold Trading Strategy for Stock Indices in Python

In this video, the presenter discusses how to write a buy-hold trading strategy for stock indices in Python using Jupyter Notebook code to write indicators, strategies, and backtests. The strategy is based on identifying 5%, 15%, or 35% drawdown and purchasing when a drawdown is reached, subsequently selling when reaching the previous all-time high. The speaker explained how to add and check positions using the get positions method which uses a list of positions and appends the position class for every new position. The exit strategy was also explained whereby every open position is closed when the drawdown approaches zero. Finally, the importance of high-quality trades and lengthy periods to permit price recovery is emphasized, and the presenter showcases the results of the backtest represented on a chart.

  • 00:00:00 In this section of the video, the speaker explains the buy-hold strategy on the German stock index, showing previous instances between 2015 and 2018 where the strategy was implemented and how it was affected by bear markets and eventual recoveries. While the strategy works best with time as a resource and can lead to profit by buying at cheap prices, it also has significant risk as it involves buying into drawdowns. The speaker also introduces the Jupyter Notebook code to write your own indicators, strategy, and backtest their results. The code is available for download on TraderPi.com.

  • 00:05:00 In this section of the video, the presenter explains how to create a buy-hold trading strategy for stock indices using Python. The strategy is based on identifying drawdown levels and buying when drawdown reaches 5%, 15%, or 35% and selling when the previous all-time high is reached. The presenter shows how to define a signal column in the data frame using the apply function, and how to use the position and strategy classes to perform a backtest. The presenter also explains how to retrieve data from the position class using the as dict method.

  • 00:10:00 In this section of the video, the speaker explains the method used to add and check positions for the buy and hold trading strategy. The get positions method is used to return a dataframe with the profit and loss calculated. The code uses a list of positions and appends the position class inside this list when a new position is added. The strategy checks for signals to open a trade and iterates through HLC data for 5 percent, 15 percent and 35 percent drawdowns. The exit strategy is also explained, whereby when drawdown is zero, every open position is closed. The backtest results are shown, and the speaker highlights the importance of high-quality trades and lengthy periods to allow prices to recover eventually. The results are then plotted onto a chart to depict the trades.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:09

Trading with Python. Code 10 Technical Trading Indicators with Python


Code 10 Technical Trading Indicators with Python

The video discusses ten technical trading indicators with Python, starting with the simple moving average (SMA), which is used to determine trends. The average true range (ATR) measures volatility, while the relative strength index (RSI) identifies overbought and oversold prices. Yesterday's high low and standard deviation can help identify ranging, breakout, and volatile markets. Bollinger Bands use a simple moving average (SMA) and standard deviation to indicate mean reversion or breakout strategies. MACD and SMA crossover indicate a change in trend by calculating fast and slow EMAs or SMAs. The moving average crossover combines fast and slow moving averages to identify potential trend reversals, while the stochastic oscillator considers the highest and lowest values of a period to identify overbought and oversold conditions.

  • 00:00:00 In this section, the speaker introduces the 10 technical indicators that will be calculated using Python, starting with the simple moving average (SMA). The historical data is requested from the MetaTrader5 library and then processed using Pandas. The SMA is a popular indicator used to determine trends, which is calculated by using the last 10 close prices. The resulting SMA is visualized using Plotly Express.

  • 00:05:00 In this section, the video explains the calculation and usage of Simple Moving Average (SMA) and Exponential Moving Average (EMA) indicators in technical trading. The SMA takes the average of the last 10 prices, and the EMA gives more weight to recent prices. The video compares the two indicators and notes that traders who want faster signals may prefer the EMA, which reacts to immediate price changes much faster than the SMA. The video then introduces the Average True Range (ATR) indicator, which measures volatility and helps traders assess risk and potential trend changes. ATR is calculated by taking the range of the candle (high - low) for a specific period and then averaging it. The video notes that a decrease in ATR may indicate the start of a retracement phase. ATR is shown in a plot and is observed to be higher during more volatile periods.

  • 00:10:00 In this section, the video discusses two technical trading indicators: the Average True Range (ATR) and Relative Strength Index (RSI). The ATR measures the volatility of a market by comparing the difference between high and low prices over a specific period, while the RSI helps identify overbought and oversold prices. The video demonstrates how to calculate the RSI using a 14-period setting and explains the formula for generating the RSI value. The video also provides sample code for plotting the RSI indicator, which can help traders identify potential buy or sell signals based on whether the RSI is in oversold or overbought territory. Additionally, the video briefly discusses the previous day's high and low values and how these can be utilized in trading strategies.

  • 00:15:00 In this section, the video discusses two technical trading indicators with Python: yesterday's high low and standard deviation. Yesterday's high low can be a valuable indicator for intraday trading as it can show if the market is ranging or if there is a breakout, which can indicate a trending market. Standard deviation is used to measure variance, and a high standard deviation can mean the market is volatile while a low standard deviation can indicate the market is not moving much. The video then discusses Bollinger Bands, which are made up of a simple moving average (SMA) with a period of 20, an upper band two standard deviations above the SMA, and a lower band two standard deviations below the SMA. Bollinger Bands can be used for mean reversion strategies or breakout strategies.

  • 00:20:00 In this section, the video explains two additional technical trading indicators, MACD and SMA crossover, and how to calculate and plot them using Python. MACD is a trend indicator that predicts reversals by calculating the fast EMA with period 20 and the slow EMA with period 26, and by looking at the relationship between those two EMAs. The SMA crossover, on the other hand, is using a much easier concept, and it simply involves a fast simple moving average and a slow simple moving average that indicate a change in trend whenever they cross. The video provides the code to calculate and plot both indicators and explains how they can be used to identify reversals in trend.

  • 00:25:00 In this section, the presenter discusses the moving average crossover and stochastic oscillator indicators. For the moving average crossover, the presenter combines a fast and slow moving average to identify potential trend reversals. A crossover is identified when either the fast moving average crosses over or under the slow moving average, in which case a crossover column is created. The presenter demonstrates the indicator's effectiveness by plotting the moving averages together with the closing price and adding vertical lines to mark each crossover. The stochastic oscillator is similar to the RSI, but instead of using only closing prices for its calculation, it considers the highest and lowest values of a period. The oscillator is defined using a formula and, like the RSI, is used to identify potential overbought and oversold conditions. The presenter invites viewers to download and test the code for themselves and suggests leaving comments about favorite indicators for a potential future video.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:09

Trading with Python. How to code an RSI Trading Strategy in Python



How to code an RSI Trading Strategy in Python

The video provides an in-depth explanation on how to code and backtest an RSI trading strategy in Python. The strategy relies on buying when the RSI is oversold and selling when it's overbought, with the entry signals being when the RSI drops below 30, and when it exceeds 70, it's time to sell. The exit strategy involves using the average true range (ATR) indicator to set take profit and stop loss 280 pips away from the buying or selling price. The video covers the use of the MetaTrader5, Pandas, and Plotly libraries for historical data requests, indicator calculation, backtesting, and result visualization. It concludes by encouraging viewers to download the Jupiter notebook to implement the RSI trading strategy in Python.

  • 00:00:00 The video details how to code and backtest an RSI trading strategy in Python. The strategy focuses on buying when the RSI is oversold and selling when it's overbought, making it a mean reversion strategy. The entry signals are when the RSI drops below 30, and when it exceeds 70, it's time to sell. The exit strategy involves using the average true range (ATR) indicator to set take profit and stop loss 280 pips away from the buying or selling price. The video also covers how to use the MetaTrader5, Pandas, and Plotly libraries for historical data requests, indicator calculation, backtesting, and result visualization.

  • 00:05:00 in this section of the video, the speaker explains how they plotted the RSI and created overbought and oversold levels using Plotly. They show that buying signals occur when the RSI drops below a specific horizontal line, while selling signals occur when it is above 70. Additionally, the ATR (average true range) indicator is introduced as a measurement of volatility, which is calculated by finding the range of the candle and taking the average for the last 14 candles. The ATR is then plotted on a chart, showing the volatility spike in early 2020. Finally, the speaker shows how to perform a backtest and create a strategy class with logical conditions for entering and exiting trades. The conditions include checking for open positions, using RSI values to determine buy signals, and setting stop loss and take profit levels.

  • 00:10:00 In this section, the speaker explains how to run the backtest for the RSI trading strategy in Python. The backtest is created by iterating through the historical data set, and the positions are saved in a list that contains position classes. The stop loss and take profit are defined as 280 hours away from the buying and selling prices. The logic for the backtest is that when the RSI exceeds the value of 70, it's a sell signal, and a short position is added to the list of positions in the strategy. After iterating through all the historical data, the backtest returns a list of positions and their profits. Using this data, the backtest results can be visualized by plotting the closed positions using Plotly Express, and the profit and loss can be plotted using the same method. The speaker shows an example of the resulting plot to indicate when the strategy performs well or poorly.

  • 00:15:00 In this section, the speaker concludes the video, thanking the audience for their attention and inviting them to download the Jupiter notebook for implementing the RSI trading strategy in Python. He notes that after a big drawdown in the period discussed, the piano is now oscillating around the same level. He signs off and promises to return soon with another video.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:10

Trading with Python. Learn Pandas on Trade Examples



Learn Pandas on Trade Examples

The video teaches users how to apply various Pandas functions to analyze trade data in Python to answer analytical questions such as determining the longest and shortest trade durations, calculating the most profitable and losing months, identifying the most active months, analyzing buy and sell orders, and calculating the biggest absolute drawdown. Additionally, it covers calculating the win rate, reward to risk ratio, and profit factor, which measures the ratio between gross profit and loss. The speaker provides a CSV file and real examples to guide viewers through the analysis process and offers a Jupiter notebook for anyone who wants to practice pandas.

  • 00:00:00 In this section, the speaker explains how to use Pandas library to analyze trade data in Python. They provide a CSV file with trade data and guide viewers through answering six analytical questions on this data. They demonstrate how to calculate the number of trades, the overall profit and loss, the date and time of the first and last trade, the biggest profit and loss, and the length of each trade. They use various Pandas functions, such as "shape," "sum," "iloc," and "loc," to perform these calculations, and provide real examples of the output.

  • 00:05:00 In this section, the video covers different trade analysis questions and how to obtain the answers using Pandas functions. The questions include finding the longest and shortest trade durations, calculating the most profitable and losing months based on trade profits, identifying the most active months in terms of trade counts, and analyzing buy and sell orders. Pandas' groupby method is utilized to aggregate and sort the data frame values accordingly. Functions used include count and sum to calculate trade counts and profits, and datetime to extract month values from the trade date times.

  • 00:10:00 In this section, the video covers various calculations and analyses, including calculating the total number of trades for each order type and determining that buy orders performed better than sell orders. The video also explains how to calculate the biggest absolute drawdown, which is the maximum cumulative loss incurred during trading, and how to calculate the average profit or loss by grouping trades based on profit type. Additionally, the video demonstrates how to calculate the win rate, which is the probability of a trade being won or lost, and how to calculate the reward to risk ratio by taking the average value of winners and losers.

  • 00:15:00 In this section, the speaker discusses the profit factor, which is the ratio between gross profit and gross loss. The net profit is calculated by summing all the profits and losses separately based on the profit type (win or loss). The profit factor is then determined by dividing the gross profit by the gross loss. The result of this calculation is a metric that determines how much the wins outweigh the losses. The profit factor in this case is 1.34. The speaker also mentions that they will provide a Jupiter notebook on their website for those who want to practice pandas.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:10

Trading with Python. Manage Data in CSV and Databases (SQLite)



Manage Data in CSV and Databases (SQLite)

In the "Manage Data in CSV and Databases (SQLite)" video, the speaker demonstrates how to save and read data in a CSV file using pandas DataFrame and how to work with databases using SQLite3. Viewers are shown how the OHLC data is saved in a pandas DataFrame, saved as a CSV file, and then later read and converted into a pandas DataFrame. The speaker also shows viewers how to work with databases in Python using SQLite3, including creating a database or connecting to an existing one, saving data inside the database, and reading the data using simple queries. The speaker concludes the video by offering viewers access to the code used in the tutorial and expressing the hope that the tutorial was helpful.

  • 00:00:00 In this section, the speaker shows how to save and read data in a CSV file using pandas DataFrame. After retrieving some OHLC data from a broker, the data is saved in a pandas DataFrame and then saved as a CSV file. By using `pd.read_csv`, the CSV data can be later read and converted into a pandas DataFrame. The speaker later demonstrates how to work with databases in Python using SQLite3, which is a part of the Python standard library. The `sqlite3.connect` method is used to create a database or connect to an existing one. The OHLC data is saved inside the database using `ohlcdf.to_sql` and then is read using simple queries by running `pd.read_sql_query`.

  • 00:05:00 In this section, the speaker concludes the video by thanking viewers for their attention and offering to share the code used in the tutorial. The speaker provides a link to their website where viewers can access the code. They express the hope that the viewers found the video helpful and promises to be back with another tutorial soon.

 

Forum on trading, automated trading systems and testing trading strategies

Python in algorithmic trading

MetaQuotes, 2023.04.13 12:33

MetaTrader 5 live trading using Python. MetaTrader 5 live trading with Python in 2021 (Template included)



MetaTrader 5 live trading with Python

The video "MetaTrader 5 live trading with Python in 2021 (Template included)" presents a helpful guide for traders aiming to customize their trading strategies and improve profitability using MetaTrader5 and Python. It presents a template that can be modified based on the trader's needs, highlighting the necessary code sections. The video also covers different functions like initializing functions, importing data, and making trade orders. Among the useful tools demonstrated is the resume function, which enables traders to monitor open positions even after shutting down the Python sheet. While emphasizing the need for a Windows device to use the MetaTrader 5 library, the speaker also suggests some options for Mac users.

  • 00:00:00 In this section, Lucas from Control shows how to put a trading strategy in live trading using MetaTrader5 and Python. He provides a template and shows how to customize the code based on one's needs. The video also demonstrates different functions, including initializing the function, importing data, and making trade orders. The resume function is highlighted as a useful tool for monitoring current open positions even after shutting down the Python sheet. Overall, the video provides a useful guide for traders who want to customize their trading strategies and maximize profitability.

  • 00:05:00 In this section, the speaker discusses a function that allows for access to open positions at any time to eventually close them. This function utilizes an algorithm that opens a position within a fixed interval and does not use a momentum strategy. The function includes a lot of comments and is simple but essential, as it returns all information about the algorithm. The speaker also provides a template that can be easily customized by changing a few lines of code, allowing users to put their own algorithm into production. However, the speaker notes that it is important to have a Windows device to use the MetaTrader 5 library and provides some options for Mac users who do not have access to a Windows device.

Reason: