Specifiche
I need a bot that would buy or sell, then open a hedge if the trade is losing
Create a hedging Expert Advisor (EA) in MQL5 for MetaTrader 5, which persistently opens counteracting trades based on the outlined logic, with features that manage the initiation and oversight of these trades, adhering to the defined multipliers for position sizes. The EA will terminate all trades once it achieves a collective take profit target.
Design of the Hedging EA:
1. Initialization: Establish initial settings, the base lot size, profit targets, trade type and the multiplier for escalating trades.
- Two different sort of inputs for multipliers: first multiplier and subsequent multiplier
- The hedging trades would be pending orders added one by one, created as soon as the previous one is traded,. so we only need to have one pending order at a time
2. Opening Initial Trades: Execute an opening buy or sell order according to the strategy's guidelines.
3. Hedging Logic: - If the first trade is a buy, then the initial hedge will be a sell. following hedges will switch directions (sell after buy, buy after sell), with the lot size of each new hedge doubling that of the one before.
- If the first trade reaches tp, close and start all over again in the direction of the win
- If the first trade reaches hedge distance, trigger a new trade in the opposite direction with the first multplier
4. Monitoring for Take Profit: - Constantly track the aggregate of all open trades. - Liquidate all positions when the total profit meets the pre-set take profit threshold.
5. Out of Margin option (Enable/Disable): Average all profitable vs losing trades and close them. - restart hedge on the remaining losing trade as per step 2
6. Need a trade panel for to show all the positions and balances.
Input
- Lots size
- Overall take Profit (Amount)
- Trade type: Buy/Sell
- Magic Number
- Hedge Distance (Amount)
- First Trade Multipliers
- Subsequent Multipliers
- <:Display Panel Settings:>
Kindest Regards