Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

forex - Open trade in different symbol than the one the EA runs in MQL4

So I want to open trades depending on multiple criteria with my EA... Doesn't really matter TBH...

The problem is that EAs run in one window. So naturally, I'd like for an EA to open assess conditions and open all the trades within one chart. Everything's fine except...

Broker won't allow an EA that runs in a chart open a trade on a different one.... It is surely that. I eliminated any other case.

Inputs just for this example:

input double LotSize = 0.01;

input int Slippage = 10;

input double StopLoss = 1000.0;

input double TakeProfit = 1000.0;

input const string SymbolA = "EURUSD";

input const string SymbolB = "GBPUSD";

The commands I use (I have them copy-pasted from another EA that works just fine so I am certain they work as well, plus I used extreme TP/SL to surpass any restrictions that brokers might have) :

       TicketA = OrderSend(SymbolA,OP_SELL,LotSize,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,EAComment,OrderTicket(),0,clrDarkRed);

       Sleep(1000);

       TicketB = OrderSend(SymbolB,OP_BUY,LotSize,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,EAComment,OrderTicket(),0,clrDarkBlue);

Error (EURUSD one opens normal as the EA runs in the EURUSD chart):

2020.12.18 01:01:45.318 '22644076': order buy market 0.01 GBPUSD sl: 1.21670 tp: 1.23670

2020.12.18 01:01:45.528 '22644076': order buy 0.01 GBPUSD opening at market sl: 1.21670 tp: 1.23670 failed [Invalid S/L or T/P]

Any suggestion how can I fix/bypass this?

Thanks in advance!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Obviously, you have to set a different open price, stop-loss, and take-profit for another symbol. So, if you are calling for the current (SymbolA) this sell:

TicketA = OrderSend(SymbolA,OP_SELL,LotSize,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,EAComment,OrderTicket(),0,clrDarkRed);

Then for a SymbolB (a different symbol), you have to first construct the price values:

double Ask_B = SymbolInfoDouble(SymbolB, SYMBOL_ASK);
double Point_B = SymbolInfoDouble(SymbolB, SYMBOL_POINT);
int Digits_B = SymbolInfoInteger(SymbolB, SYMBOL_DIGITS);
double SL_B = NormalizeDouble(Ask_B - StopLoss * Point_B, Digits_B);
double TP_B = NormalizeDouble(Ask_B + StopLoss * Point_B, Digits_B);

And only then call something like this:

TicketB = OrderSend(SymbolB,OP_BUY,LotSize,Ask_B,Slippage,SL_B,TP_B,EAComment,OrderTicket(),0,clrDarkBlue);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...