Forex
Google

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-15-2006, 11:49 AM
timbo timbo is offline
Junior Member
 
Join Date: Nov 2005
Posts: 14
timbo is on a distinguished road
Possible to trade different currency than the one EA is attached to?

Hi guys,

Wondering if anyone can help me out - I'm trying to write an EA that will be attached to the EURUSD chart, but want it occasionally to place a USDCHF trade as well as the EURUSD ones. Is this possible? I tried the following code:

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

But I kept getting the message "unknown symbol name USDCHF for OrderSend function". Is this because the EA is attached to the EURUSD chart? And is there any way to tell the EA to buy a different currency (and then later to close it)?

Any suggestions would be very appreciated! (Oh, and does anyone know of an EA that does this? I find it helpful to look at the code of working EA's when I'm struggling with a problem.)

Tim
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-15-2006, 12:14 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
Wink

Quote:
Originally Posted by timbo
Hi guys,

Wondering if anyone can help me out - I'm trying to write an EA that will be attached to the EURUSD chart, but want it occasionally to place a USDCHF trade as well as the EURUSD ones. Is this possible? I tried the following code:

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

But I kept getting the message "unknown symbol name USDCHF for OrderSend function". Is this because the EA is attached to the EURUSD chart? And is there any way to tell the EA to buy a different currency (and then later to close it)?

Any suggestions would be very appreciated! (Oh, and does anyone know of an EA that does this? I find it helpful to look at the code of working EA's when I'm struggling with a problem.)

Tim
Tim,

I'm writing right now an article about this issue, please check it at:

http://www.metatrader.info/node/124
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-15-2006, 12:44 PM
timbo timbo is offline
Junior Member
 
Join Date: Nov 2005
Posts: 14
timbo is on a distinguished road
Quote:
Originally Posted by codersguru
Tim,

I'm writing right now an article about this issue, please check it at:

http://www.metatrader.info/node/124
Thanks CG! You're such a helpful guy..... I've really appreciated all the hard work you put into those Metatrader lessons, and they have been a great help to me!

I look forward to reading the article when it's ready

Tim
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-03-2006, 11:20 AM
timbo timbo is offline
Junior Member
 
Join Date: Nov 2005
Posts: 14
timbo is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 06-04-2006, 11:57 AM
timbo timbo is offline
Junior Member
 
Join Date: Nov 2005
Posts: 14
timbo is on a distinguished road
Quote:
Originally Posted by codersguru
In the part 2 of the article you'll know what does the above code mean!
Ooh.... thanks CG..... looking forward to it, and I'll try to be more patient!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-04-2006, 12:54 PM
timbo timbo is offline
Junior Member
 
Join Date: Nov 2005
Posts: 14
timbo is on a distinguished road
Hey CG..... I just found your article on Hedging which helped with my original question(and helped me understand the code snippets below), but when I try to backtest your Hedging.mq4 EA I get an error message saying "invalid price for OrderSend function" when it tries to place the USDCHF order. Do you know why this is happening?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-05-2006, 12:46 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
Arrow Trading is permitted for the symbol under test only

Quote:
Originally Posted by timbo
Hey CG..... I just found your article on Hedging which helped with my original question(and helped me understand the code snippets below), but when I try to backtest your Hedging.mq4 EA I get an error message saying "invalid price for OrderSend function" when it tries to place the USDCHF order. Do you know why this is happening?
It's a limitation in MT BackTesting:

Trading is permitted for the symbol under test only, no portfolio testing Attempts to trade using another symbol will return error

Please review this article:
http://articles.mql4.com/72


So, this kind of program have to forward tesing only!
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-06-2006, 11:55 AM
timbo timbo is offline
Junior Member
 
Join Date: Nov 2005
Posts: 14
timbo is on a distinguished road
Thanks again for your help CG... the Hedging article really helped me understand the concept of instructing the EA to buy/sell other currencies!!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Easiest Currency Pair to Trade yyc196 General Discussion 12 04-03-2007 02:06 PM
Trade muliple currency Pairs rbowles Metatrader 4 5 08-13-2006 05:51 AM
Why EA is not working when attached josephine General Discussion 5 03-04-2006 06:47 PM


All times are GMT. The time now is 10:59 AM.