I need help in correcting an EA... The full code is referred in the postion instead of order, but couldn't find the right term (i.e. what's the parallel name for POSITION_VOLUME - which is not ORDER_VOLUME)
inputdouble Multiplier = 2;
inputstring SignalName = "Luobo Froex";
inputint MagicNumber = 53443;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---
trade.SetExpertMagicNumber(MagicNumber);
//--- set available slippage in points when buying/selling
trade.SetDeviationInPoints(50);
//--- order filling mode, the mode allowed by the server should be used
trade.SetTypeFilling(ORDER_FILLING_RETURN);
//--- logging mode: it would be better not to declare this method at all, the class will set the best mode on its own
trade.LogLevel(1);
//--- what function is to be used for trading: true - OrderSendAsync(), false - OrderSend()
trade.SetAsyncMode(false);
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
//---
FindTrades();
CloseTrades();
}
//+------------------------------------------------------------------+void FindTrades(){
for(int i = (OrdersTotal()-1); i >= 0; i --)
{
int ordtick = (int)OrderGetTicket(i);
if(OrderSelect(ordtick)){
int ordtype = (int)OrderGetInteger(ORDER_TYPE);
double ordopenprice = OrderGetDouble(ORDER_PRICE_OPEN);
double ordtp = OrderGetDouble(ORDER_TP);
double ordlots = OrderGetDouble(ORDER_VOL);
string ordcomment = OrderGetString(ORDER_COMMENT);
string ordsymbol = OrderGetString(ORDER_SYMBOL);
if(ordcomment==SignalName && NotFound(ordtick)){
double lotsi=NormalizeDouble(ordlots*Multiplier,2);
if(ordtype==ORDER_TYPE_BUY){
pricet=SymbolInfoDouble(ordsymbol,SYMBOL_ASK);
int send = trade.Buy(lotsi,ordsymbol,pricet,0,0,(string)ordtick);
}
if(ordtype==ORDER_TYPE_SELL){
pricet=SymbolInfoDouble(ordsymbol,SYMBOL_BID);
int send = trade.Sell(lotsi,ordsymbol,pricet,0,0,(string)ordtick);
}
}
}
}
}
double pricet;
string com;
bool NotFound(int tick){
com=(string)tick;
for(int i = (OrdersTotal()-1); i >= 0; i --)
{
int ordtick = (int)OrderGetTicket(i);
if(OrderSelectByTicket(ordtick)){
int ordtype = (int)OrderGetInteger(ORDER_TYPE);
double ordopenprice = OrderGetDouble(ORDER_PRICE_OPEN);
double ordtp = OrderGetDouble(ORDER_TP);
double ordlots = OrderGetDouble(ORDER_VOLUME);
string ordcomment = OrderGetString(ORDER_COMMENT);
if(com==ordcomment){return(false);}
}
}
return(true);
}
void CloseTrades(){
for(int i = (OrdersTotal()-1); i >= 0; i --)
{
int ordtick = (int)OrderGetTicket(i);
if(OrderSelectByTicket(ordtick)){
int ordtype = (int)OrderGetInteger(ORDER_TYPE);
double ordopenprice = OrderGetDouble(ORDER_PRICE_OPEN);
double ordtp = OrderGetDouble(ORDER_TP);
double ordlots = OrderGetDouble(ORDER_VOLUME);
string ordcomment = OrderGetString(ORDER_COMMENT);
int ordmag = (int)OrderGetInteger(ORDER_MAGIC);
string ordsymbol = OrderGetString(ORDER_SYMBOL);
//if(ordmag==MagicNumber)Comment("here"," ", ordcomment); if(!NotFoundT(ordcomment) && ordmag==MagicNumber){
if(ordtype==ORDER_TYPE_BUY){pricet=SymbolInfoDouble(ordsymbol,SYMBOL_BID);}
if(ordtype==ORDER_TYPE_SELL){pricet=SymbolInfoDouble(ordsymbol,SYMBOL_ASK);}
int clo = trade.OrderClose(ordtick,-1);
}
}
}
}
bool NotFoundT(string tick){
for(int i = (OrdersTotal()-1); i >= 0; i --)
{
int ordtick = (int)OrderGetTicket(i);
if(OrderSelectByTicket(ordtick)){
int ordtype = (int)OrderGetInteger(ORDER_TYPE);
double ordopenprice = OrderGetDouble(ORDER_PRICE_OPEN);
double ordtp = OrderGetDouble(ORDER_TP);
double ordlots = OrderGetDouble(ORDER_VOLUME);
string ordcomment = OrderGetString(ORDER_COMMENT);
int ordmag = (int)OrderGetInteger(ORDER_MAGIC);
string ordtickS = (string)ordtick;
if(ordtickS==tick){return(true);}
}
}
return(false);
}
MQL5: linguagem de estratégias de negociação inseridas no Terminal do Cliente MetaTrader 5. A linguagem permite escrever seus próprios sistemas automáticos de negócios, indicadores técnicos, scripts e bibliotecas de funções
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi guys,
I need help in correcting an EA... The full code is referred in the postion instead of order, but couldn't find the right term (i.e. what's the parallel name for POSITION_VOLUME - which is not ORDER_VOLUME)