Something Interesting in Financial Video - page 33

Sergey Golubev  

Forum on trading, automated trading systems and testing trading strategies

Programming tutorials

MetaQuotes, 2023.05.24 16:54

Moving Average Crossover EA mql5 Programming



Moving Average Crossover EA mql5 Programming

Hi, this is Toby, and in today's video, I'll show you how to code a simple moving average crossover expert advisor for MetaTrader 5. Let's get started.

First, let's define what we want the expert advisor to do. We want the EA to open a buy position when the fast moving average (blue line) crosses above the slow moving average (red line) and open a sell position when the fast moving average crosses below the slow moving average. We'll also add a stop loss and take profit to the EA, as well as input variables for the periods of the moving averages.

To begin coding, open the MetaEditor in MetaTrader 5. Create a new expert advisor using the template and name it "Moving Average." Clean up the code by removing unnecessary lines and comments. Next, add input variables for the periods of the fast and slow moving averages. Set default values for these variables and display them in the input tab of the EA settings.

Check the user input in the OnInit function to ensure valid values are entered. If the input is invalid (zero or negative), display an alert message and stop the EA. Create handles for the fast and slow moving averages using the ma function. Set the symbol, period, and input variables for each moving average. Check if the creation of handles is successful. If not, display an alert message and stop the EA. Create global variables for storing the indicator values. Use dynamic arrays for the fast and slow buffers. In the OnTick function, copy the latest indicator values into the buffers and check if enough data is available. If not, return and display an alert message.

Print the indicator values on the screen to verify if everything is working correctly. Use the Comment function to display the values of the fast and slow moving averages.

In the Strategy Tester, test the EA to check if the indicator values are displayed correctly. Now, we can check for a crossover of the moving averages. If the fast moving average is below the slow moving average at bar 1 and above the slow moving average at bar 0, we have a crossover. Open a buy position in this case.

To open positions, use the CTrade class. Define a trade variable and proceed with the necessary actions. Compile the code and test the EA in the Strategy Tester to verify if the crossover condition is working correctly and positions are opened accordingly.

That's it for coding the moving average crossover expert advisor in MetaTrader 5. And then we can use the trade.Buy function to open a buy position. We specify the volume of the position, which can be a fixed value or based on your risk management strategy. For now, let's use a fixed volume of 0.1 lots. Now we need to add a condition to check for a sell position. If the fast moving average is above the slow moving average for bar 1 and below for the current bar, we have a crossover in the opposite direction. In this case, we want to open a sell position. We can use the trade.Sell function to do that.

Finally, we can add a stop loss and take profit to our positions. We'll use the trade.SetStopLoss and trade.SetTakeProfit functions. Let's set a stop loss of 100 pips and take profit of 200 pips for this example. Now we have a complete code for our simple moving average crossover expert advisor. We can compile it and test it in the MetaTrader 5 platform.

Once you have compiled the code without any errors, you can save the expert advisor and use it in MetaTrader 5. Remember to backtest and optimize your expert advisor before using it with real money.


Sergey Golubev  

Forum on trading, automated trading systems and testing trading strategies

Quantitative trading

MetaQuotes, 2023.05.12 14:25

Basics of Quantitative Trading



Basics of Quantitative Trading

In this video on the basics of quantitative trading, algorithmic trader Shaun Overton discusses the challenges and opportunities involved in algorithmic trading. Overton explains that data collection, analysis, and trading are the three simple problems involved in algorithmic trading, though the process can get complicated due to finding high-quality data and proper analysis. It can be challenging to select the right platform with good data and features to meet the trader's goals, with the most popular platforms being MetaTrader, NinjaTrader, and TradeStation, depending on the trading type one prefers. Overton also discusses the harsh reality of how easy it is to blow up accounts when trading in the live market, and how important it is to manage risk. Additionally, he explains how quantitative traders can predict overextended moves in the market and discusses the impact of currency wars.

