[ARCHIVO] Cualquier pregunta de novato, para no saturar el foro. Profesionales, no pasen de largo. En ninguna parte sin ti - 3. - página 539

 

Estoy escribiendo un EA basado en el indicador QQEA. Así, la idea para el EA es: cuando la línea roja cruza la línea amarilla hacia arriba, una orden de compra debe abrirse, y cuando la línea roja cruza la línea amarilla hacia abajo, una orden de venta debe abrirse. Pero no soy capaz de abrir un solo pedido. Los pedidos se abren siempre que se cumpla la condición. ¡Sí, y sólo se abren órdenes de compra HAYDNT ?!

//

Código EA

//--- input parameters
extern double MaxRisk=1.0;
extern double FixLot = 0.01;
extern double Exponent=2.0;
extern int Magic = 888;

// костыли

extern int TakeProfit=100;
extern int StopLoss=100;

int init()
  return(0);
}
int deinit()
{
//----

//----
return(0);
}
 int start()
{
//----
int Count=0;
double b0,b1;
int ticket;

// параметры индикатора
int SF = 5; // original 5
int RSI_Period = 14; // original 14
double DARFACTOR = 4.236; //original 4.236

//------------ Параметры из индикатора QQEA -----------------------
// Buffer0 -- красная жирная
string Buffer0 = iCustom(NULL, 0, "QQEA" , SF, RSI_Period, DARFACTOR,0 , 0); 
// Buffer1 -- жёлтый пунктир
string Buffer1 = iCustom(NULL, 0, "QQEA" , SF, RSI_Period, DARFACTOR,1 , 0);

b0=StrToDouble(Buffer0);
b1=StrToDouble(Buffer1);


double Lot=GetLot(MaxRisk);

// если лот <0 выводим сообщение об ошибке
if(Lot==0) 
{
Alert("Недостаточно средств!");
return(0);
} 

if (Lot!=0 && b0>b1) // если лот <> 0 и красная выше жёлтой
{
ticket=NewOrder(OP_BUY,Lot);
if (ExistOrders(Symbol(), 1, 888, 0) == true ) // проверяем наличие ордера sell
{
CloseOrder();
}
}

if (Lot!=0 && b0<b1) // если лот <> 0 и красная выше жёлтой
{
ticket=NewOrder(OP_SELL,Lot);
if (ExistOrders(Symbol(), 0, 888, 0) == true ) // проверяем наличие ордера buy
{
CloseOrder();
}
} 

Comment("Red line: ",b0,"Yellow line: ",b1);
return(0);
}
//-------------------------------------------------------------
//расчёт лота

double GetLot(int Risk)
{double Free =AccountFreeMargin();
double One_Lot =MarketInfo(Symbol(),MODE_MARGINREQUIRED);
double Min_Lot =MarketInfo(Symbol(),MODE_MINLOT);
double Max_Lot =MarketInfo(Symbol(),MODE_MAXLOT);
double Step =MarketInfo(Symbol(),MODE_LOTSTEP);
double Lot =MathFloor(Free*Risk/100/One_Lot/Step)*Step;
if(Lot<Min_Lot) Lot=Min_Lot;
if(Lot>Max_Lot) Lot=Max_Lot;
if(Lot*One_Lot>Free) return(0.0);
return(Lot);}


bool ExistOrders(string sy="", int op=-1, int Magic=-1, datetime ot=0)
{
int i, k=OrdersTotal(), ty;

if (sy=="0") sy=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
ty=OrderType();
if (ty>1 && ty<6) {
if ((OrderSymbol()==sy || sy=="") && (op<0 || ty==op)) {
if (Magic<0 || OrderMagicNumber()==Magic) {
if (ot<=OrderOpenTime()) return(True);
}
}
}
}
}
return(False);
}


