İş tamamlandı
İş Gereklilikleri
Hi,
I need to program the following trade management EA.
Trade methodology
Please refer to the attachment with 2 Excel files for the illustration of the trade logic
Here is a specific example for illustration of a 3-level order scenario. This can be replicated (as necessary) when more levels are triggered:
1) Level 1 trade - Place SELL stop ("Type of order") for [2.0] ("Starting lot") lots of USDJPY at [106.50] ("Price")
2) When Level 1 pending order is placed, set Target Profit at [5] pips ("Level 1 TP")
When Level 1 trade is triggered
3) When Level 1 trade is triggered, immediately place Level 2 BUY trade (opposite side as the Level 1 trade) [20] pips away ("Range"), i.e. BUY stop at [106.70] with a total of 2.0 + [2.0] ("Lot increment") = 4.0 lots.
4) Compute the new price that will allow both Level 1 & Level 2 trades to close at Breakeven + [x] pips profit ("TP of higher levels"), taking into consideration the commissions of all the trades ("Commissions per 1 standard lot").
5) Suppose this price is [106.95]. Set the TP of Level 2 trade to 106.95 and SL of Level 1 trade to 106.95 + [0.05] ("Bid-Ask Spread") = 106.955
When Level 2 trade is triggered
6) When Level 2 trade is triggered, immediately place Level 3 Sell trade (opposite side as the Level 2 trade) [20] pips away, i.e. Sell stop at [106.50] with a total of 4.0 + [2.0] ("Lot increment") = 6.0 lots.
4) Compute the new price that will allow Level 1, 2 and 3 trades to close at Breakeven + [x] pips profit ("TP of higher levels"), taking into consideration the commissions of all the trades ("Commissions per 1 standard lot").
5) Suppose this price is [106.25]. Set the TP of Level 1 and 3 trades to 106.25 + [0.05] ("Bid-Ask Spread")= 106.255. Set the SL of Level 2 Buy trade to 106.25. At this point, DO NOT adjust the TP of the Level 2 trade or the SL of the Level 1 trade yet as we need the market to move towards 106.95 price & hopefully, not trigger level 3 trade.
6) Cancel the pending order when the whole series of trades closes.
In summary, every time a new level is triggered, the next level of trade is immediately placed as a pending stop order. At this time, the next level trade TP is set and the SL of the existing trades that are in the opposite direction as the pending stop order are set to be the same as the next level TP (with bid-ask spread adjustment).
EA parameters
The EA should contain the following parameters for user input. These have been highlighted in bold in the above description
1) Price. User to set the price for the EA to place the order.
2) Type of order (Stop orders or Limit orders). Thus, if 106.50 is the Price set by the user and the current market price is above 106.50 and the user chooses LIMIT order, then the EA places a BUY LIMIT order at 106.50. If Stop order is chosen, then the EA places a SELL stop order at 106.50
3) Starting Lot (Set default to 2.0)
4) Level 1 TP (Set default to 5.0 pips)
5) Range (Set default to 20 pips)
6) Lot increment (Set default to 2.0 lots). This means for each level, the EA will add 2.0 lots to the previous lot size. In the default case, it shall be in 2,4,6,8,10,12... sequence
7) TP of higher levels (Set default to 2.0 pips) The EA needs to replicate the "GoalSeek" function in Excel to find breakeven price for the whole batch of trades. It should first round off to the nearest 5 decimal places for non-JPY pair & nearest 3 decimal places for JPY pairs for the breakeven price. Then, it should add the appropriate 2 pips to this breakeven price. This is assumed to be the "Bid" price and used to adjust the TPs/SLs of all BUY orders.
8) Commissions per 1 standard lot. The computation should take into account the commissions incurred by all the trades
9) Bid - Ask Spread (Set default to 1.0 pip). The computation should also take into account the assumed bid-ask spread. This bid-ask spread is used to adjust the SLs or TPs of all SELL orders (i.e. Bid Price + Bid-Ask spread).
The EA should automatically close the higher level pending order when the current series of trades is closed.
It should also have unique magic numbers for the series of trades. The user should be allowed to open another chart of the same pair to trade another price level by changing the magic number. The EA should prompt the user if the magic number is not changed and there are still existing trades of the same pair managed by the EA.
The EA should also be able to resume managing the same series of trades if the MT4 terminal is shut down and re-started after an interruption or after the weekend.