Hi all,
I’ve been racking my brains trying to figure this out for myself, but even with days of googling I just can’t manage to sus it.
I’m trying to create an EA that utilises a manually drawn horizontal line to open a buy/sell order. There is more to it than that, but it is the horizontal line that I can’t figure out.
Basically, I’m hoping someone here can help me by providing a simple piece of code that will let me manually place a horizontal line on to a chart, and then will do the following -
- Can be used in stratergy tester mode.
- Looks for a horizontal line named “buy” or “sell”
- If the close of the most recent candle is above the line named “buy” it will open a buy order.
- If the close of the most recent candle is below the line named “sell” it will open a sell order.
- User input externs are - lot size, SL size, slippage size.
- I need to be able to move the line about as price moves, until such a time as I can leave the line in place and let a candle close beyond it.
It’s been driving me crazy with frustration not being able to get past this small piece of the code, and if someone can help I really will be most grateful!
Many thanks for your time.
Cord
I think this might be something you could adapt. It uses a trendline, but you can make a trendline horizontal too. Or you could tinker with the code to change it to a horizontal line.
Hope it helps
TrendMeLeaveMe - MQL4 Code Base
Thanks sweetpip.
I found that ea before, but never with a guide on how to actually use it! I’ll plug away and see if I can convert it to my needs.
Most appreciated!
Cord
It’s pretty straight forward. You need to draw a trendline and name it either buystop or sellstop. When price gets in the zone close to the line, it sets a pending buy or sell order for how ever many pips outside the line break you set…for buys this is the [B]buystop_stepupper[/B] parameter, and for sells it’s the [B]sellstop_steplower[/B] parameter. Meaning for example you want the order to trigger 5 pips past the break of the line.
As price walks up or down the line, it modifies the pending order’s trigger price. Therefore the trigger price will always match the price at the line when price eventually crosses the line.
I modified it so it wouldn’t open any orders and instead just alerts me when it’s at the trendline. Then [B]I[/B] could decide to open an order based on other factors.