Cross Trend Line to Trade MT5
- Utilities
- Ziheng Zhuang
- Version: 10.2
- Updated: 30 October 2023
- Activations: 10
This EA provides the following functions:
- Open a position: When the price crosses the trend line, open a long or short order
- Closing: When the price crosses the trend line, close the long or short position
- Trailing stop loss: EA will continue to increase the stop loss of long orders or lower the stop loss of short orders along the trend line.
- The line can be a trend line or a horizontal line, Trend lines can be rays or line segments. Line segments have a special function, which is to only trade within the period where the line is located.
- These lines that can open and close positions are all lines with specific names. EA provides a line drawing panel to replace manual line drawing.
- All open and closed positions will have screenshots saved in the MQL5/Files/Cross Trend Line to Trade folder.
The EA only works on hedging account
MT4 Version: https://www.mql5.com/en/market/product/4439
Line drawing panel:
- Click the green "+" button, and 6 groups of panels will be generated one by one. Each group of panels can click the corresponding button to draw trend lines or horizontal lines.
- Click the purple button to select the line type: Trend Line or Horizontal Line
- Click Del to delete all drawn lines
- Click the X to close the panel and return to the original state.
- Clicking buttons B1, B2, B3, B4, and B5 will draw five lines. When the price crosses any of these five lines, a long order will be opened.
- Clicking the buttons S1, S2, S3, S4, and S5 will draw five lines. When the price hits any of these five lines, a short order will be opened.
- For a detailed description of the names and functions of all trend lines, please read below.
Trend line names and functions:
- Open long: B1, B2, B3, B4, B5 - When the price crosses any of these five lines, a long order will be opened. Only one order can be opened for each line at a time. The order will have special comments containing the name of the line to avoid repeated opening of positions on the same line.
- Open short: S1, S2, S3, S4, S5 - these 5 names are used to open short orders. Just like opening a long position above, only one order can be opened per line.
- Close all long orders: Cls-Buy-All-1, Cls-Buy-All-2, Cls-Buy-All-3. When the price crosses any of these 3 lines, all long orders will be closed.
- Close all long and short orders: Cls-All-1, Cls-All-2, Cls-All-3. When the price crosses any of these 3 lines, all long and short orders will be closed.
- Close all short orders: Cls-Sell-All-1, Cls-Sell-All-2 , Cls-Sell-All-3, when the price crosses any of these 3 lines, all short positions are closed.
- Close all long orders with profit: Cls-Buy-Win-1, Cls-Buy-Win-2, Cls-Buy-Win-3. When the price crosses any of these three lines, all profitable long orders are closed. warehouse.
- Close all long orders with loss: Cls-Buy-Loss-1 , Cls-Buy-Loss-2 , Cls-Buy-Loss-3, when the price crosses any of these 3 lines, all losing long orders are closed.
- Close all short orders with profit : Cls-Sell-Win-1, Cls-Sell-Win-2 , Cls-Sell-Win-3, when the price crosses any of these 3 lines, all profitable short positions are closed.
- Close all short orders with loss: Cls-Sell-Loss-1 , Cls-Sell-Loss-2 , Cls-Sell-Loss-3 , if the price crosses any of these three lines, all short positions with losses will be closed.
- Close the long order with max. profit: Cls-Buy-WinMax-1, Cls-Buy-WinMax-2 , Cls-Buy-WinMax-3, when the price crosses any of these 3 lines, the long order with the largest profit will be closed, and that line will be deleted immediately to avoid repeated closings.
- Close the long order with max. loss : Cls-Buy-LossMax-1, Cls-Buy-LossMax-2 , Cls-Buy-LossMax-3, When the price crosses any of these three lines, the long position with the largest loss will be closed. , that line will be deleted immediately to avoid repeated closing.
- Close the short order with max. profit : Cls-Sell-WinMax-1, Cls-Sell-WinMax-2 , Cls-Sell-WinMax-3, when the price crosses any of these 3 lines, the short position with the largest profit will be closed. , that line will be deleted immediately to avoid repeated closing.
- Close the short order with max. loss: Cls-Sell-LossMax-1, Cls-Sell-LossMax-2 , Cls-Sell-LossMax-3, When the price crosses any of these 3 lines, the short position with the largest loss will be closed. , that line will be deleted immediately to avoid repeated closing.
- The earliest long order to close the position: Cls-Buy-First-1, Cls-Buy-First-2, Cls-Buy-First-3, when the price crosses any of these three lines, the long order with the earliest opening time will be closed. , that line will be deleted immediately to avoid repeated closing.
- The latest long order to close a position: Cls-Buy-Last-1, Cls-Buy- Last -2, Cls- Last -First-3 When the price crosses any of these 3 lines, the long order with the latest opening time will be closed.
- The earliest short order to close a position: Cls-Sell-First-1, Cls-Sell-First-2, Cls-Sell-First-3, when the price crosses any of these 3 lines, the short position with the earliest opening time will be closed. , that line will be deleted immediately to avoid repeated closing.
- The latest long order to close a position: Cls-Sell-Last-1, Cls-Sell- Last -2, Cls -Sell -First-3 - When the price crosses any of these 3 lines, the short position with the latest opening time will be closed. , that line will be deleted immediately to avoid repeated closing.
- Moving stop for long orders: TSB1, TSB2, TSB3 - trailing stop loss lines for long orders, these 3 lines are used for moving stop loss for long orders. When the market price is above the line, the stop loss for long orders moves to the line.
- Short order moving stop loss: TSS1, TSS2, TSS3 - short order tracking stop loss line, these 3 lines are used for moving stop loss short order. When the market price is below the line, the short stop is moved to the line.
Input parameter explanation:
1. Line-related settings
- Trend Line Style: Select the style of line you draw: Line Segment, Line Ray
- Select Line Role: Select the role played by lines B1, B2, B3, B4, and B5: Open Position (open a position) or Alert Only (only alarm, not open a position)
- B1 Lots: The opening lot number corresponding to line "B1".
- B2 Lots: The opening lot number corresponding to line "B2".
- B3 Lots: The opening lot number corresponding to line "B3".
- B4 Lots: The opening lot number corresponding to line "B4".
- B5 Lots: The opening lot number corresponding to line "B5".
- Select Line Role: Select the role played by lines S1, S2, S3, S4, S5: Open Position (open position) or Alert Only (only alarm, no position opening)
- S1 Lots: The opening lot number corresponding to line "S1".
- S2 Lots: The opening lot number corresponding to line "S2".
- S3 Lots: The opening lot number corresponding to line "S3".
- S4 Lots: The opening lot number corresponding to line "S4".
- S5 Lots: The opening lot number corresponding to line "S5".
2. Take profit and stop loss points, order number control, pop-up windows, emails, mobile phone push and other settings
- Magic Number: This is the magic number of EA, which is the code name of EA.
- Stop Loss In pips: When EA opens a position, it sets the stop loss price for the order according to this point parameter.
- Take Profit In pips: When EA opens a position, it sets the take profit price for the order based on this pip parameter.
- Max Buy Orders: The maximum number of long orders. In fact, up to 5 long orders may be opened because there are only 5 trend lines: B1, B2, B3, B4, and B5. Assuming this parameter is set to 2, when the price crosses any two lines, 2 orders will be opened, and no position will be opened even if it crosses other lines.
- Max Sell Orders: The maximum number of short orders. In fact, up to 5 short orders may be opened, because there are only 5 trend lines: B1, B2, B3, B4, B5. Assuming this parameter is set to 2, when the price crosses any two lines, 2 orders will be opened, and no position will be opened even if it crosses other lines.
- Delete Line After Trade: If set to true, the line will be deleted by the EA after a transaction (opening or closing a position) occurs.
- Trail Stop Level in pips (Buy Orders): A long order must make a profit of this pip before it can trail the stop loss. If this parameter is 0, it does not need to meet the profit pip level before it can trail the stop loss.
- Trail Stop Level in pips (Sell Orders): A short order must make a profit of this pip before it can follow the trailing stop. If this parameter is 0, it does not need to meet the profit pip before it can trail the stop.
- Popup Alert: When a position is opened or closed, a pop-up window will appear.
- Email Alert: When a position is opened or closed, an email reminder will be sent.
- Mobile Push Alert: When a position is opened or closed, a mobile phone push message will be sent to remind you.
3. Panel position and button size settings
- Shift X: Horizontal offset relative to the upper right corner of the chart
- Shift Y: Vertical offset relative to the upper right corner of the chart
- Button Width: button width
- Button Height: button height
- Font Size: Font size on the button
- The Overall Scale Ratio: The number of times the panel is enlarged or reduced
Other notes:
- Every time you start MT5 or load EA to the chart, the EA will pause for 3 seconds because the chart is being updated at the moment MT5 is started, so transactions should be avoided at this time.
- When the trailing stop loss parameter is 0, the stop loss follows the trend line.
- When the trailing stop loss parameter is greater than 0, only orders with profit points greater than the parameter value will move the stop loss following the trend line.
- The stop loss price for long orders will never retrace downwards
- The stop loss price of a short order will never retrace upwards
- In order to avoid unexpected trades caused by price crossing the trend line when the price gapped on Monday, it is recommended to delete the trend line on Friday or move the trend line to the left side of the chart.
//---