EA Order vs Postion

 

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)


input double Multiplier = 2;
input string SignalName = "Luobo Froex";
input int MagicNumber = 53443;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   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                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   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);
}

Negociação Automatizada e Análise de Estratégia
Negociação Automatizada e Análise de Estratégia
  • www.mql5.com
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
Reason: