Arrows with custom indicator only working for sell signal and only for one previously closed candle

 

Hi,

Sorry for my poor skills with programming. I have a volume indicator and based on this indicator I would like two arrows to show up. Code for my arrows indicators is shown below which I have taken from this link.

https://www.mql5.com/en/code/7332

#property  indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red


extern bool  ArrowsSignal = true;

int limit=1;int counter;
double CrossUp[];
double CrossDown[];
double prevtime;
double Range, AvgRange;




int init()
{
   SetIndexStyle(0, DRAW_ARROW, EMPTY, 2);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY, 2);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
   
   return(0);
}

int deinit()
{
   return(0);
}



int start() {

long up=(long)iCustom(NULL,0,"Better_Volume",0,1);
long down=(long)iCustom(NULL,0,"Better_Volume",4,1);
long pinky=(long)iCustom(NULL,0,"Better_Volume",5,1);


for(int i=1;i<=limit;i++){
   
counter=i;
Range=0;
AvgRange=0;
   
for (counter=i ;counter<=i+9;counter++)
     {
      AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
   
Range=AvgRange/10;

if(up > 2500){if(ArrowsSignal == true)CrossUp[i] = Low[i] - Range*0.5;}

if(down > 2500){if(ArrowsSignal == true)CrossDown[i] = High[i] + Range*0.5;}

if ((CrossUp[0] > 2000) && (CrossDown[0] > 2000)) { prevtime = 0; }
if ((CrossUp[0] == Low[0] - Range*0.5) && (prevtime != Time[0]))
    {
     prevtime = Time[0];
}
if ((CrossDown[0] == High[0] + Range*0.5) && (prevtime != Time[0]))
    {
     prevtime = Time[0];
}
}

   return (0);
}

Custom indicator is volume based.

Problem is this code only shows down arrows and only one occurrence for the recently closed candle. How can I see all previous signals ?

Thanks

 
s9919: only one occurrence for the recently closed candle.
  1. long up=(long)iCustom(NULL,0,"Better_Volume",0,1);
    long down=(long)iCustom(NULL,0,"Better_Volume",4,1);
    long pinky=(long)iCustom(NULL,0,"Better_Volume",5,1);
    
    for(int i=1;i<=limit;i++){
    Perhaps you should use values per bar "i" instead of only bar one.
  2. int limit=1;
    Perhaps you should calculate more than one bar.
 
WHRoeder:
s9919: only one occurrence for the recently closed candle.
  1. Perhaps you should use values per bar "i" instead of only bar one.
  2. Perhaps you should calculate more than one bar.

Thanks. It is working for previous bars now. I also fixed it to show blue arrows now.
 But arrows are showing up on each candle instead of proper signal. I have the same checking condition in expert advisor too for same indicator and it works fine with that EA. Somehow it is not working correctly for these arrows.

Files:
vpa.mq4  6 kb
 
#1
 

Thank you for your help.

but I could not understand your answer. I have attached both of the indicators. Arrows are still not working, I tried many times but I do not understand what is wrong with them. The same values work for the EA though.

Files:
arrow.mq4  2 kb
 
main indicator
Files:
 
long up=(long)iCustom(NULL,0,"Better_Volume",0,1);
long down=(long)iCustom(NULL,0,"Better_Volume",4,1);
long pinky=(long)iCustom(NULL,0,"Better_Volume",5,1);

for(int i=1;i<=limit;i++){
What part of "Perhaps you should use values per bar "i" instead of only bar one," is unclear?
 
Tried it. does not work still. Thanks
 
"Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.