How to create a trend sell stop with MQL5

video
play-sharp-fill

 

  • Introduction and Objective:
    • The tutorial covers the concept of placing a sell stop order based on a detected downward trend. The goal is to create an expert advisor that automatically sets a sell stop order when a short trend is identified.
  • Initial Setup in MetaEditor:
    • Users are directed to open the MetaEditor and initiate a new file named “simple sell stop”.
  • Array Creation and Initialization:
    • Two arrays, “mypricearray0” and “mypricearray1”, are created to store price data for the last three candles.
    • The copyrates function is used to populate these arrays with the required data.
  • Trend Detection Logic:
    • The tutorial provides logic to determine if the current trend is downward by comparing the value of the current candle to the previous one. If the trend is downward (value is negative), it’s identified as a short trend.
  • Sell Stop Logic:
    • The expert advisor checks if there are no other open positions or orders. If none exist, it places a sell stop order. The sell stop is set to trigger when the price crosses a specific line below the current price.
  • Testing and Visualization:
    • After coding, users are shown how to test the functionality in MetaTrader using the strategy tester. The visual mode displays the expert advisor in action, showing the placement of sell stop orders based on detected short trends.
  • Conclusion and Further Learning:
    • The tutorial demonstrates how to create an expert advisor that places sell stop orders based on detected short trends. This automated approach allows traders to capitalize on potential market downturns without manual intervention.

By following this tutorial, users can effectively set up an expert advisor that places sell stop orders in response to detected short trends, streamlining their trading process.


Video Timestamps

  • 0:00 – Introduction to the video topic: triggering a sell stop during a downward trend.
  • 0:30 – Explanation of the sell stop and its activation when a short trend is detected.
  • 1:00 – Steps to create an Expert Advisor in MetaEditor for the sell stop.
  • 1:30 – Setting up the Expert Advisor, naming it, and initializing the code.
  • 2:00 – Including the necessary library and creating an instance for trading.
  • 2:30 – Defining the array for prices and using a simple moving average.
  • 3:00 – Further details on the moving average and its calculation.
  • 3:30 – Getting the bid price and ensuring the correct number of digits.
  • 4:00 – Calculating the long-term trend and its significance.
  • 4:30 – Conditions to open a sell stop position and ensuring no other orders or positions exist.
  • 5:00 – Code to open the sell stop position and its parameters.
  • 5:30 – Compiling the code and testing it in MetaTrader.
  • 6:00 – Observing the Expert Advisor in action and its results.

1. What is the main focus of the tutorial?

  • The tutorial covers the concept of placing a sell stop order based on a detected downward trend. The aim is to automate the process of setting a sell stop order when a short trend is identified.

2. How can users access the MetaEditor for coding?

  • Users are directed to open the MetaEditor and initiate a new file named “simple sell stop”.

3. What is the purpose of the “simple sell stop” file in MetaEditor?

  • The “simple sell stop” file is initiated within the MetaEditor to code and develop the expert advisor that automatically sets a sell stop order when a short trend is detected.

4. How are the arrays named “mypricearray0” and “mypricearray1” utilized in the tutorial?

  • The arrays “mypricearray0” and “mypricearray1” are designed to store price data for the last three candles. They are populated using the copyrates function.

5. How does the tutorial detect a downward trend?

  • The tutorial provides logic to determine if the current trend is downward by comparing the value of the current candle to the previous one. If the trend is downward (value is negative), it’s identified as a short trend.

6. Under what conditions does the expert advisor place a sell stop order?

  • The expert advisor checks if there are no other open positions or orders. If none exist, it places a sell stop order. The sell stop is set to trigger when the price crosses a specific line below the current price.

7. How can users test the functionality of the sell stop expert advisor?

  • After coding, users are shown how to test the functionality in MetaTrader using the strategy tester. The visual mode displays the expert advisor in action, showing the placement of sell stop orders based on detected short trends.

8. What is the significance of placing a sell stop order based on detected short trends?

  • Placing a sell stop order based on detected short trends allows traders to capitalize on potential market downturns without manual intervention, making the trading process more efficient.

9. What can users achieve by following this tutorial?

  • By following this tutorial, users can effectively set up an expert advisor that places sell stop orders in response to detected short trends, streamlining their trading process.