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