The "Basics of Quantitative Trading" video on YouTube covers various strategies for algorithmic trading, including sentiment analysis and long-term strategies based on chart lines; however, the biggest returns are made during big tail events and trends. Attendees of the video discuss different platforms for backtesting, challenges of integrating multiple platforms for trading analysis, and the increasing interest in formalizing and automating trading strategies. Some long-term traders seek automation as they have been in the game for a long time, and NinjaTrader for programming languages is recommended but has limitations.

  • 00:00:00 Algorithmic trader Shaun Overton explains the three simple problems involved in algorithmic trading: data collection, analysis, and trading. However, the process can become complicated due to obstacles such as finding high-quality data and proper analysis, especially as trading requires careful examination of data. Trading using free options is not recommended as they may contain duplicates or gaps in the data. Additionally, using paid options is out of the retail trader's league as it can cost thousands of dollars per instrument. Nonetheless, trading can be simplified by using platforms that offer software and broker APIs.

  • 00:05:00 The speaker discusses the different software options available for analyzing data and placing trades. The most popular platforms for forex trading are MetaTrader, NinjaTrader, and TradeStation, depending on the type of trading one prefers. MetaTrader is overwhelmingly the most popular, and there are more than a thousand brokers around the world that offer it. The speaker explains that using a pre-built platform like these options makes trading and analyzing data more straightforward and avoids the need to recode analysis multiple times when it comes time to trade. The speaker also goes over the different programming languages used by each platform.

  • 00:10:00 The speaker discusses different platforms for quantitative trading and explains how Multicharts has become popular by copying TradeStation's platform and language. However, there are differences between the languages and it is not always completely compatible. The speaker also talks about the importance of data in quantitative trading and the challenges that come with each platform. He notes that MetaTrader is simple to use but not sophisticated enough for more complex analysis, and the data provided is often of poor quality. Overall, the speaker highlights the importance of carefully selecting a platform with good data and features that meet the trader's goals.

  • 00:15:00 Shaun Overton discusses the challenges of collecting and storing data for quantitative trading strategies. He explains the difficulties in trying to store years' worth of testing data and the limitations that brokers place on obtaining data due to server limitations. He notes that while MetaTrader offers free data, it is not high quality data, while NinjaTrader provides good data but has a steep learning curve to set up. He also warns about the dangers of programming strategies specific to a certain broker as it marries the trader to that particular broker, making it difficult to switch if they are unsatisfied. He lists reasons traders might be upset with a broker, including bad service and bad execution.

  • 00:20:00 Shaun Overton explains some of the issues and games that brokers play to make money off of traders and their trades. Brokers can manipulate market pricing and trades to force traders to pay more for their trades by showing one price and then making traders accept a worse price. Additionally, a trader can receive bad execution from poor latency or software failure. Currently, the biggest issue with algorithmic trading is institutionalized corruption and how institutions can steal money from traders due to technological accidents, as well as Dark Pools and other trading venues that have their own rules in place to manipulate trades.

  • 00:25:00 The speaker discusses the limitations of broker-specific platforms for quantitative trading. While they may be efficient for extremely simple strategies, they have limitations and cannot support anything more sophisticated. The speaker recommends stable platforms like NinjaTrader and MultiCharts, which have good research quality and allow for custom programming and GUI adjustments. However, the speaker warns that these platforms are not suitable for managing portfolios or running funds as they lack the ability to talk to multiple charts and require a lot of manual labor.

  • 00:30:00 Shaun Overton discusses the harsh reality of how easy it is to blow up accounts when trading in the live market, which 90-95% of accounts are closed within 6 months or a full year. There are 2 ways brokers make money, by commissions or risk, and frequently the more popular and lucrative way is by taking on trading losses. Regular traders make money when volatility is low, but when it's high, they get decimated. Risk management is talked about, but for most people, it's just hot air, and they continue to lose money by not managing their risk.

  • 00:35:00 Shaun discusses how volatility affects quantitative trading strategies and how retail traders tend to be wrong in their market predictions. He explains how the ratio of long vs. short positions can be tracked by brokers with access to client accounts and how this information can be used to predict overextended moves. Overton notes that this information is becoming more widely available, with websites like MyFxBook and OANDA publishing data on market positioning. However, he cautions that while this information can be a gold mine for brokers, it may not provide steady cash flow and may result in periods of large losses.

  • 00:40:00 Shaun Overton discusses the potential for quantitative traders to look into client funds of major banks to devise long and short strategies based on the percentage of trades going in a certain direction. He also comments on the skepticism of retail investors participating in the stock market, particularly in light of recent negative news, leading to a withdrawal of billions of dollars since the last crash. Overton also mentions a recent news story on CNBC regarding big fund managers and their impact on the shares of big companies, demonstrating the power of institutional money in moving the market.

  • 00:45:00 It is discussed how institutional trading, especially in forex, may not be as influential in the market as retail trading due to the average account size of traders. However, larger evaluations and greater amounts of money traded lead to more people messing with prices, and even small events such as drunk trading could have an impact on the market. The main driver of currencies is interest rates, and it is a currency war where everyone wants a zero interest rate, making it harder to determine which country's currency is the weakest. Lastly, Japan's currency pair, Dollar Yen, is analyzed in terms of its history and how its prices going down could be related to the dollar weakening and the yen strengthening.

  • 00:50:00 Shaun Overton discusses the impact of currency wars on exporters. He explains how exporters such as Toyota are heavily impacted when the value of the currency in which they operate increases in value. Overton states that there is currently a currency war among major currencies, where countries are trying to devalue themselves, with everyone competing to be zero. Therefore, traders need to be speculating on who is going to do the worst job at destroying a currency, as they will be the best in this environment. Overton feels that the Dollar is currently a disaster, but the best disaster so far. Country-specific social risks and events, such as September 11th and the Fukushima disaster, can also impact currency prices.

  • 00:55:00 Speakers discussed trading in thin markets and exotic currencies. It was mentioned that for algorithmic trading, you need liquidity and a thin spread, which makes it difficult to trade in less popular currencies like the South African Rand or Turkish Lira. Furthermore, the spread of these currencies can be 8 or 9 times more than it costs to trade the Euro against the Dollar, making it challenging to make a profit. Regarding strategies for those with less than 50k in their accounts, speakers mention the importance of focusing on things like the Commitments of Traders report in futures markets to gain insights into market positions.

  • 01:00:00 A group discusses various strategies for algorithmic trading, including sentiment analysis and a simple long-term strategy based on chart lines. The challenge with trading is understanding the distribution of returns since most of the time it is just noise. However, the biggest returns are made during big tail events and trends. Therefore, the best strategies do not consistently make money but grab opportunities when they are there. Despite the desire for signals and action, it is best to let the market do what it is going to do. Quantopian, a program that analyzes market data, is also mentioned.

  • 01:05:00 In this section, attendees of the "Basics of Quantitative Trading" YouTube video discuss different platforms they use for backtesting and optimization, as well as the challenges of integrating multiple platforms for trading analysis and strategy development. While some attendees note that Quantopian provides a platform for individual analysis and is negotiating contracts with brokers to potentially solve platform integration challenges, others discuss the limitations of platforms like NinjaTrader and the difficulties of integrating them with other platforms, with some highlighting the fact that they are better suited for manual trading or as simple backtesting tools. Additionally, Shaun Overton notes that his business is built around formalizing and automating traders' own strategies, with attendees noting that both individual traders and markets are showing increasing interest in formalizing and automating their trading strategies.

  • 01:10:00 Traders attending a quantitative trading seminar ask about the benefits of automating certain trading strategies. Shaun Overton, the speaker, notes that some traders who have been in the game for 10, 20, or even 30 years simply want to automate their strategies so they no longer have to monitor them all day. When discussing trading-specific programming languages, Overton endorses NinjaTrader because it runs on C Sharp, but notes that there are limitations to what can be done within it.

