Cualquier pregunta de los recién llegados sobre MQL4 y MQL5, ayuda y discusión sobre algoritmos y códigos - página 569

 
YanSay:

¿Pueden decirme cómo excluir/añadir una fecha específica al EA?

Por ejemplo, no negociar el 2 de marzo de 2018. Intenté diferentes opciones, me confundí con las fechas.

La opción más fácil es ésta:

input datetime i_dtSkipTheDay = D'2018.03.02';


...
datetime dtDayStartTime = TimeCurrent() / (60 * 60 * 24); 
if (dtDayStartTime == i_dtSkipTheDay)
{
   // не торговать
}
 

He escrito un EA, que comercia bien. Decidí complementarlo y prescribir órdenes de cierre por señales opuestas... pero no reacciona .... no abre en absoluto o abre pero no cierra por señales opuestas.... solo por TP y SL

 if (CCILong < Level0 && CountBuy() == 0)
       {   for(int i=OrdersTotal()-1; i >=0; i--)
          {
             if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
             {
                if(OrderMagicNumber() == Magic && OrderType() == OP_BUY)
                  bool close1 = OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, clrNONE);
             }
          }
       }   
          if (CCILong > Level0 && CountSell() == 0)
       {   for(int i=OrdersTotal()-1; i >=0; i--)
          {
             if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
             {
                if(OrderMagicNumber() == Magic && OrderType() == OP_SELL)
                  bool close1 = OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, clrNONE);
             }
          }
       }
 
baksik99:

He escrito un EA, que comercia bien. Decidí complementarlo y prescribir órdenes de cierre por señales opuestas... pero no reacciona .... no abre en absoluto o abre pero no cierra por señales opuestas.... sólo por TP y SL

Usted ha escrito:

if (CCILong < Level0 && CountBuy() == 0)

Si no hay órdenes de compra, debemos cerrar la compra. Lo mismo ocurre con la venta.

 
Ihor Herasko:

Lo tienes escrito:

Si no hay órdenes de compra, hay que cerrar la compra. Lo mismo ocurre con la venta.

¿Deben ser eliminados porCountSell yCountBuy?

Funcionó .... ¡Lo arreglé! ¡¡¡Gracias!!! ++++
 
Ihor Herasko:

La opción más fácil es ésta:

Desgraciadamente no funcionó(

Todo como tú lo has hecho, sólo que no es igual:

input datetime i_dtSkipTheDay = D'2018.03.02';

datetime dtDayStartTime = TimeCurrent() / (60 * 60 * 24);
if (dtDayStartTime != i_dtSkipTheDay)
{
//Открытие ордера
}

Todavía en el probador abre el trato en ese día.

 
YanSay:

Desgraciadamente no ha funcionado(.

Hice todo como tú, sólo que no igual:

Todavía en el probador abre el trato en ese día.

¿Y qué?

input datetime i_dtSkipTheDay = D'2018.03.02';

if (TimeToStr(TimeCurrent(),TIME_DATE) != TimeToStr(i_dtSkipTheDay,TIME_DATE))
{
//Открытие ордера
}
 
Taras Slobodyanik:

¿Qué te parece esto?

¡Funcionó así! ¡Muchas gracias!

 
YanSay:

Desgraciadamente no ha funcionado(.

Hice todo como tú, sólo que no igual:

Aún así, abre un comercio en el probador en ese día.

Lo siento, hay que multiplicar ahí atrás:

input datetime i_dtSkipTheDay = D'2018.03.02';

datetime dtDayStartTime = (TimeCurrent() / (60 * 60 * 24)) * (60 * 60 * 24);
if (dtDayStartTime != i_dtSkipTheDay)
{
//Открытие ордера
}

Por eso no funcionó.

 
Ihor Herasko:

Lo siento, hay que multiplicar ahí atrás:

Por eso no funcionó.

Gracias.

 

Estoy tratando de hacer mi propio indicador de fractal utilizando el estándar, parece que funciona, pero todavía pone fractales en todos los lugares equivocados a veces, ¿puede alguien ayudar?

//+------------------------------------------------------------------+
//|                                                     Fractals.mq5 |
//|                   Copyright 2009-2017, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
#property indicator_type1   DRAW_ARROW
#property indicator_type2   DRAW_ARROW
#property indicator_color1  Gray
#property indicator_color2  Gray
#property indicator_label1  "Fractal Up"
#property indicator_label2  "Fractal Down"
bool high_f, low_f;
//---- input data
input int period = 5;
int per = period;
//---- indicator buffers
double ExtUpperBuffer[];
double ExtLowerBuffer[];
//--- 10 pixels upper from high price
int    ExtArrowShift=-10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
  if(per % 2 == 0) per++;
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowerBuffer,INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_ARROW,217);
   PlotIndexSetInteger(1,PLOT_ARROW,218);
//---- arrow shifts when drawing
   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,ExtArrowShift);
   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-ExtArrowShift);
//---- sets drawing line empty value--
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- initialization done
  }
//+------------------------------------------------------------------+
//|  Accelerator/Decelerator Oscillator                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int i,limit;
//---
   if(rates_total<per)
      return(0);
//---
   if(prev_calculated<per+(per-1)/2)
     {
      limit=(per-1)/2;
      //--- clean up arrays
      ArrayInitialize(ExtUpperBuffer,EMPTY_VALUE);
      ArrayInitialize(ExtLowerBuffer,EMPTY_VALUE);
     }
   else limit=rates_total-per;

   for(i=limit;i<rates_total-(per+1)/2 && !IsStopped();i++)
     {
      
      for(int g = 1; g < (per+1)/2; g++){
         high_f = true; low_f = true;
         
         //---- Upper Fractal
         if(high[i-g] > high[i] || high[i+g] > high[i]){
            ExtUpperBuffer[i] = EMPTY_VALUE;
            high_f = false;  
            
         }else{            
            if(high_f) ExtUpperBuffer[i] = high[i];  
         }
         //---- Lower Fractal
         if(low[i-g] < low[i] || low[i+g] < low[i]){           
            ExtLowerBuffer[i] = EMPTY_VALUE;
            low_f = false;   
         }else{            
            if(low_f) ExtLowerBuffer[i] = low[i];     
         }
      
      }
     }
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }

//+------------------------------------------------------------------+