It's more of a concept than specific code (although I do have some of that too), but I use MyMagicNumber * 100 as my base, and look for trades in range MyMagicNumber * 100 to MyMagicNumber * 100 + 99 for open trades
Range 00-49 is buy, 50-99 is sell.
I have 5 SL methods
0x or 5x = SL method 0 = trailing SL
1X or 6X = SL method 1 = SL of Hi/Lo last N bars
2X or 7X = SL method 2 = SL of last Peak/Trough etc.
This allows for up to 10 trades of any particular SL method.
The concept can be modified to allow say 100 trades for each of 100 SL methods.
In your case, I would write a 'GetNextAvailableMagicNumberForBuyWithStopLossType(int pStopLossMethod)" that scanned open orders.
Then again, there's nothing stopping you from having multiple orders with SAME MagicNumber - so long as you do not treat it like a unique key.
*WARNING* I understand that in the US you cannot have hedged trades (some long, some short) open at the same time, but I am not affected by that ;-)
*IDEA* If you want to be long & short at the same time, use a combination symbol (Long USDJPY, Short USDJPY via EURJPY & EURUSD). okay, you get 2 spreads, but it's allowed (I think)
I am also toying with the idea of using OrderComment to store extra information rather than MagicNumber, but am afraid that it might get clobbered my MT4 ("Last part of the comment may be changed by server.")
Oh dear, thanks for your help but I don't have a chance of coding that, any way you could provide the coding please?
Maybe it would be simpler if the EA just ignores any
existing open trades, i.e just leave them open, and then opens and
closes its own new single trade
At the moment it opens and closes its own trade, but it also closes any additional existing open trades
How could I code this?
extern int Magic = 12345; //rest of your code // by closing the orders if(OrderType()==OP_BUY && OrderSymbol()==Symbol()&& OrderMagicNumber()== Magic) { OrderClose(....); } if(OrderType()==OP_SELL && OrderSymbol()==Symbol()&& OrderMagicNumber()== Magic) { OrderClose(....); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have an EA that is now profitable but it opens a trade and closes a trade at the same time, so that only 1 trade is active at any one time.
I want to now run it on an existing account that has a few existing trades already open, I want to leave those trades running, yet have the EA continue opening and closing its own trade, as a side issue, when any of the existing trades become profitable, it then closes those.
This side request of closing the existing trades at profit can be ignored if that will keep it simple, I can close those manually if need be.
Here is what my EA uses at the moment