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*Point,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

 
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*Point,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

 
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

 

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

 
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:

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!

 
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!!

 

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?

 

Trading is permitted for the symbol under test only

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 testingAttempts to trade using another symbol will return error

Please review this article:

https://www.mql5.com/en/articles/1512

So, this kind of program have to forward tesing only!

 

Thanks again for your help CG... the Hedging article really helped me understand the concept of instructing the EA to buy/sell other currencies!!

 

Help modifying Escape 3 ea

I have been working on modifying an ea called Escape 3 to trade 2 currency pairs at once. My strategy is to trade pairs that are negatively correlated. Right now I am working on GBPUSD AND USDJPY. This EA was intended to place on the GBPUSD chart and when a GBPUSD trade is triggered it will do the opposite with USDJPY. I have used some of the code on this thread however it becomes evident I need help since it doesnt compile properly. While compiling I get an error "unbalenced left parenthesis". Once that error is fixed I would like to be certain the ea will close open USDJPY positions as well once desired profit target is reached. This is not my EA I am only changing code that is available for free on this forum.

Here is the code:

Files:
 

hey

codersguru:
It's a limitation in MT BackTesting:

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

Please review this article:

Testing Features and Limits in MetaTrader 4 - MQL4 Articles

So, this kind of program have to forward tesing only!

I have been trying to get to you for a while now but your storage box is filled up so you cant recieve new messages, can you let me know where to reach you to or you could drop me a line to k o l a y 2 k _ 2 at yahoo.com

Thanks.

Reason: