Questions from Beginners MQL5 MT5 MetaTrader 5 - page 413

 
first_may:
It's not clear what was meant?
Meaning:Insert the code correctly in the forum
 
Karputov Vladimir:
I meant the following:Insert the code correctly in the forum

I see. I check the location of the tenkan and the kinjun on the first and second candle. If there is a signal, I enter an alert. But I would like it to be a one time thing. Please help me. Here is the code.

 
//+------------------------------------------------------------------+
//|                                                main_Ichimoku.mq5 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"



//+------------------------------------------------------------------+
//| Объявим переменные для хранения настроек индикаторов             |
//+------------------------------------------------------------------+
int IKHtenkansen=8;
int IKHkijunsen=24;
int IKHsenkouspanb=48;
//+------------------------------------------------------------------+
//| Объявим переменные для хранения хэндлов индикаторов              |
//+------------------------------------------------------------------+
int h_ich=INVALID_HANDLE;
//+------------------------------------------------------------------+
//| Объявим необходимые массивы для хранения данных индикаторов      |
//+------------------------------------------------------------------+
double ich1_buffer[]; 
double ich2_buffer[]; 
//+------------------------------------------------------------------+
//| Объявим переменные для хранения сигналов индикаторов             |
//+------------------------------------------------------------------+
int SignalICH;



//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   SignalICH=TradeSignal_20();
   
   
   Comment("SignalICH: "+(string)SignalICH);
}



//+------------------------------------------------------------------+
//| Функция                                             |
//+------------------------------------------------------------------+
int TradeSignal_20()
{
   int sig=0;

   if(h_ich==INVALID_HANDLE)
   {
      h_ich=iIchimoku(Symbol(),Period(),IKHtenkansen,IKHkijunsen,IKHsenkouspanb);
      return(0);
   }
   else
   {
      if (CopyBuffer(h_ich,0,0,3,ich1_buffer)<2) return(0); // TENKANSEN_LINE
      if (CopyBuffer(h_ich,1,0,3,ich2_buffer)<2) return(0); // KIJUNSEN_LINE
      if (!ArraySetAsSeries(ich1_buffer,true)) return(0);
      if (!ArraySetAsSeries(ich2_buffer,true)) return(0);
   }
   
   //--- проводим проверку условия и устанавливаем значение для sig
   if (ich1_buffer[1]>ich2_buffer[1]) sig=1;
   else if(ich1_buffer[1]<ich2_buffer[1]) sig=-1;
   else sig=0;
   
   if (ich1_buffer[1]>ich2_buffer[1])
      if (ich1_buffer[2]<ich2_buffer[2])
         Alert(Symbol()+": покупка");
   
   if (ich1_buffer[1]<ich2_buffer[1])
      if (ich1_buffer[2]>ich2_buffer[2])
         Alert(Symbol()+": продажа");
   
   
   //--- возвращаем торговый сигнал
   return (sig);
}
 
first_may:

I see. I check the location of the tenkan and the kinjun on the first and second candle. If there is a signal, I enter an alert. But I would like it to be a one time thing. Please help me. Here is the code.

Not more than one alert on one bar:

//+------------------------------------------------------------------+
//|                                                main_Ichimoku.mq5 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Объявим переменные для хранения настроек индикаторов             |
//+------------------------------------------------------------------+
int IKHtenkansen=8;
int IKHkijunsen=24;
int IKHsenkouspanb=48;
//+------------------------------------------------------------------+
//| Объявим переменные для хранения хэндлов индикаторов              |
//+------------------------------------------------------------------+
int h_ich=INVALID_HANDLE;
//+------------------------------------------------------------------+
//| Объявим необходимые массивы для хранения данных индикаторов      |
//+------------------------------------------------------------------+
double ich1_buffer[];
double ich2_buffer[];
//+------------------------------------------------------------------+
//| Объявим переменные для хранения сигналов индикаторов             |
//+------------------------------------------------------------------+
int SignalICH;
//+------------------------------------------------------------------+
//| Объявим переменную-флаг разрешения/запрета алерта                |
//+------------------------------------------------------------------+
bool bool_alert=false;
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   static datetime prevtime=0;
   datetime time_zero[];
   CopyTime(Symbol(),Period(),0,1,time_zero);
   
   if(!bool_alert)
      if(prevtime!=time_zero[0])
         bool_alert=true;
   prevtime=time_zero[0];
   
   SignalICH=TradeSignal_20();

   Comment("SignalICH: "+(string)SignalICH);
  }