//открытие нового ордера
int NewOrder(int Cmd,double Lot)
{double TP=0; //тейкпрофит
double SL=0; //стоплосс
double PR=0; //Цена
while(!IsTradeAllowed()) Sleep(100);
if(Cmd==OP_BUY)
{PR=Ask;
if(TakeProfit>0) TP=Ask+TakeProfit*Point;
if(StopLoss>0) SL=Ask-StopLoss*Point;}
if(Cmd==OP_SELL)
{PR=Bid;
if(TakeProfit>0) TP=Bid-TakeProfit*Point;
if(StopLoss>0) SL=Bid+StopLoss*Point;}
int tic=OrderSend(Symbol(),Cmd,Lot,PR,3,SL,TP," ",0,0,Green);
if(tic<0) Print("Ошибка открытия ордера: " ,GetLastError());
return(tic);}


// закрытие ордера
void CloseOrder()
{double PR=0;
while(!IsTradeAllowed()) Sleep(100);
if(OrderType()==OP_BUY) PR=Bid;
if(OrderType()==OP_SELL) PR=Ask;
if(!OrderClose(OrderTicket(),OrderLots(),PR,3,Red))
Print("Ошибка закрытия ордера: " ,GetLastError());
return;}
Archivos adjuntos:
qqea_1.mq4  4 kb
 
PAZITIV:

Estoy escribiendo un EA basado en el indicador QQEA. Así, la idea para el EA es: cuando la línea roja cruza la línea amarilla hacia arriba, una orden de compra debe abrirse, y cuando la línea roja cruza la línea amarilla hacia abajo, una orden de venta debe abrirse. Pero no soy capaz de abrir un solo pedido. Los pedidos se abren siempre que se cumpla la condición. ¡Sí, y sólo se abren órdenes de compra HAYDNT ?!

//

Código EA

//--- input parameters
extern double MaxRisk=1.0;
extern double FixLot = 0.01;
extern double Exponent=2.0;
extern int Magic=888;

// костыли

extern int TakeProfit=100;
extern int StopLoss=100;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
//----
   int Count=0;
   double b0,b1;
   int ticket;

// параметры индикатора
   int SF=5; // original 5
   int RSI_Period=14; // original 14
   double DARFACTOR=4.236; //original 4.236

//------------ Параметры из индикатора QQEA -----------------------
// Buffer0 -- красная жирная
   string Buffer0=iCustom(NULL,0,"QQEA",SF,RSI_Period,DARFACTOR,0,0);
// Buffer1 -- жёлтый пунктир
   string Buffer1=iCustom(NULL,0,"QQEA",SF,RSI_Period,DARFACTOR,1,0);

   b0=StrToDouble(Buffer0);
   b1=StrToDouble(Buffer1);


   double Lot=GetLot(MaxRisk);
// если лот <0 выводим сообщение об ошибке
   if(Lot==0)
     {
      Alert("Недостаточно средств!");
      return(0);
     }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   if(Lot!=0 && b0>b1) // если лот <> 0 и красная выше жёлтой
     {
      ticket=NewOrder(OP_BUY,Lot);
      if(ExistOrders(Symbol(),1,888,0)==true) // проверяем наличие ордера sell
        {
         CloseOrder();
        }
     }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   if(Lot!=0 && b0<b1) // если лот <> 0 и красная выше жёлтой
     {
      ticket=NewOrder(OP_SELL,Lot);
      if(ExistOrders(Symbol(),0,888,0)==true) // проверяем наличие ордера buy
        {
         CloseOrder();
        }
     }

   Comment("Red line: ",b0,"Yellow line: ",b1);
   return(0);
  }
//-------------------------------------------------------------
//расчёт лота

double GetLot(int Risk)
  {
   double Free=AccountFreeMargin();
   double One_Lot =MarketInfo(Symbol(),MODE_MARGINREQUIRED);
   double Min_Lot =MarketInfo(Symbol(),MODE_MINLOT);
   double Max_Lot =MarketInfo(Symbol(),MODE_MAXLOT);
   double Step=MarketInfo(Symbol(),MODE_LOTSTEP);
   double Lot =MathFloor(Free*Risk/100/One_Lot/Step)*Step;
   if(Lot<Min_Lot) Lot=Min_Lot;
   if(Lot>Max_Lot) Lot=Max_Lot;
   if(Lot*One_Lot>Free) return(0.0);
   return(Lot);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ExistOrders(string sy="",int op=-1,int Magic=-1,datetime ot=0)
  {
   int i,k=OrdersTotal(),ty;

   if(sy=="0") sy=Symbol();
   for(i=0; i<k; i++)
      //+------------------------------------------------------------------+
      //|                                                                  |
      //+------------------------------------------------------------------+
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         ty=OrderType();
         if(ty>1 && ty<6)
           {
            if((OrderSymbol()==sy || sy=="") && (op<0 || ty==op))
              {
               if(Magic<0 || OrderMagicNumber()==Magic)
                 {
                  if(ot<=OrderOpenTime()) return(True);
                 }
              }
           }
        }
     }
   return(False);
  }
//открытие нового ордера
int NewOrder(int Cmd,double Lot)
  {
   double TP=0; //тейкпрофит
   double SL=0; //стоплосс
   double PR=0; //Цена
   while(!IsTradeAllowed()) Sleep(100);
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   if(Cmd==OP_BUY)
     {
      PR=Ask;
      if(TakeProfit>0) TP=Ask+TakeProfit*Point;
      if(StopLoss>0) SL=Ask-StopLoss*Point;
     }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   if(Cmd==OP_SELL)
     {
      PR=Bid;
      if(TakeProfit>0) TP=Bid-TakeProfit*Point;
      if(StopLoss>0) SL=Bid+StopLoss*Point;
     }
   if(GetOrdersCount(Magic,Cmd)>0)return(0);
   int tic=OrderSend(Symbol(),Cmd,Lot,PR,3,SL,TP," ",0,0,Green);
   if(tic<0) Print("Ошибка открытия ордера: ",GetLastError());
   return(tic);
  }
// закрытие ордера
void CloseOrder()
  {
   double PR=0;
   while(!IsTradeAllowed()) Sleep(100);
   if(OrderType()==OP_BUY) PR=Bid;
   if(OrderType()==OP_SELL) PR=Ask;
   if(!OrderClose(OrderTicket(),OrderLots(),PR,3,Red))
      Print("Ошибка закрытия ордера: ",GetLastError());
   return;
  }
//+------------------------------------------------------------------+
// подсчет кол-ва открытых позиций
int GetOrdersCount(int MagicNumber,int Type)
  {
   int count=0;

   for(int i=0; i<OrdersTotal(); i++)
     {
      // already closed
      if(OrderSelect(i,SELECT_BY_POS)==false) continue;
      // not current symbol
      if(OrderSymbol()!=Symbol()) continue;
      // order was opened in another way
      if(OrderMagicNumber()!=MagicNumber) continue;

      if(OrderType()==Type)
        {
         count++;
        }
     }

   return(count);
  }
//-------------------------------------------------------
Escribe de forma más legible, será más fácil después.
 
PAZITIV:

Estoy escribiendo un EA basado en el indicador QQEA. Así, la idea para el EA es: cuando la línea roja cruza la línea amarilla hacia arriba, una orden de compra debe abrirse, y cuando la línea roja cruza la línea amarilla hacia abajo, una orden de venta debe abrirse. Pero no soy capaz de abrir un solo pedido. Los pedidos se abren siempre que se cumpla la condición. Y sólo se abren órdenes de compra.

//

Código EA


Déjame hacerte una pregunta.

¿En qué se basa el tipo de cadena?

//------------ Параметры из индикатора QQEA -----------------------
// Buffer0 -- красная жирная
   string Buffer0=iCustom(NULL,0,"QQEA",SF,RSI_Period,DARFACTOR,0,0);
