Errors, bugs, questions - page 564

 
Cloud nerwork using error.
What is the cause of this problem? Can't use cloud resources.
 
Urain:

Explain.


There was a preliminary announcement of planned changes. The final list of changes in the next build will be published after the release of the build itself.
 
Rosh:
There has been a preliminary announcement of planned changes. The final list of changes in the next build will be published after the release of the build itself.
Thank you.
 

I have gnawed long and hard into the indicator code, until I have absolutely despaired of catching errors. I did not write it in "Dummies" because I suspect not errors made by me, but errors in the work of the terminal.

The purpose of the indicator is to place fractals on the current timeframe from another timeframe and add new ones as the new fractal bars appear. Please do not suggest other ways to place fractal arrows, it is not about that; we have fundamental questions concerning this code and, perhaps, related to the incorrect operation of the terminal. I took an example from the iFractals Help which was logically shortened by half (to the upper fractals only) for easier perception and a bit of code from the standard Fractals.mq5 was borrowed. I had to be very meticulous to avoid any misunderstanding: I have bound almost all possible arrays and cleaned the worked arrays, freed the handle of the called indicator, which did not give any noticeable difference in the results. The following problems and peculiarities in operation were noticed:

  1. When I start the terminal for the first time, open a new chart window, and apply a freshly compiled indicator, all of the fractals accumulate on the zero bar at the end of the history (only one seems to be placed), instead of being placed in accordance with the idea and logic of the code. The correct placement can only be initiated by jumping to other timeframes (sometimes not even the first time). Also, when deleting the indicator from the chart, closing the chart window, recompiling, opening a new window and applying the indicator, we almost always manage to get the required Fractal Arrangement immediately. To see the erroneous effect, the terminal must be completely unloaded and all steps of step 1 must be repeated. 1. Perhaps the problem lies in the lifetime of the handle of the called indicator and its specific behavior at the initial start of the custom indicator? In the case of incorrect arrangement of fractals (when they are all "compressed" on the zero bar), the output of all elements of exact_extremum in the loop gives zero results, but the output of the adjacent values of TimeUpBuffer, on the basis of which it is calculated and filled, always shows consistently different time dates. Hence the question: what prevents it from being filled during the initial indicator creation, if it fills correctly with the correct values during the next times?
  2. The same code that inherited the same problem, but now the emphasis is on a completely different feature. In this indicator, we can refrain from binding of some intermediate-calculated arrays as INDICATOR_CALCULATIONS to indicator buffers. This is the initial code of the indicator. Everything seems to be ok, apart from p. I seem to be fine with everything, except for point 1.
  3. But in order to be very clever, let's try to follow the best recommendations and link the arrays for intermediate calculations to the indicator buffers:
    #property indicator_chart_window
    #property indicator_buffers 3
    #property indicator_plots   1
    
    [...]
    
    int OnInit()
      {
       [...]
       SetIndexBuffer(1,PreliminaryUpBuffer,INDICATOR_CALCULATIONS);
       SetIndexBuffer(2,exact_extremum,INDICATOR_CALCULATIONS);
       [...]
      }
    compile and run. As a result we will get an error message in Terminal Expert Advisor's logs: 2011.11.11 07:42:03 (AUDUSD,H1) Array out of range, line:
                CopyHigh(_Symbol,PERIOD_M1,TimeUpBuffer[shift+1]-1,
                                           TimeUpBuffer[shift],
                                           exact_extremum);
    
    Fractal placement on some timeframes is either absent or sporadic.
  4. Initiate an Ouija session, make magical hand passes, obey automatic writing, and replace:
    #property indicator_chart_window
    #property indicator_buffers 3
    #property indicator_plots   1
    for:
    #define NUMBER 1
    
    #property indicator_chart_window
    #property indicator_buffers NUMBER+2
    #property indicator_plots   NUMBER
    Whether or not this is correct, but it incomprehensibly works!

I have a request to noosphere inhabitants and especially to developers: could you please explain each item and advise how to debug indicator code (if I will not change its implementation).

Thanks and files attached.

P.S.: In file names were parentheses, but after uploading they are spoiled.

 

How do I determine the current profit on a magic trade?

this code returns profits on closed trades and i need them on open trades

#include <Trade\Trade.mqh>
CTrade trade;
void OnTick()
  {
   double profit=0;
   if(PositionSelect(Symbol()))profit=PositionGetDouble(POSITION_PROFIT);
   if(profit==0) trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,0.1,SymbolInfoDouble(Symbol(),SYMBOL_ASK),0,0,"");
   if(profit>1) trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,0.1,SymbolInfoDouble(Symbol(),SYMBOL_ASK),0,0,"");
   
   double ld_return=0;  
   HistorySelect(0,TimeTradeServer());
   for(int i=HistoryDealsTotal()-1;i>=0;i--) // По всем сделкам от конца к началу
     {
      ulong ticket=HistoryDealGetTicket(i); // Определение тикета сделки и ее выделение
      if(ticket!=0) 
      {
      if(HistoryDealGetInteger(ticket,DEAL_TYPE)<2)
      ld_return+=HistoryDealGetDouble(ticket,DEAL_PROFIT);
      }
     }     
   Comment(ld_return);   
  }
 

How do I know why the initialisation fails?

I reset errors before the start of initialization with

ResetLastError();

At the end of initialization I see an error

Print("Ошибка " + IntegerToString(GetLastError()));

I end up getting on the Expert Advisors tab

2011.11.11 08:47:51 SimpleExpert (EURUSD,H1) Error 0

On the "Journal" tab

2011.11.11 08:47:51 Experts initializing of SimpleExpert (EURUSD,H1) failed

 
Konstantin83:

How do I know why initialisation fails?

Before starting the initialisation I reset the errors with the function

ResetLastError();

At the end I display an error

Print("Ошибка " + IntegerToString(GetLastError()));

I get the following result in the Experts tab

2011.11.11 08:47:51 SimpleExpert (EURUSD,H1) Error 0

On the "Journal" tab

2011.11.11 08:47:51 Experts initializing of SimpleExpert (EURUSD,H1) failed

Does OnInit return 0 or not 0?
 
stringo:
Does OnInit return 0 or not 0?

OnInit returns true, somehow missed it.

Thanks, that's ok.

 
ddd06:

How do I determine the current profit on a magic trade?

This code returns profits on closed trades, but I need them on open ones

Look at Dmitry's(Integer) article. Everything is optimally implemented there. Article:Optimal Method of Cumulative Position Volume Calculation by Specified Magic Number.
 
Good afternoon, started to write multivariant, I call iMA, for some reason in the real trade everything works fine, as soon as I run in the tester an error expert removed because indicator 'Moving Average' cannot load [4804], what is the indicator on the indicator, not very clear, I could not find a plausible answer on the Internet. Please advise, I would be very grateful to you.
Документация по MQL5: Технические индикаторы / iMA
Документация по MQL5: Технические индикаторы / iMA
  • www.mql5.com
Технические индикаторы / iMA - Документация по MQL5