why would RSi on Open prices repaint current 0 bar.??..

 

HI

 why would RSi on Open prices repaint current 0 bar... I ve been on this for a coupel of weeks now and it's just getting me gray hairs..

Here is the code for RSI . why would it repaint current bar???? :)

I use it in the stochastic RSi that has the code below it as well. the stochastic RSI repaints as well..

I am especially interested in knowing why would the stoch rsi repaints since it is based on the RSI. the Stoch rsi is the second code below. thanks 

Why? Anybody?

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int RSIPeriod=14;
//---- buffers
double RSIBuffer[];
double PosBuffer[];
double NegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(3);
   SetIndexBuffer(1,PosBuffer);
   SetIndexBuffer(2,NegBuffer);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,RSIBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="RSI("+RSIPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,RSIPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive;
//----
   if(Bars<=RSIPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=RSIPeriod;i++) RSIBuffer[Bars-i]=0.0;
//----
   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double sumn=0.0,sump=0.0;
      if(i==Bars-RSIPeriod-1)
        {
         int k=Bars-2;
         //---- initial accumulation
         while(k>=i)
           {
            rel=Open[k]-Open[k+1];
            if(rel>0) sump+=rel;
            else      sumn-=rel;
            k--;
           }
         positive=sump/RSIPeriod;
         negative=sumn/RSIPeriod;
        }
      else
        {
         //---- smoothed moving average
         rel=Open[i]-Open[i+1];
         if(rel>0) sump=rel;
         else      sumn=-rel;
         positive=(PosBuffer[i+1]*(RSIPeriod-1)+sump)/RSIPeriod;
         negative=(NegBuffer[i+1]*(RSIPeriod-1)+sumn)/RSIPeriod;
        }
      PosBuffer[i]=positive;
      NegBuffer[i]=negative;
      if(negative==0.0) RSIBuffer[i]=0.0;
      else RSIBuffer[i]=100.0-100.0/(1+positive/negative);
      i--;
     }

 

//---- input parameters
 extern int RSI_Periods=14;
 extern int Percent_K=14;
 extern int Percent_D=9;
 extern int NumOfBars=0;
 
//---- buffers
 double Buffer1[];
 double Buffer2[];
 
//+------------------------------------------------------------------+
 //| Custom indicator initialization function |
 //+------------------------------------------------------------------+
 int init()
 {
 //---- indicators
 SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
 SetIndexBuffer(0,Buffer1);
 SetIndexLabel(0,"StochRSI");
 SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
 SetIndexBuffer(1,Buffer2);
 SetIndexLabel(1,"Signal");
 
//----
return(0);
 }
 //+------------------------------------------------------------------+
 //| Custor indicator deinitialization function |
 //+------------------------------------------------------------------+
 int deinit()
 {
 //---- TODO: add your code here
 
//----
return(0);
 }
 //+------------------------------------------------------------------+
 //| Custom indicator iteration function |
 //+------------------------------------------------------------------+
 int start()
 {
 int counted_bars=IndicatorCounted();
 double Current_RSI,Lowest_RSI,Highest_RSI,sum_K;
 //---- TODO: add your code here
 if(NumOfBars==0)NumOfBars=Bars;
 for(int i=NumOfBars-MathMax(RSI_Periods,Percent_K)-1;i>=0;i--){
Current_RSI=iRSI(NULL,0,RSI_Periods,PRICE_OPEN,i);
 Highest_RSI=Current_RSI;
 Lowest_RSI=Current_RSI;
 
for(int x=0;x<=Percent_K;x++){
 Lowest_RSI=MathMin(Lowest_RSI,iRSI(NULL,0,RSI_Periods,PRICE_OPEN,i+x));
 Highest_RSI=MathMax(Highest_RSI,iRSI(NULL,0,RSI_Periods,PRICE_OPEN,i+x));
 }
 
sum_K=0;
 for(x=0;x<=Percent_D;x++) sum_K=sum_K+Buffer1[i+x];
 
Buffer1[i]=((Current_RSI-Lowest_RSI)/(Highest_RSI-Lowest_RSI))*100;
 Buffer2[i]=sum_K/Percent_D;
 }
 //----
 return(0);
 }
 //+------------------------------------------------------------------+
 
anyone can help?thanks
 
strive23:

HI

 why would RSi on Open prices repaint current 0 bar... I ve been on this for a coupel of weeks now and it's just getting me gray hairs..

Here is the code for RSI . why would it repaint current bar???? :)

I use it in the stochastic RSi that has the code below it as well. the stochastic RSI repaints as well.. Why? Anybody?

 

I copy paste the first code : nope, it does not moving on 1 minute chart.

