Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 569

 
YanSay:

Can you tell me how to exclude/add a specific date to the EA?

For example, not to trade March 2, 2018. Tried different options, got confused with dates.

The easiest option is this:

input datetime i_dtSkipTheDay = D'2018.03.02';


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

I have written an EA, it trades fine. I decided to complement it and prescribe closing orders by opposite signals ... but it does not react .... it does not open at all or opens but does not close by opposite signals.... only by TP and 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:

I have written an EA, it trades fine. I decided to complement it and prescribe closing orders by opposite signals ... but it does not react .... it does not open at all or opens but does not close by opposite signals.... only by TP and SL

You have written:

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

If there are no Buy orders, we should close Buy. The same goes for Sell.

 
Ihor Herasko:

You have it written:

If there are no Buy orders, you have to close Buy. The same goes for Sell.

Are they to be removed byCountSell andCountBuy?

It worked .... I fixed it! thank you!!!++++
 
Ihor Herasko:

The easiest option is this:

Unfortunately it didn't work(

All as you have done, only not equal:

input datetime i_dtSkipTheDay = D'2018.03.02';

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

Still in the tester opens the deal on that day.

 
YanSay:

Unfortunately it didn't work(.

I did everything as you did, only not equal:

Still in the tester opens the deal on that day.

And so?

input datetime i_dtSkipTheDay = D'2018.03.02';

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

How about this?

It worked like that! Thank you very much!

 
YanSay:

Unfortunately it didn't work(.

I did everything as you did, only not equal:

Still opens a trade in the tester on that day.

Sorry, it needs to be multiplied back there:

input datetime i_dtSkipTheDay = D'2018.03.02';

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

That's why it didn't work.

 
Ihor Herasko:

I'm sorry, it needs to be multiplied back there:

That's why it didn't work.

Thank you!

 

I'm trying to make my own fractal indicator using the standard one, it seems to work, but it still puts fractals in all the wrong places sometimes, can anyone help?

//+------------------------------------------------------------------+
//|                                                     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);
  }

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