- Introduction to Bollinger Bands Sell Trailing Stop Expert Advisor (00:00 – 00:13)
- Introduction to creating an expert advisor in MQL5 for moving a sell trailing stop based on the upper Bollinger band.
- Opening MetaEditor and Creating New File (00:13 – 00:39)
- Instructions on opening MetaEditor from MetaTrader and creating a new expert advisor file named ‘Simple Bollinger Bands Sell Trailing Stop.’
- Setting Up the Expert Advisor (00:39 – 01:03)
- Removing unnecessary lines and including the ‘trade.mqh’ file for trading functions.
- Creating an instance of the CTrade class for trading operations.
- Initializing Variables and Prices (01:03 – 01:48)
- Creating a static double variable for the last stop Bollinger bands value.
- Calculating the ask and bid prices using ‘SymbolInfoDouble.’
- Creating Test Position and Setting Initial Value (01:48 – 02:27)
- Selling a test position if no positions are open.
- Setting an initial high value for the last stop Bollinger bands value.
- Defining Bollinger Bands Arrays (02:27 – 03:59)
- Creating upper and lower band arrays and sorting them.
- Defining Bollinger bands parameters and filling arrays with ‘CopyBuffer.’
- Implementing Trailing Stop Conditions (03:59 – 04:44)
- Checking conditions for moving the sell trailing stop based on the upper band value.
- Updating the last stop Bollinger bands value.
- Creating Function to Check Bollinger Sell Trailing Stop (04:44 – 06:44)
- Defining a user-defined function to modify the position’s stop loss.
- Looping through open positions and adjusting the stop loss based on Bollinger band values.
- Compilation and Testing in MetaTrader (06:44 – 07:56)
- Instructions on compiling the expert advisor and fixing any errors.
- Testing the expert advisor in MetaTrader using the Strategy Tester.
- Conclusion and Additional Resources (07:56 – 08:00)
- Recap of the tutorial and its purpose.
- Invitation to explore more videos and courses for further learning.
In this tutorial, we delve into the creation of an Expert Advisor (EA) that’s designed to move a sell trailing stop based on the upper Bollinger Band. Here’s a step-by-step guide on how to achieve this using MQL5:
- Initialization: Start by clicking on the small icon or pressing F4 on your keyboard. This action will bring up the Metaeditor window.
- File Creation: Navigate to File, select New File, then choose Expert Advisor from the template. Continue and name this file “simple bollinger bands sell trailing stop”.
- Code Cleanup: For a clean slate, remove everything above the
ontickfunction, including the two comment lines.
- Include Essential Files: It’s crucial to include the
trade dot mqhfile. This file equips us with basic trading functions essential for our EA.
- Variable Declaration: Within the
ontickfunction, declare a static double variable named “last stop bollinger bands value”. This will be pivotal later when we move our trailing stop and need to compare the current value with the last known value.
- Price Calculation: Accurately determine the Ask and Bid price. This is crucial for any trading operations.
- Position Verification: To move our sell trailing stop, it’s essential to have a test position in place. This ensures that our EA operates under real trading conditions.
- Array Creation: Construct an upper and a lower band array. These arrays will hold values that the Bollinger Bands indicator generates.
- Bollinger Bands Definition: Use the integrated
ibandsfunction to define the Bollinger Bands. This function calculates the upper, middle, and lower bands based on historical price data.
- Array Population: With the
Copy Bufferfunction, populate your array according to the Bollinger Bands definition you’ve set. This function copies the indicator data into the array.
- Condition Setting: Implement conditions to inspect the Bollinger sell trailing stop. This is where the logic of when and how to move the trailing stop is determined.
- Custom Function Creation: Craft a user-defined function to scrutinize the Bollinger sell trailing stop. This function will contain the logic and conditions under which the trailing stop should be adjusted.
For those unfamiliar with the intricacies of the code or if the tutorial seemed too rapid, it’s advisable to consult other videos in this foundational series. Additionally, the premium course available on the website offers a more in-depth exploration of this topic.