Haven't check the second code. 

 
phi.nuts:

I copy paste the first code : nope, it does not moving on 1 minute chart.

Haven't check the second code. 


thanks, the second code does repaint. it is based on the RSI. i just checked again. could you please give it a new look? thanks
 
strive23:

thanks, the second code does repaint. it is based on the RSI. i just checked again. could you please give it a new look? thanks

i and x can both equal 0

 Lowest_RSI=MathMin(Lowest_RSI,iRSI(NULL,0,RSI_Periods,PRICE_OPEN,i+x));
 Highest_RSI=MathMax(Highest_RSI,iRSI(NULL,0,RSI_Periods,PRICE_OPEN,i+x));
 
RaptorUK:

i and x can both equal 0


Hi RaptorUK, but iam using Price_Open, so it shouldn't matter if they both equal to 0 right ? it only takes the price once per bar.. where's the catch?

thanks! 

 
strive23:


Hi RaptorUK, but iam using Price_Open, so it shouldn't matter if they both equal to 0 right ? it only takes the price once per bar.. where's the catch?

thanks! 

Ah,  OK,  good point . . .  I guess I should try it on a chart before commenting in haste ;-)

Will the code you have posted work ?
 
RaptorUK:
Ah,  OK,  good point . . .  I guess I should try it on a chart before commenting in haste ;-)

Will the code you have posted work ?


here is the complete code with the preprocessor details.yes it works. thanks

#property indicator_separate_window
 #property indicator_buffers 2
 #property indicator_minimum -5
 #property indicator_maximum 105
 #property indicator_color1 Maroon
 #property indicator_color2 Blue
 
//---- input parameters
 extern int RSI_Periods=14;
 extern int Percent_K=14;
 extern int Percent_D=9;
 extern int NumOfBars=0;
 
//---- buffers
 double Buffer1[];
 double Buffer2[];
 
//+------------------------------------------------------------------+
 //| Custom indicator initialization function |
 //+------------------------------------------------------------------+
 int init()
 {
 //---- indicators
 SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
 SetIndexBuffer(0,Buffer1);
 SetIndexLabel(0,"StochRSI");
 SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
 SetIndexBuffer(1,Buffer2);
 SetIndexLabel(1,"Signal");
 
//----
return(0);
 }
 //+------------------------------------------------------------------+
 //| Custor indicator deinitialization function |
 //+------------------------------------------------------------------+
 int deinit()
 {
 //---- TODO: add your code here
 
//----
return(0);
 }
 //+------------------------------------------------------------------+
 //| Custom indicator iteration function |
 //+------------------------------------------------------------------+
 int start()
 {
 int counted_bars=IndicatorCounted();
 double Current_RSI,Lowest_RSI,Highest_RSI,sum_K;
 //---- TODO: add your code here
 if(NumOfBars==0)NumOfBars=Bars;
 for(int i=NumOfBars-MathMax(RSI_Periods,Percent_K)-1;i>=0;i--){
Current_RSI=iRSI(NULL,0,RSI_Periods,PRICE_OPEN,i);
 Highest_RSI=Current_RSI;
 Lowest_RSI=Current_RSI;
 
for(int x=0;x<=Percent_K;x++){
 Lowest_RSI=MathMin(Lowest_RSI,iRSI(NULL,0,RSI_Periods,PRICE_OPEN,i+x));
 Highest_RSI=MathMax(Highest_RSI,iRSI(NULL,0,RSI_Periods,PRICE_OPEN,i+x));
 }
 
sum_K=0;
 for(x=0;x<=Percent_D;x++) sum_K=sum_K+Buffer1[i+x];
 
Buffer1[i]=((Current_RSI-Lowest_RSI)/(Highest_RSI-Lowest_RSI))*100;
 Buffer2[i]=sum_K/Percent_D;
 }
 //----
 return(0);
 }
 //+------------------------------------------------------------------+

 
strive23:


here is the complete code with the preprocessor details.yes it works. thanks

If this is what you are using to test with then the explanation is simple . . .

Highest_RSI=MathMax(Highest_RSI,iRSI(NULL,0,RSI_Periods,   PRICE_CLOSE,   i+x));

Edit:  OK,  you have just edited your post . . .   I'll try your new code.

 
RaptorUK:


Edit:  OK,  you have just edited your post . . .   I'll try your new code.

Your new code doesn't repaint . . . as far as I can see from watching for a couple of mins. 
 
RaptorUK:
Your new code doesn't repaint . . . as far as I can see from watching for a couple of mins. 


I dontknow..it does on my alpari platform.. the data window for the last data keeps changing..
Reason: