작업 종료됨
![](https://c.mql5.com/i/avatar/avatar_na2.png)
명시
Hi
I want a very CLEAN BASIC Martingale code as follows:
A - INPUTS
1. Initial Lots
2. Lots for Positions 2 to 5
3. Lots for Positions 6 to 10
4. Distance in points to open Position 2 to 5 (from each previous position price)
5. Distance in points to open Position 6 to 10 (from each previous position price)
6. Dropdown for "Sell Only", "Buy Only", "Buy and Sell at the same time"
7. Take Profit in points (not pips)
B - WORKINGS
1. It must always trade. First trades must always be either a buy, sell or both depending on input selected
2. Then it must Martingale from there as per the inputs. It must always place the next order as a pending order in the system. As it triggers, the next pending order goes in and so on.
3. VERY IMPORTANT - The EA must continuously recalculate the average cost of all buy and sell positions separately (Total cost/Total lots for "buy" = average cost for "BUY") and (Total cost/Total lots for "sell" = average cost for "SELL")
4. The take profit in points added to the average price of "SELL" and "BUY" must be sent as a pending order immediately - BUY positions and SELL positions separately.
5. Once BUY or SELL positions gets closed with take profit, it must immediately open either a buy or sell again and start over.
C- EXAMPLE
Buy EURUSD at 1.09000 for 1 lots with 100 points take profit and 100 points distance to Martingale (Assume all trades at 1 lot and 100 distance BUT obviously it must work as per the inputs I mentioned above where it will be different for trades 2 to 5 and 6 to 10)
1. EA Immediately puts 1.09100 as TP order and another pending buy order at 1.08900
2. Price goes down to 1.08900 the EA opens another BUY as per the pending order. The EA now immediately puts another buy at 1.08800. At the same time the EA also now recalculates the two open positions cost which is ((1.09000x1) +(1.08900x1))/2 = 1.08950. The EA deletes the previous TP (1.09100) in the system and updates it to 1.09050 (1.08950 new average cost plus 100)
3. Price goes down to 1.08800 the EA opens another BUY as per the pending order. The EA now immediately puts another buy at 1.08700. At the same time the EA also now recalculates the three open positions cost which is ((1.0900x1) +(1.08900x1)+(1.08800x1))/3 = 1.08900. The EA deletes the previous TP (1.09050) in the system and updates it to 1.0900 (1.08900 new average cost plus 100)
4. Price goes to 1.0900 and take profit kicks in. EA immediately starts again.
5. The same principles applies for SELL trades (If I selected buy and sell at the same time)