Questions from Beginners MQL5 MT5 MetaTrader 5 - page 498

 
Artyom Trishkin:

Not a mistake: a loop with global i (blue), and another loop with local i (red)

The compiler will complain
 
pako:
The compiler will swear.
Yes, it will. But it fits the question better than ever ;)
 
Artyom Trishkin:

Not a mistake: a loop with global i (blue), and another loop with local i (red)

Even I get it... The i (blue) is the flat and the i (red) is the toilet. :))))

 
Good day.Can you advise how to run ZigZag in EA.EA in general working,but left signals a lot,glued to it ZZ,stopped working. Cannot open file ZigZag on the test, no debugging at all, on the demo did not buy a single order, what is there to do?
xtern string   ZigZag                       = "Данные ZigZag";
extern int      InpDepth                      = 20;
extern int      InpDeviation                  = 5;
extern int      InpBackstep                   = 3;

double MacdCurrent,SignalCurrent,SignalMAPrevious,SignalMAThis,
       PriceCurrentOpen,PriceCurrentClose,SignalParabolic,ZZThis,ZZPrevious;
int    ticket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
 if (Digits==3||Digits==5)
 {
  slippage*=10;
 }   
 return(INIT_SUCCEEDED);
} 
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
 datetime EaStartTime = StringToTime(StartTime);  // время начала работы советника
 datetime EaEndTime = StringToTime(EndTime);      // время окончания работы советника
 datetime CurrTime = TimeCurrent();               // это если нужно взять время терминала
 if (CurrTime < EaStartTime || CurrTime >= EaEndTime)
  return;                                         // если еще не время торговать - выход
 {
  MacdCurrent=iMACD(NULL,0,InpFastEMA,InpSlowEMA,InpSignalSMA,Macd_Applied_Price,MODE_MAIN,0);
  SignalCurrent=iMACD(NULL,0,InpFastEMA,InpSlowEMA,InpSignalSMA,Macd_Applied_Price,MODE_SIGNAL,0);
  SignalMAPrevious=iMA(NULL,0,InpMAPeriod,InpMAShift,InpMAMethod,MA_Applied_Price,1);
  SignalMAThis=iMA(NULL,0,InpMAPeriod,InpMAShift,InpMAMethod,MA_Applied_Price,0);
  SignalParabolic=iSAR(NULL,0,InpSARStep,InpSARMaximum,0);
  ZZThis=iCustom(NULL,0,ZigZag,InpDepth,InpDeviation,InpBackstep,0,0);
  ZZPrevious=iCustom(NULL,0,ZigZag,InpDepth,InpDeviation,InpBackstep,0,4);
   if (CountTrades()==0) CheckForOpen();
 }
}  
void CheckForOpen()
 
Alexey Viktorov:

Even I figured it out... The i (blue) is the flat and the i (red) is the toilet. :))))

You should write a popular science book, you obviously have a talent for explaining things simply ))

With a declared

#property strict

will just give a warning that the local i overrides the global one.

declaration of 'i' hides global declaration at line 20 test.mq4 25 13

 
Alexey Volchanskiy:

You should write a popular science book, you obviously have a talent for explaining things simply ))

With a declared

will just give a warning that the local i overrides the global one.

declaration of 'i' hides global declaration at line 20 test.mq4 25 13

My readers have a clear talent for such simple explanations. I have no such talents. A man's not a writer, he's a reader...
 
Alexey Viktorov:
That's what Artem was explaining. I have no such talents... You're not a writer, you're a reader...
Well... we're Siberian cottonmouths ;)
 
Nickolay72:
Hi, can you tell me how to run ZigZag in the EA, in general, working, but the left signals a lot, glued to it ZZ, stopped working. Cannot open file ZigZag on the test, debugging at all does not go, on the demo did not buy a single order. what is there to do?

In the custom indicators is a fileZigZag, if so, is it exactly called there as when you access it from the EA ?

  ZZThis=iCustom(NULL,0,ZigZag,InpDepth,InpDeviation,InpBackstep,0,0);
  ZZPrevious=iCustom(NULL,0,ZigZag,InpDepth,InpDeviation,InpBackstep,0,4);
 
Vladimir Zubov:

If yes, is the fileZigZag located in custom indicators, is it called as it is when accessing it from the Expert Advisor?

You should take the file name in quotes without the extension. It's strange, it compiles well. What was the originalZigZag variable ?

ZZThis=iCustom(NULL,0,"ZigZag",InpDepth,InpDeviation,InpBackstep,0,0);
 

How to level out or compensate for single minus sags in a five

there is a function but it doesn't work

//+------------------------------------------------------------------+
//| Считаем лот в зависимости от полученного профита                 |
//+------------------------------------------------------------------+
double Volume(void)
  {
   double lot=Lots;
//--- Получим доступ к истории
   HistorySelect(0,TimeCurrent());
//--- Сделки в истории
   int orders=HistoryDealsTotal();
//--- Тикет последней сделки  
   ulong ticket=HistoryDealGetTicket(orders-1);
   if(ticket==0)
     {
      Print("Нет сделок в истории! ");
      lot=Lots;
     }
//--- Профит сделки
   double profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
//--- Лот сделки
   double lastlot=HistoryDealGetDouble(ticket,DEAL_VOLUME);
//--- Профит отрицательный
   if(profit<0.0)
     {
      //--- Увеличиваем следующий лот
      lot=lastlot*KLot;
      Print(" Cделка закрыта по стопу! ");
     }
//--- Приводим лот к минимальному
   double minvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
   if(lot<minvol)
      lot=minvol;
//--- Если лот больше максимального то начальный лот
   if(lot>MaxLot)
      lot=Lots;
//--- Возвращаем торговый объем
   return(lot);
  }
//+------------------------------------------------------------------+
//| Смотрим тип последней закрытой сделки                            |
//+------------------------------------------------------------------+
int LastDealType(void)
  {
   int type=0;
//--- Получим доступ к истории
   HistorySelect(0,TimeCurrent());
//--- Сделки в истории
   int orders=HistoryDealsTotal();
//--- Тикет последней сделки  
   ulong ticket=HistoryDealGetTicket(orders-1);
//--- Нет сделок в истории
   if(ticket==0)
     {
      Print("Нет сделок в истории! ");
      type=0;
     }
   if(ticket>0)
     {
      //--- Последняя сделка BUY 
      if(HistoryDealGetInteger(ticket,DEAL_TYPE)==DEAL_TYPE_BUY)
        {
         type=2;
        }
      //--- Последняя сделка SELL
      if(HistoryDealGetInteger(ticket,DEAL_TYPE)==DEAL_TYPE_SELL)
        {
         type=1;
        }
     }
//---
   return(type);
  }