Sergey Golubev  

Doji Candlestick Chart Pattern

The Doji is a important Candlestick formation, signalling indecision between bulls and bears. A Doji is formed when the opening price and the closing price are equal. In a Doji chart pattern, the stock market moves up and down during the trading session, but cannot commit either way.




Forum on trading, automated trading systems and testing trading strategies

Something Interesting

Sergey Golubev, 2023.08.10 06:46

Trading strategy based on the improved Doji candlestick pattern recognition indicator - the article

Trading strategy based on the improved Doji candlestick pattern recognition indicator

The article "Improved candlestick pattern recognition illustrated by the example of Doji" dealt with the concept of metabars. In short, a metabar is a conditional combination of several consecutive bars into a large one. This is similar to a bar of a higher timeframe, but not exactly, since the size of the metabar is not fixed (it "floats" in a given range) and there is no binding to a specific start and end time of the bar. Therefore, the use of metabars allows traders to detect various patterns of candlestick analysis much more often.


Sergey Golubev  

How to Trade Spinning Tops and Doji Candlestick Patterns


In our last lesson we learned how different candlestick formations can tell us different things about whether the buyers or the sellers won out in a particular time period. In today's lesson we are going to look at some of the basic candlestick patterns and what they mean when looked at in the context of recent price action in the market.

The Spinning Top

When a candlestick with a short body in the middle of two long wicks forms in the market this is indicative of a situation where neither the buyers nor the sellers have won for that time period as the market has closed relatively unchanged from where it opened. The upper and lower long wicks however tell us that both the buyers and the sellers had the upper hand at some point during the time period the candle represents. When you see this type of candlestick form after a runup or run down in the market it can be an indication of a pending reversal as the indescision in the market is representative of the buyers loosing momentum when this occurs after an uptrend and the sellers loosing momentum after a downtrend.

The Doji

Like the Spinning Top the Doji Represents indecision in the market but is normally considered a stronger signal because unlike the spinning top the open and the close that form the Doji Candle are at the same level. If a Doji forms in sideways market action this is not significant as the sideways market action is already indicative of indecision in the market. If the Doji forms in an uptrend or downtrend this is normally seen as significant as this is a signal that the buyers are loosing conviction when formed in an uptrend and a signal that sellers are loosing conviction if seen in a downtrend. Most traders will place greater significance on the Doji when it forms in a market that is in overbought or oversold territory.

The Bullish Engulfing Pattern

The Bullish Engulfing pattern is another candlestick formation which represents a potential reversal in the market when seen in a downtrend. The pattern is made up of a white and black candle where the latest candle (the white candle) opens lower than the previous candle's (the black candle) close and closes higher than the previous candle's open. When this happens the current period's white candle completely engulfs the previous period's black candle.

When thinking about this from a buyer/seller perspective, you can understand that the long body of the current candle engulfing completely the body of the previous candle to the upside is representative that the buyers have not only taken control but have taken control with force. When this white engulfing candle occurs after a small black candle the formation is given even more significance as the small black candle is already indicative of a trend that is running low on steam.



Reason: