wow! thanks admin. Never really thought it would be possible to even attempt it. You've actually gotten most of it working but Its a bit tricky and am sure you can get it perfectly right with these further inputs from me.
First lets make some useful assumptions:
- Lets assume NO SPREAD, so ask is equal to bid.
- Its a hedging EA, but with some martingale function as to the lot sizing.
Now to get it right, I'll explain the strategy to you so maybe you can then translate it better into the programming.
Strategy:
Imagine you are sitting in from of the PC ready to trade manually. Your constants are:
TakeProfit = 10
Stoploss = 30
1.You place 2 pending orders (Buystop & Sellstop), 0.01 lot size 10 pips on either side of current market price (!this is because we do not know for sure which direction price would go & we don't care either).
-
When either one activates, you immediatly delete the other, that leaves you with just one open trade, but since we are also not certain for sure that price would go in our favor and hit the TP, we decide to place 2 pending orders of multiple lot sizes on the other side, one at 10pips from the entry price of the current open trade with 2X the lot size of the open trade (0.02), and the other at 20pips from the entry price of the current open trade with 4X the lot size of the open trade (0.04).
-
So incase price instead of going directly to hit the TP of the open trade, decides to go the negative way, upon 10pips below the open price of the current trade (say A1), our 0.02 lot size pending order would be activated and if keeps going that direction, it would hit TP after 10pips, at that point our 0.04 lotsize pending order would now be activated. And if price keeps going that way, then 10pips after, it would also hit the TP of our 0.04 lotsize trade which coincidentally is also the 30 pips stoploss of our very first trade to activate, which didnt go our way. When that happens, all trades are closed, so there wouldnt be any open trades left and we start allover again, this time from the initial lot size of 0.01 and 2 pending orders 10pips on either side of price.
In summary,
Imagine it was our BUYSTOP (A1) that had activated in the first place with lot size of 0.01, then we delete the other SELLSTOP (B1) and replace it with 2 other SELLSTOPS (B2 & B3), B2 is place at 10 pips from entry price of A1 with double the lot size of A1 which is 0.02, and B3 is placed 10 pips from B2, which is 20pips from A1, with double the lot size of B2 and quadripple the lot size of A1, which is 0.04.
So if things go negative on us and price goes down, when we are 10pips negative on A1, B2 would activate, and when we are 20pips negative on A1, B2 would have hit its TP of 10pips, and B3 would activate, and when we are 30pips negative on A1 which is also the stoploss of A1, B3 would have hit its TP of 10pips and ALL trades would have closed. Then the cycle can repeat itself again.
So strategically we would have lost say maybe 30 cents on A1 cos of 0.01 lotsize, but gained 20 cents on B2 cos of 0.02 lotsize, and 40 cents on B3 cos of 0.04 lot size. So when we do the maths, (40 + 20)-30 = 30 cents profit.
So even when price didnt go our initial upwards direction and lock in 10 cents profit for our 0.01 trade, we even made more profit on the reverse.
Remember all trades have same 10pips takeprofit and 30pips stoploss, its the LOT SIZING that does the MAGIC.
That is why it is SO IMPORTANT that if you can program it in such a way that before a new pending order is place, it checks what the lot size of the previously opened trade is and multiplies that by 2 to get the pending order placed at 10pips, and then by 4 to get the pending order placed at 20pips.
Conclusion.
You have already done a great job cos it places the orders as it should, you just need to modify it to place the right lotsizes, and also when you study the above strategy well, you would just realize clearly that the trades cycle does not carry on forever, cos even though on quite rangy markets, our lotsizes could grow large, there must be a point when there would be no open trades, that point where the stoploss of one trade equals the tp of the second opposing pending order, and thats when the cycle should start allover again from 0.01 lotsize.
Please do add this current information into the already made program you've done and lets see what the end product would be like. Thanks sooo much. Pls do ask if you need any information or further clarification. Thank you.
P.S. rather than make new cycle start by 00:00hrs, make it start immediately upon attaching EA to chart. Thank you.