Trabajo finalizado
Tarea técnica
I need an EA that open a first trade at market and simultaneously opens a pending order in the opposite direction at a distance to the open trade. This is how the EA will operate:
Trade will be managed in cycles in which there will be levels. A level is a trade and a cycle contains one or more levels. The first trade is level 1, second trade is Level2, etc
First trade:
Only the first trade needs any logic. Subsequent trades in a cycle depend on the point of first trade.
I use an oscillator to determine the first Buy/Sell. When the oscillator signals Buy, the first Buy trade will be fired in the cycle, thereafter, the oscillator is not used in the decision for the other trades in the cycle.
How to enter a trade
Buy:
1st Buy at market with TP = 30 pips and SL = 60 pips and simultaneously
Pending Sell (Sell Stop) 30 pips below market price TP = 30 and SL = 60 pips.
Scenario 1: If the first trade hits Take profit, that is the end of that cycle. The EA must wait for another trading opportunity.
Scenario 2: If the first trade moves down by 30 pips it will obviously hit the pending sell order. It means at this stage we will have a buy and a sell open. At that stage, a pending Buy Stop must be open 30 pips above current price with TP = 30 and SL = 60. If price moves down by 30 pips, the following things will happen
First trade will hit stop loss @ 60 pips
Second trade will hit take profit @ 30 pips
The Pending Buy Stop will not get filled and must be deleted
Scenario 3: In this scenario we have the first trade Buy, Second trade Sell and price has moved again to fill another Buy. It means we will have 2 buy open and one sell. At this point, a Pending Sell Stop must be opened 30 pips away from the most current order opened.
Scenario 4, etc: This cycle of opening a trade and simultaneously placing a pending order in the opposite direction must continue until all open orders have closed. At that stage, the cycle has bee completed and no pending order must exist for that currency pair anymore.
Correct working of this EA must ensure that once a trade in a cycle has hit Take profit, no other order (pending or open) must still be in existence. This is because the SL for Buy is the TP for Sell and vice versa. The EA must delete all open order for a pair once this is achieved.
In summary
If Level1 is a buy, then level2 must be a Sell then level 3 is a Buy and Level4 is a Sell, and so on
When the first entry is fired, level2 will be a pending order.
When Level 2 gets filled Level3 is pending
When Level 3 gets filled Level4 is pending
When Level4 gets filled Level5 is pending, etc
Lot size increment
Let the first lot size be a user input. It should increase using the following factor, x1 represents the first trade.
X1, x3,x6,x12,x24,x48,etc. Apart from the second trade which is 3 multiples of the one preceding it, the other trades will be double the one before it. By coding, this should increment to infinity
Entry prices
Apart from the first entry which is determined with Trix, subsequent prices must follow a pattern well defined like this:
Level 1, Level3,Level5, Level7, Level9,(every other level) must be the same prices both for entry, Take Profit and Stop Loss. Same also for Levels 2,4,6,8,etc.
Other Issues to take into consideration
Once a take profit is hit, pending order for that currency must be deleted.
A new cycle starts once a cycle closes in profit. Any other pending order for that pair at that time must be deleted.