// Buffer1 -- жёлтый пунктир
   string Buffer1=iCustom(NULL,0,"QQEA",SF,RSI_Period,DARFACTOR,1,0);
 
   double diMA60=iMA(NULL,60,Period_indikatora1,0,Mod_MA,PRICE_CLOSE,sdvig);
   double diMA30=iMA(NULL,30,Period_indikatora2,0,Mod_MA,PRICE_CLOSE,sdvig)

chicos EA utiliza dos marcos de tiempo diferentes (30 y 60), dime qué período de poner en el probador, y si el período de prueba en la EA no va a cambiar?

 
NO menos que el mínimo, es decir, en su caso M30
 

¿Qué significan estas entradas de registro?

2012.01.31 14:34:45 Gestor de memoria: no puede asignar 10436536 bytes de memoria

2012.01.31 14:34:45:45 HistoryBase: no hay suficiente memoria 'EURGBP1' [206996 bares]

? ¿Es posible arreglar si hay algún problema?

 

Ayuda con las matrices. No funciona como yo quiero.

Hay una matriz de precios p[]. Necesito crear un nuevo array, cuya longitud sea un elemento menos, y se cuente como la diferencia entre dos elementos adyacentes del primer array. Si la diferencia es negativa, multiplique por -1.

hay p [6]={1, 5, 9, 4, 6, 2, 3}

Deberíamos conseguir

p_diff[5] = {-1*(1-5), -1*(5-9), 9-4, -1*(4-6), 6-2, -1*(2-3)} es decir, p_diff[5] = {4, 4, 5, 2, 4, 1}

int start()
{
  if( !NewBar() ) return(0);                                           
  int i, n, k,
      j = 0;                             
  for(i=0; i<=Bars_count; i++)
  {
      ZZ[i]=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,i);  
      if(ZZ[i]!=0) 
      {
         Print(ZZ[j]);
         j = j + 1;
         k = j - 1;
         Print("index = ",k);
      }
  }
  Print("iiii = ", k);
  for(n = 0; n <= k-1; n++)
  { 
      ZZ_diff[n] = (ZZ[n] -ZZ[n+1]);
      if(ZZ_diff[n] < 0)  
         ZZ_diff[n] = ZZ_diff[n] * (-1);
      Print(ZZ_diff[n], "   index diff = ", n);
  }
return(0);
}
 
-Aleksey-:

¿Qué significan estas entradas de registro?

2012.01.31 14:34:45 Gestor de memoria: no puede asignar 10436536 bytes de memoria

2012.01.31 14:34:45:45 HistoryBase: no hay suficiente memoria 'EURGBP1' [206996 bares]

? ¿Es posible arreglar si hay algún problema?


Aumentar la capacidad de la RAM, reducir las barras máximas en la ventana.
 
gince:

Ayuda con las matrices. No funciona como yo quiero.

Hay una matriz de precios p[]. Necesito crear un nuevo array, cuya longitud sea un elemento menos, y se cuente como la diferencia entre dos elementos adyacentes del primer array. Si la diferencia es negativa, multiplique por -1.

hay p [6]={1, 5, 9, 4, 6, 2, 3}

Deberíamos conseguir

p_diff[5] = {-1*(1-5), -1*(5-9), 9-4, -1*(4-6), 6-2, -1*(2-3)} es decir, p_diff[5] = {4, 4, 5, 2, 4, 1}

doble MathAbs( valor doble)

La función devuelve el valor absoluto (valor de módulo) del número que se le pasa

ZZ_diff[n] = MathAbs(ZZ[n] -ZZ[n+1]);
 
double zz_arr[1000];
double preZz=0;
int i,ii;
for(i=5000;i>=0;i--){
   double zz = iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,i); 
   if(zz!=0){
      if(preZz==0){preZz=zz;continue;}
      zz_arr[ii]=MathAbs(zz-preZz);
      preZz=zz;
      ii++;
   }
}
ArrayResize(zz_arr,ii);
Razón de la queja: