If I don't use the "StopLevel" and TakeProfit on the second order, then it work, but when I use them then it doeDos'nt work (...)
What doesn't work? Do u get errors or what?
//++++ These are adjusted for 5 digit brokers. double pips2points, // slippage 3 pips 3=points 30=points pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init() { if (Digits == 5 || Digits == 3) { // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } //...Once you send/modify/cancel/delete an order, time passes before you get the results. You MUST call RefreshRates() before ANY other server call.
(...)
ticket1 = OrderSend(symbol1, OP_SELL, LotSize, MarketInfo(symbol1,MODE_BID), Slippage, StopLossLevel,TakeProfitLevel,0,Magicnumber1,0) & OrderSend(symbol2, OP_SELL, LotSize, MarketInfo(symbol2,MODE_BID), Slippage, StopLossLevel,TakeProfitLevel,0,Magicnumber1,0);
This part doesn't make sense. It sends 2 orders and does a bitwise AND of the returned ticket's binary representation, then assigns the result to ticket1. Is that what u really want?
See here -> https://docs.mql4.com/basis/operations/bit
This part doesn't make sense. It sends 2 orders and does a bitwise AND of the returned ticket's binary representation, then assigns the result to ticket1. Is that what u really want?
See here -> https://docs.mql4.com/basis/operations/bit
I want to send 2 SELL or BUY orders one for EURUSD and one for USDCHF, both with SL and TP tha's it ;-)
Ciao
Fabio
I want to send 2 SELL or BUY orders one for EURUSD and one for USDCHF, both with SL and TP tha's it ;-)
Ciao
Fabio
Just break the OrderSend() statement into two:
int ticket1=OrderSend(...); int ticket2=OrderSend(...);
It execute the 1st order with SL and TP, while for the second if the SL=0 and TP=0 then it excute otherwise if SL !=0 and TP!=0 then it does not execute the order ;-)
Any idea ?
Ciao
Fabio
Add an error check immediately after the OrderSend() statement. There's an example here -> https://docs.mql4.com/trading/OrderSend (at the bottom).
Add an error check immediately after the OrderSend() statement. There's an example here -> https://docs.mql4.com/trading/OrderSend (at the bottom).
Ticket = OrderSend("EURUSD", OP_SELL, Lots,
NormalizeDouble(Bid,digit),
Slippage,
NormalizeDouble(StopLossLevel,digit),
NormalizeDouble(TakeProfitLevel,digit),
"Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("SELL order opened : ", OrderOpenPrice()); else Print("Error opening SELL order : ", GetLastError());
}
Ticket = OrderSend("USDCHF", OP_SELL, Lots,
NormalizeDouble(Bid,digit),
Slippage,
NormalizeDouble(StopLossLevel,digit),
NormalizeDouble(TakeProfitLevel,digit),
"Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("SELL order opened : ", OrderOpenPrice()); else Print("Error opening SELL order : ", GetLastError());
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I wrote this simple code in order to send a SELL order for both EURUSD and USDCHF . I let the EA running on EURUSD chart only ;-)
If I don't use the "StopLevel" and TakeProfit on the second order, then it work, but when I use them then it does'nt work
Can somebody help me ?
Thanks
Fabio
#property link "https://www.metaquotes.net//"
bool wannaBuy = true;
bool wannaBuy1 = true;
extern double LotSize = 0.01;
extern string symbol1 = "EURUSD";
extern string symbol2 = "USDCHF";
extern int MaxDifference = 6;
extern int Slippage = 3;
extern int Magicnumber1 = 786;
extern int Magicnumber2 = 123;
extern bool StopLossModeFix = true;
extern double StopLoss = 25;
extern bool TakeProfitMode = True;
extern int TakeProfit = 45;
int sendticket = 3;
string pairs[18];
double StopLossLevel, TakeProfitLevel;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
pairs[0] = symbol1;
pairs[1] = symbol2;
wannaBuy = true;
wannaBuy1 = true;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int pipMultiplier=1;
int digit = MarketInfo(Symbol(),MODE_DIGITS);
if (digit==3 || digit==5)
pipMultiplier=10;
// Send order for EURUSD & USDCHF
if (wannaBuy) {
int ticket1;
if (StopLossModeFix)StopLossLevel = Bid + StopLoss * pipMultiplier * Point;
StopLoss=StopLossLevel-Bid;
StopLoss=StopLoss*pipMultiplier * 1000;
if (TakeProfitMode) TakeProfitLevel = Bid - TakeProfit * pipMultiplier * Point;
else TakeProfitLevel =0;
RefreshRates();
ticket1 = OrderSend(symbol1, OP_SELL, LotSize, MarketInfo(symbol1,MODE_BID), Slippage, StopLossLevel,TakeProfitLevel,0,Magicnumber1,0) & OrderSend(symbol2, OP_SELL, LotSize, MarketInfo(symbol2,MODE_BID), Slippage, StopLossLevel,TakeProfitLevel,0,Magicnumber1,0);
if (ticket1 <0 )
{
Print ("OrderSend failed with error #", GetLastError());
return(0);
}
wannaBuy = false;
}
//----
return(0);
}
//+------------------------------------------------------------------+