OrderCloseBy error in MetaTrader

I'm writing MQL4 strategy, and I'm struggling with OrderCloseBy function. It returns Error 3.

I wrote some simple program, see below, and it works most of the times in demo account, but always returns error 3 on ordercloseby in strategytester.

What can be the issue?

#property copyright "Copyright 2012, MetaQuotes Software Corp."

#property link "[url removed, login to view]"

#include <[url removed, login to view]>

int StrategyID = 3002;

string StrategyName = "TestCloseBy";

int TotalCount=2;

int ticketBuy = -1;

int ticketSell = -1;

int iCount = 1;

int start()


double dLots = 1;

int OpenTicket = OrdersTotal();

if (OpenTicket==0 && iCount<=TotalCount)


ticketBuy = OrderSend(Symbol(),OP_BUY,dLots,Ask,3,0,0,StrategyName+": buy order", StrategyID,0,Green);




Print(StrategyName+":Buy market order opened confirm : ",OrderOpenPrice(), " ticketBuy : ",ticketBuy, ", vs ticketBuy : ",OrderTicket());


else Print(StrategyName + ":Error opening market order : ",GetLastError());

ticketSell = OrderSend(Symbol(),OP_SELL,dLots,Bid,3,0,0,StrategyName+": sell order", StrategyID,0,Red);




Print(StrategyName+":Sell market order opened confirm : ",OrderOpenPrice(), " ticketsell : ",ticketSell, ", vs ticketSell : ",OrderTicket());


else Print(StrategyName + ":Error opening market order : ",GetLastError());


else if (OpenTicket==2 && iCount<=TotalCount)


if (OrderCloseBy(ticketBuy, ticketSell, White) == true)

Print(StrategyName,":OrderCloseBy ",ticketBuy,", ",ticketSell);


Print(StrategyName,"Error closing order test:",ticketBuy," : ",ticketSell," with Error ",GetLastError());





Compétences : Metatrader

en voir plus : ordercloseby, ordercloseby error, mql4 ordercloseby function, metatrader ordercloseby, true green, always property, mql4 ordercloseby, symbol of red, www market net, metaquotes, mqh, simple print function, pending order strategy, strategy sell software, software program symbol, mql4 string, metatrader string, metatrader program, pending order metatrader, red error, program strategy, mql4 buy market order, metatrader net order, mql4 strategy, buy symbol

Concernant l'employeur :
( 6 commentaires ) Nes Ziona, Israel

Nº du projet : #2352178

Décerné à:


Hi mate, I have 4+ years in MT4 expert advisor and indicators programming. I'm ready to help and I GUARANTEE my work. Regards, Irwin.

%selectedBids___i_sum_sub_7% %project_currencyDetails_sign_sub_8% USD en 0 jours
(134 Commentaires)

4 freelance font une offre moyenne de $30 pour ce travail


Hi there, i can help you :)

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 0 jours
(11 Commentaires)

Hello, I can help you. Please check PMB.

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(8 Commentaires)

I can do this job. Below is some of the feedbacks from my customers at [url removed, login to view] infarm: Each job gives me more confidence in EricHe. Doesn't give up the job until it Plus

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 0 jours
(2 Commentaires)