//+------------------------------------------------------------------+
//| Функция                                                          |
//+------------------------------------------------------------------+
int TradeSignal_20()
  {
   int sig=0;

   if(h_ich==INVALID_HANDLE)
     {
      h_ich=iIchimoku(Symbol(),Period(),IKHtenkansen,IKHkijunsen,IKHsenkouspanb);
      return(0);
     }
   else
     {
      if(CopyBuffer(h_ich,0,0,3,ich1_buffer)<2) return(0); // TENKANSEN_LINE
      if(CopyBuffer(h_ich,1,0,3,ich2_buffer)<2) return(0); // KIJUNSEN_LINE
      if(!ArraySetAsSeries(ich1_buffer,true)) return(0);
      if(!ArraySetAsSeries(ich2_buffer,true)) return(0);
     }

//--- проводим проверку условия и устанавливаем значение для sig
   if(ich1_buffer[1]>ich2_buffer[1]) sig=1;
   else if(ich1_buffer[1]<ich2_buffer[1]) sig=-1;
   else sig=0;8

   if(ich1_buffer[1]>ich2_buffer[1])
      if(ich1_buffer[2]<ich2_buffer[2])
         if(bool_alert)
           {
            Alert(Symbol()+": покупка");
            //--- опускаем флаг
            bool_alert=false;
           }

   if(ich1_buffer[1]<ich2_buffer[1])
      if(ich1_buffer[2]>ich2_buffer[2])
         if(bool_alert)
           {
            Alert(Symbol()+": продажа");
            //--- опускаем флаг
            bool_alert=false;
           }

//--- возвращаем торговый сигнал
   return (sig);
  }
//+------------------------------------------------------------------+
 
Karputov Vladimir:

There is no more than one alert per bar:

Thank you very much!!!
 

Hi All!

How to make an EA to skip 1 signal after a losing trade? ( very good Z-strategy )

Explain in words, the code itself is able to implement.

 
Leanid Aladzyeu:

Hi All!

How to make an EA to skip 1 signal after a losing trade? ( very good Z-strategy )

Explain in words, the code itself is able to implement.

At a loss give a certain value to the global variable of the terminal and reset it to zero at the first signal. The trading function monitors this value and decides whether to open a new trade or not.

In other words, the work order is approximately as follows:

a) Track profit;

b) count signals, check the checkbox in case of loss, if there is no other signal to trade yet, reset the checkbox when the first signal after the loss occurs;

c) check the box and decide whether to trade or wait.

It is more convenient to use GPT, they are saved when the terminal crashes, simple variables in the code can be reset by any sneeze and the Expert Advisor will work with errors.

 
Vitalie Postolache:

At a loss, assign a certain value to the terminal's global variable and reset it to zero at the first signal. The trading function monitors this value and decides whether to open a new trade or not.

That is, the order of work is approximately the following:

a) Track profit;

b) count signals, check the box in case of a loss, if we haven't yet had another signal to trade, reset the box when the first signal comes in after a loss;

c) check the box and decide whether to trade or wait.

GPT is more convenient to use, they are saved when the terminal crashes, simple variables in the code can be reset by any sneeze and the Expert Advisor will work with errors.

All understood except one . How to make a signal counter?
So?
if("Condition" == тру)
i ++;
 
Leanid Aladzyeu:
Got it all but one . How to make a signal counter?
Right?
if("Condition"==true)
i ++;
Like this:Static variables.
 

spits

sl = NormalizeDouble(sl,MarketInfo(symbol,MODE_DIGITS));

possible loss of data due to type conversion .mq4 1697 29

type Doble at SL.


Reason: