Termos de Referência
Project Overview
I need assistance coding a hedging Expert Advisor (EA) that operates in "closed cycles" with a strict limit of five simultaneous open positions.
EA Logic & Mechanism
-
Initial Entry:
-
Open a Buy position of 0.01 lots (Position A) with a Take Profit (TP) target of $1.00.
-
-
Scenario 1: Price Drops (Hedging Step 1):
-
If the price moves against the first trade, open two positions simultaneously: a Sell 0.02 (Position B) and a Buy 0.01 (Position C).
-
If the price continues to drop and hits the TP, close positions A and B. Position C remains open.
-
Immediately open two new positions at that level: a Sell 0.02 (Position F) and a Buy 0.01 (Position G).
-
-
Scenario 2: Price Reverses (Expanding the Hedge):
-
If the price reverses back up before hitting the TP in Scenario 1, open two additional positions: a Buy 0.01 (Position D) and a Sell 0.01 (Position E).
-
Maximum Limit: At this point, there are 5 open positions. The EA must not open any further trades until some are closed.
-
-
Cycle Completion & Reset:
-
If the price goes up: Close four positions (A, B, C, and D) at the TP. Keep Position E (Sell) open. Then, open a Buy 0.02 (Position I) and a Sell 0.01 (Position J) to restart the cycle.
-
If the price goes down: Apply the same logic in the opposite direction.
-
Continuity: The EA must ensure there is always at least one active position open to keep the cycle moving.
-
Technical Parameters & Risk Management
To ensure the EA is flexible and robust, please incorporate the following settings and logic:
-
Adjustable Inputs: * The Lot Size, Grid Distance (pips), and Take Profit (TP) amount must be user-defined variables.
-
Fixed Ratios: While the base lot size can change, the ratio between Buy and Sell positions must remain fixed as per the logic above.
-
-
Cycle Reset Logic:
-
A new cycle should only begin after at least four positions from the previous cycle have been closed.
-
To ensure smooth execution and avoid overlapping errors, the TP for these closing positions should be set at $0.90 instead of $1.00.
-
Note: Pending orders must remain fixed at the initial 10-pip distance, regardless of the TP adjustment.
-
-
Slippage & Execution:
-
In the event of price slippage, the EA must prioritize closing the trades and placing the pending orders at the pre-calculated levels.
-
The EA should execute the close even if the final profit is slightly less than $1.00 or results in a small loss due to market gaps.
-
-
Safety Features:
-
Equity Protection: Include a Total Drawdown Stop Loss (either in currency or percentage) that closes all positions and stops the EA if a specific loss limit is reached.
-
Developer Suggestions: I am open to suggestions regarding error handling (e.g., requotes or connection timeouts) and optimizations for faster execution.
-
.