Download MetaTrader 5
To add comments, please log in or register
Launch agents on an idle PC. It is profitable!
Piratone
38
Piratone 2014.09.02 09:44 

Hi all,

i've created an indicator with three buffers to manage color changing, but i've a problem about refresh of the last candle (candle in realtime)...don't work correctly in that candle (it's not enough a "Windowredraw" instruction).

Thanks for suggest.

Alain Verleyen
Moderator
28701
Alain Verleyen 2014.09.02 10:14  
Piratone:

Hi all,

i've created an indicator with three buffers to manage color changing, but i've a problem about refresh of the last candle (candle in realtime)...don't work correctly in that candle (it's not enough a "Windowredraw" instruction).

Thanks for suggest.

Please post relevant code.
Piratone
38
Piratone 2014.09.02 11:50  

int start()
  {
   int    nLimit,nCountedBars;
   string Y,M,D,Giorno;

   nCountedBars=IndicatorCounted();
   if(nCountedBars>0) nCountedBars--;
   nLimit=Bars-nCountedBars-1;
//----
   for(i=nLimit; i>=0; i--)
     {
      Y=IntegerToString(TimeYear(Time[i]));
      M=IntegerToString(TimeMonth(Time[i]));
      D=IntegerToString(TimeDay(Time[i]));
      Giorno=Y + "." + M + "." + D;
      if(Time[i]==StrToTime(Giorno + " " + OffStart))
         {
          ExtOBVBuffer[i]=xxx;
          ExtAppoggioBuffer[i]=xxx;
          Vol=xxx;
          Min=Vol;
          Max=Vol;
          Up=false;Dw=false;Nt=true;
          continue;
         }

      if(i==Bars-1)
        {
         ExtOBVBuffer[i]=xxx;
         ExtAppoggioBuffer[i]=xxx;
        }
      else
        {
         double dCurrentPrice=GetAppliedPrice(COHLMTW, i);
         double dPreviousPrice=GetAppliedPrice(COHLMTW, i+1);
         if(dCurrentPrice==dPreviousPrice)
           {
            Vol=Vol;
           }
         else
           {
            if(dCurrentPrice<dPreviousPrice)
               {
                if(Nt)Vol=ExtOBVBuffer[i+1];
                if(Up)Vol=ExtOBVBufferUp[i+1];
                if(Dw)Vol=ExtOBVBufferDw[i+1];
               }
            else
               {
                if(Nt)Vol=ExtOBVBuffer[i+1];
                if(Up)Vol=ExtOBVBufferUp[i+1];
                if(Dw)Vol=ExtOBVBufferDw[i+1];
               }
           }
        }

      if(Vol>=Min+DeltaPuntiInd){Up=true;Dw=false;Nt=false;Min=Vol;}
      if(Vol<=Max-DeltaPuntiInd){Up=false;Dw=true;Nt=false;Max=Vol;}

      if(Nt){ExtOBVBuffer[i]=Vol;ExtOBVBufferUp[i]=EMPTY_VALUE;ExtOBVBufferDw[i]=EMPTY_VALUE;}
      if(Up){ExtOBVBuffer[i]=EMPTY_VALUE;ExtOBVBufferUp[i]=Vol;ExtOBVBufferDw[i]=EMPTY_VALUE;}
      if(Dw){ExtOBVBuffer[i]=EMPTY_VALUE;ExtOBVBufferUp[i]=EMPTY_VALUE;ExtOBVBufferDw[i]=Vol;}

      if(Vol<Min)Min=Vol;
      if(Vol>Max)Max=Vol;

      ExtAppoggioBuffer[i]=Vol;

      WindowRedraw();
     }
//----
   return(0);
  }

Keith Watford
Moderator
8026
Keith Watford 2014.09.02 11:59  
Piratone:

Hi all,

i've created an indicator with three buffers to manage color changing, but i've a problem about refresh of the last candle (candle in realtime)...don't work correctly in that candle (it's not enough a "Windowredraw" instruction).

Thanks for suggest.

Your post is not very clear, but I have an idea of what is causing your problem.

When your code is checking conditions for Bar[0], conditions can change from tick to tick. This can result in more than 1 buffer receiving a value for that bar. 

You can get over this by setting all buffers on Bar[0] to EMPTY_VALUE before checking the conditions.

The same goes for Bar[1] because it is possible that the last tick is missed when it was Bar[0] and so it needs to be checked that conditions did not change on the last tick. 

whroeder1
13656
whroeder1 2014.09.02 12:33  
Piratone: i've a problem about refresh of the last candle (candle in realtime)...don't work correctly in that candle
if(Nt)Vol=ExtOBVBuffer[i+1];
if(Up)Vol=ExtOBVBufferUp[i+1];
if(Dw)Vol=ExtOBVBufferDw[i+1];
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. In the initial fill Nt/Up/Dn contains the state of the previous candle and is used to compute the next. At the start of the loop you need to set those variables to the state they were at the previous candle. You're currently using the last calculated state of the current candle.
Piratone
38
Piratone 2014.09.02 13:05  

Thanks Gum,

i've tried to insert this instructions:

      ExtOBVBuffer[i]=EMPTY_VALUE;
      ExtOBVBufferUp[i]=EMPTY_VALUE;
      ExtOBVBufferDw[i]=EMPTY_VALUE;
      ExtAppoggioBuffer[i]=EMPTY_VALUE;

before

      if(Nt){ExtOBVBuffer[i]=Vol;ExtOBVBufferUp[i]=EMPTY_VALUE;ExtOBVBufferDw[i]=EMPTY_VALUE;}
      if(Up){ExtOBVBuffer[i]=EMPTY_VALUE;ExtOBVBufferUp[i]=Vol;ExtOBVBufferDw[i]=EMPTY_VALUE;}
      if(Dw){ExtOBVBuffer[i]=EMPTY_VALUE;ExtOBVBufferUp[i]=EMPTY_VALUE;ExtOBVBufferDw[i]=Vol;}

but not change.

if i don't use different color, so one buffer, all is ok.

Piratone
38
Piratone 2014.09.02 15:34  
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. In the initial fill Nt/Up/Dn contains the state of the previous candle and is used to compute the next. At the start of the loop you need to set those variables to the state they were at the previous candle. You're currently using the last calculated state of the current candle.



Thanks WH, you've inspirated my mind :)

Next time, i'll use SRC button.

/
To add comments, please log in or register