Building an Expert Advisor to manage a manually drawn trend line
The FX TrendLine Plug-in can monitor any trend line on a chart. It does this by searching for a trend line by name.
After you manually draw your trend line on your price chart, record the exact name of the trend line. This name will be referenced in your Expert Advisor by the fnIsTrendLineBroken.
To build an Expert Advisor that opens a BUY trade when a trend line has been broken, drag and drop the TrendLine function fnIsTrendLineBroken on to the OpenBuyOrder drawing pad and connect it before the Logic element IsOpenBuyTrue.
Set the parameters of the fnIsTrendLineBroken function:
- name: set the value of the name parameter to the exact name of the trend line. For example "mytrendline".
- type: set the value of the type parameter to the direction to test for the trend line break, either FROM_ABOVE or FROM_BELOW.
- price: set the value of the price parameter to one of the price constants, or Bid or Ask.
- shift: set the value of the shift parameter to the index value of the candle (or bar) to test for the break.
- Normally, the shift value is set to 0 and the price value is set to Bid or Ask. This will test the latest price against the trend line on the far right edge of the chart.
- Alternatively, any candle on the chart can be tested for a break.
After connecting and configuring the fnIsTrendLineBroken function, configure the IsOpenBuyTrue Logic element to test for the break. The function IsOpenBuyTrue returns a value of true if/when the line is broken.
The full OpenBuyOrder drawing is shown below.