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

 
PokrovMT5:

Maxim, good day! Thanks for the variant, mine is almost the same, it also works, butAlekseu Fedotov suggested it and I wrote that there is an idea how to correct it?



If you don't mind redrawing (for example, you will recalculate it anyway, like now) - return from the OnCalculate function the place from which you want to recalculate it, in your case - the bar of the previous hour.

return rates_total-iBarShift(_Symbol,_Period,time[0]-TimeMinute(time[0])*60-TimeSeconds(time[0])-1 ); // about this, written "out of hand and not checked", to demonstrate the approach.

 
MakarFX I did, but that doesn't solve the issue for
// #property  copyright "Copyright © 2005, Yura Prokofiev"
// #property  link      "Yura.prokofiev@gmail.com"
#property  strict
#property  indicator_separate_window
#property  indicator_buffers 3
 
extern int      Barrs  = 10;     // Баров для расчета
extern string   simvol = "EURGBP";
double Buf_0[], Buf_1[], Buf_2[];

void OnInit()
{
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2,Yellow);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2,Red);
   IndicatorDigits((int)SymbolInfoInteger(simvol,SYMBOL_DIGITS));

   SetIndexBuffer(0,Buf_0);
   SetIndexBuffer(1,Buf_1);
   SetIndexBuffer(2,Buf_2);

   IndicatorShortName("Fisher "+simvol);
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
}

int start()
{
   int    i, limit, counted_bars=IndicatorCounted();
   double prev,current;
   double Value=0, Value1=0, Value2=0, Fish=0, Fish1=0, Fish2=0;
   double price, MinL=0, MaxH=0;

   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(i=0; i<limit; i++)
   {
      MaxH = iHigh(simvol,   0, iHighest(simvol,  0, MODE_HIGH,Barrs,i));
      MinL = iLow (simvol,   0, iLowest (simvol,  0, MODE_LOW, Barrs,i));
      price = (iHigh(simvol, 0, i) + iLow(simvol, 0, i))/2;
      if(MaxH != MinL)
      Value = 0.33*2*((price-MinL)/(MaxH-MinL)-0.5) + 0.67*Value1;     
      Value=MathMin(MathMax(Value,-0.999),0.999); 
      Buf_0[i]=0.5*MathLog((1+Value)/(1-Value))+0.5*Fish1;
      Value1=Value;
      Fish1=Buf_0[i];
   }
   bool up=true;
   for(i=limit-2; i>=0; i--)
   {
      current=Buf_0[i];
      prev=Buf_0[i+1];
      if(((current<0)&&(prev>0))||(current<0))   up= false;    
      if(((current>0)&&(prev<0))||(current>0))   up= true;
      Buf_1[i]=0;  Buf_2[i]=0;
      if(!up) Buf_2[i]=current;
      else    Buf_1[i]=current;
   }
   return 0;
}

Bottom old, top new

The chart timeframe used is the one where the indicator - zeros stand

 
YarTrade:

Can you please tell me how to reset the buffer when a new bar appears, but so that the previous data is not erased and is displayed on the chart. For some reason I can't reset the buffer to zero and whena new barappears, new data is overlaid on the old accumulated data. What am I wrong in my code? Thanks for the clarification.

When a new bar appears, the terminal adds new null items to the buffers. In lines 3 ... 6 is exactly zeroing them . Everything else is saved
 
STARIJ:
When a new bar appears, the terminal adds new null elements to the buffers. In lines 3 ... ... 6 are exactly zeroed. All other elements are preserved

Why do the bars in the histogram grow immediately with the appearance of a new bar and continue to grow, but the next bar grows when the next bar appears and the previous one does?

 
YarTrade:

Why do the bars in the histogram immediately after the appearance of a new bar have the growth of the previous bar, and then continue to grow, and the next bar has, at the appearance of the next bar, the growth of the previous one?

You have a summation
V2 = V1 + V2;
 
Hello everyone, I can not figure it out myself, some sort of poltergeist, although I may be inattentive.
int ticket_order=0;
void OnTick()
{
  if(OrdersTotal()==0)
   {
    // километр кода
    ticket_order=OrderSend(Symbol(),up_down,lots,Ask,3,0,0);
    }
    if(OrdersTotal()==1)
   {
     OrderSelect(ticket_order,SELECT_BY_TICKET);
     bool Ans=OrderModify(ticket_order,Price,SL,TP,0);
    }
}
     
   
I don't know what to blame, maybe I should use OrderModify() or OrderSelect to send a ticket by reference and change it somehow?
 
ijonhson: error message wrong ticket(OrderModify())
There was a similar one. Rearrange the first and second conditional statements along with the guts - might help.
 
STARIJ:

Bottom old, top new

The timeframe of the chart used is the one where the indicator - zeros stand

Thank you HUGE. That's what I wanted.
 
ijonhson:
Greetings all, can't figure it out myself,

This makes it easier to find the error:

if ( OrderSelect(ticket_order,SELECT_BY_TICKET) )
  if ( OrderModify(ticket_order,Price,SL,TP,0) ) {}
But I think before OrderSelect() it should be tiket_order=(correct_ticket)
 
ijonhson:
Hello all, I can not understand myself, some sort of poltergeist, although I may be inattentiveIn such a combination in the strategy tester, the error incorrect ticket (OrderModify()), and on the n-th order, not on the first or second, I do not know what to blame, maybe in OrderModify(), or OrderSelect ticket is passed by reference and it somehow changes?
You select order by ticket and then, after kilometre of code, try to modify it. But it may already be closed at that time.
Reason: