I am trying to build a hedging EA, buying 4 different pairs. When I attach it to a chart, say EURUSD, and try to run it, it will only open the EURUSD order and none of the others. How do I get this to open all 4 orders? I have attahced the code.
I am not sure you can do that.
Anyway, you have to use the price of the specified symbol, you cannot use the same Bid or Ask for all ! So use MarketInfo() for all is regarding a pair other than the one of the chart.
I've seen it done with other EAs but you are right about Bid and Ask. maybe that's why it failed although the error was invalid symbol. There should be a way. The OrderSend just expects a string.
I've seen it done in other EAs and OrderSend just expects a string. You are right about MarketInfo(). Maybe that's the problem, but the error says invalid symbol.
I've seen it done in other EAs and OrderSend just expects a string. You are right about MarketInfo(). Maybe that's the problem, but the error says invalid symbol.
May it be the "m" suffix on IBFX mini accounts ?
Did you try on a demo account or only in the backtester ?
I think you should be able to open orders on other symbol on an account, but not in the backtester.
See Testing Features and Limits in MetaTrader 4
Attempts to trade using another symbol will return error
I am trying to build a hedging EA, buying 4 different pairs. When I attach it to a chart, say EURUSD, and try to run it, it will only open the EURUSD order and none of the others. How do I get this to open all 4 orders? I have attahced the code.
bhale.
Use the MarketInfo() function instead of using bid and ask.
OrderSend("EURUSD",OP_BUY,EurUsdLots,MarketInfo("EURUSD",MODE_ASK),0,0,0,NULL,12345,0,CLR_NONE);
Modified code attached.
Hope this helps.
fxd01
bhale.
Use the MarketInfo() function instead of using bid and ask.
OrderSend("EURUSD",OP_BUY,EurUsdLots,MarketInfo("EURUSD",MODE_ASK),0,0,0,NULL,12345,0,CLR_NONE);
Modified code attached.
Hope this helps.
fxd01And of course, as Michael mentioned, add "m" suffix (ie. EURUSDm) if you are using IBFX mini a/c
Yeah thanks guys. You are right. The change worked but it won't work in the Strategy Tester, so have to do this on on forward test only. Right now the problem with this is it doesn't get the profit loss right. OrderProfit() returns zero all the time. If I can get this calculation working, then this EA will buy the four pairs and when it reaches profit target, close them out and reopen. So far just doing it manually has brought some large wins on a full lot, with very little drawdown since it is a dollar hedge. Many days, the $150 target is reached 4 or 5 times. If I do nothing it can reach $400 to $500.
Yeah thanks guys. You are right. The change worked but it won't work in the Strategy Tester, so have to do this on on forward test only. Right now the problem with this is it doesn't get the profit loss right. OrderProfit() returns zero all the time. If I can get this calculation working, then this EA will buy the four pairs and when it reaches profit target, close them out and reopen. So far just doing it manually has brought some large wins on a full lot, with very little drawdown since it is a dollar hedge. Many days, the $150 target is reached 4 or 5 times. If I do nothing it can reach $400 to $500.
You cannot use Profit(), but you can use something like this for a buy:
Profit = MarketInfo(yoursymbol, MODE_TICKVALUE)*OrderLots()*(MarketInfo(yoursymbol, MODE_BID) - OrderOpenPrice())/MarketInfo(yoursymbol, MODE_POINT);
Profit() does work
You cannot use Profit(), but you can use something like this for a buy: Profit = MarketInfo(yoursymbol, MODE_TICKVALUE)*OrderLots()*(MarketInfo(yoursymbol, MODE_BID) - OrderOpenPrice())/MarketInfo(yoursymbol, MODE_POINT);
No, the original OrderProfit() does work.
There is however another small glitch which is causing the Profit not to work:
You have double defined the Ticket variables: once global and the 2nd time in the Buy() function
Just remove the "int" in the Buy function and Profit will work.
(Otherwise the ticketnumbers will remain local and not be known globally to be used for the other functions)
Put: Comment("Current profit: ", pl); in the TotalProfit() and you will see it updated in the upperleftcorner of your screen.
Just one other question:
How do you determine the right Lots for these 4 different currencypairs?
Is this a one time correlation or does it need to be changed overtime?
Cheers
Herbert
- 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 am trying to build a hedging EA, buying 4 different pairs. When I attach it to a chart, say EURUSD, and try to run it, it will only open the EURUSD order and none of the others. How do I get this to open all 4 orders? I have attahced the code.