View Single Post
  #5 (permalink)  
Old 06-03-2006, 05:11 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Quote:
Originally Posted by timbo
Hi CG.... it was very interesting reading your tutorial, but I still don't understand exactly how to tell Metatrader to buy or sell a different currency from the one the EA is attached to. Would it be possible for you to post an example of some code that does this? For example, when the EA is attached to EUR/USD, how do I tell it to buy USD/CHF at the current Ask price?

Originally I tried:

OrderSend("USDCHF", OP_BUY, Lots, Ask, 3, StopLoss*Point, TakeProfit*Point, "UC", 55555, 0, Green)

which didn't work. Is this because I didn't use the ibars Function first, or have I got the code completely wrong?

Can you, or anyone else help with this?

Tim
Hi Tim,

I think you are in a hurry and can not wait for the part 2 of the article, So take the temporarily answer:

To open an "USDCHF" (or any another pair) for an EA that hosted on "EURUSD" chart (or any another pair) you have to use code like this:

PHP Code:
if(Buy==true//buy conditions have been met
      
{
         
RefreshRates();
         
OrderSend("USDCHF",OP_BUY,Lots,MarketInfo("USDCHF",MODE_ASK),Slippage,MarketInfo("USDCHF",MODE_ASK)-StopLoss*Point,MarketInfo("USDCHF",MODE_ASK)+TakeProfit*Point,ExpertComment,MagicNumber,0,Green);
        }
      if(
Sell==true//sellconditions have been met
      
{
         
RefreshRates();
         
OrderSend"USDCHF",OP_SELL,Lots,MarketInfo("USDCHF",MODE_BID),Slippage,MarketInfo("USDCHF",MODE_BID)+StopLoss*Point,MarketInfo("USDCHF",MODE_BID)-TakeProfit*Point,ExpertComment,MagicNumber,0,Red);
         } 
In the part 2 of the article you'll know what does the above code mean!
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Reply With Quote