orderAsk = Ask - bias * Point; orderBid = Bid - bias * Point; ticket=OrderSend(Symbol(),OP_SELLSTOP,lot,orderBid,1,orderAsk+Point*sl,orderBid-tp*Point,"NewsTrader",2,0,Red);
You can't open pending orders closer than MarketInfo(Symbol(), MODE_STOPLEVEL)*Point from the market or MarketInfo( Symbol(), MODE_FREEZELEVEL )*Point. Usually 3pips/0 during news events likely much more.- On a 5 digit broker you must adjust your TP, SL, and slippage (2=0.2 pips)
//++++ 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; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2db
- You must refreshRates between server calls.
- if ticket <0 Print GetLastError() so you know why.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
extern int lot = 1;
extern int sl = 10;
extern int tp = 10;
extern int bias = 1; //we place our order x pips from current price
double orderAsk;
double orderBid;
string OrderCloseDate;
int init()
{
Print(MarketInfo(Symbol(), MODE_STOPLEVEL));
return(0);
}
int deinit()
{
return(0);
}
int start()
{
//we have to know the time and date of news publication
//I don't want to write what sombody else has written here https://www.mql5.com/en/articles/1502
//we can use this indicator to get the date and time of news publications
//I have put here some example date and
int newsDateYear = 2010;
int newsDateMonth = 10;
int newsDateDay = 5;
int newsDateHour = 23;
int newsDateMinute = 23;
//we need to open order before news publication
newsDateMinute -= 10; //10 minutes before publication
string orderOpenDate = newsDateDay + "-" + newsDateMonth + "-" + newsDateYear
+ " " + newsDateHour + ":" + newsDateMinute + ":00";
int currentYear = Year();
int currentMonth = Month();
int currentDay = Day();
int currentHour = Hour();
int currentMinute = Minute();
//we get current time
string currentDate = currentDay + "-" + currentMonth + "-" + currentYear
+ " " + currentHour + ":" + currentMinute + ":00";
if(orderOpenDate == currentDate)
{
//we place 2 orders: buy stop and sell stop
if(ticket < 1)
{
orderAsk = Ask - bias * Point;
orderBid = Bid - bias * Point;
ticket=OrderSend(Symbol(),OP_SELLSTOP,lot,orderBid,1,orderAsk+Point*sl,orderBid-tp*Point,"NewsTrader",2,0,Red);
}
if(ticket2 < 1)
{
orderAsk = Ask + bias * Point;
orderBid = Bid + bias * Point;
ticket2=OrderSend(Symbol(),OP_BUYSTOP,lot,orderAsk,1,orderBid-Point*sl,orderAsk+tp*Point,"NewsTrader",2,0,Green);
}
}
return(0);
}