Distance arrows / candles

 

Hello everyone. I need help to solve a problem on the distance of the arrows from the candles.

I have these two codes:

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue;  
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i) < 50 
      )
        {
         Buffer1[i] = Low[i] - 3 * myPoint; 
        }
      else
        {
         Buffer1[i] = 0;
        }
     }
   return(rates_total);
  }

 

With this code, the distance between the arrows and candles remains constant and that is fine. 

 

With your help I have written this code which evaluates the alert after a few seconds from open candel.

This is the code that I would use: 

int start()
{
  static datetime BarStart=0;
   static bool check=false;
    if(BarStart!=Time[0])
     {
      BarStart=Time[0];
      check=true;
     }
 if(check && TimeCurrent()>=Time[0]+3) 

     {
      check=false;
     
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, Period1, PRICE_CLOSE, 0) < 50
      
      )
        {
         Buffer1[0] = Low[0] - 3 * myPoint); 
         
        }
      else
        {
         Buffer1[0] = 0;
     }
     }
      
return(0);
}
 //-----------------------------------------------------------------------------------------------------------------------------

 

 But with this code, the arrows often enter into the candle. you can resolve this problem by keeping constant the distance arrows / candle?

Thank you all, Massimo.

 

Try adding (Outside of any if() condition)

if(Buffer[0]!=0)
  Buffer1[0] = Low[0] - 3 * myPoint);
   
 

Hello GumRai, thanks for the reply.

I tried to do as you suggested, but definitely something wrong. I stated Buffer as Array and I entered the condition outside any if () condition. Where am I wrong?

int start()
{
  static datetime BarStart=0;
   static bool check=false;
    if(BarStart!=Time[0])
     {
      BarStart=Time[0];
      check=true;
     }
 if(check && TimeCurrent()>=Time[0]+3) 

     {
      check=false;

 if(Buffer[0]!=0)
 {
  Buffer1[0] = Low[0] - 1 * myPoint;
}
     
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, Period1, PRICE_CLOSE, 0) < 50
      
      )
        {
         Buffer1[0] = Low[0] - 3 * myPoint); 
         
        }
      else
        {
         Buffer1[0] = 0;
     }
     }
      
return(0);
}
 //-----------------------------------------------------------------------------------------------------------------------------


Excuse me but I am a neophyte. This is the result you get


I thank you for the answer, Max.
 
omissamf:

Hello GumRai, thanks for the reply.

I tried to do as you suggested, but definitely something wrong. I stated Buffer as Array and I entered the condition outside any if () condition. Where am I wrong?


Excuse me but I am a neophyte. This is the result you get


I thank you for the answer, Max.

No you did not. It is inside the if condition

if(check && TimeCurrent()>=Time[0]+3) 
      static datetime BarStart=0;
      static bool check=false;
      if(BarStart!=Time[0])
        {
         BarStart=Time[0];
         check=true;
        }
      if(check && TimeCurrent()>=Time[0]+3)
        {
         check=false;
         //Indicator Buffer 1
         if(iRSI(NULL,PERIOD_CURRENT,Period1,PRICE_CLOSE,0)<50)
           {
            Buffer1[0]=Low[0]-3*myPoint;
           }
         else
           {
            Buffer1[0]=0;
           }
        }

      if(Buffer[0]!=0)
        {
         Buffer1[0]=Low[0]-1*myPoint;
        }
 
GumRai, I tried your suggestion, but it does not work.
Thanks, Max.
 

I just noticed

      if(Buffer[0]!=0)
        {
         Buffer1[0]=Low[0]-1*myPoint;
        }

should be

      if(Buffer1[0]!=0)
        {
         Buffer1[0]=Low[0]-1*myPoint;
        }

..

 
Hello GumRai, I did as you told me. I tried with buffer1 [0] but the result is what you see in the picture.

Thanks for your patience, Massimo.


This is the code I used:

int start()
{

  static datetime BarStart=0;
   static bool check=false;
    if(BarStart!=Time[0])
     {
      BarStart=Time[0];
      check=true;
     }
   if(check && TimeCurrent()>=Time[0]+Ritardo_Secondi)
     {
      check=false;
      //Check Condition
    

//_________________________________
 
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, Period1, PRICE_CLOSE, 0) < 30
    
      )
        {
         Buffer1[0] = Low[0] - 1 * myPoint;
        
        }
      else
        {
         Buffer1[0] = 0;
        }
        
      if(Buffer1[0]!=0)
        {
         Buffer1[0]=Low[0]-1*myPoint;
        }
      //Indicator Buffer 2
      if(iRSI(NULL, PERIOD_CURRENT, Period1, PRICE_CLOSE, 0) > 70
     
      )
        {
         Buffer2[0] = High[0] + 1 * myPoint; 
        
        }
      else
        {
         Buffer2[0] = 0;
        }
        
      if(Buffer2[0]!=0)
        {
         Buffer2[0]=High[0]+1*myPoint;
        }
     }
      
return(0);
}



 

Once again you have put your highlighted code inside the block of code controlled by

if(check && TimeCurrent()>=Time[0]+Ritardo_Secondi)

.

 
GumRai Hello, I understand. So it is not possible to correct this error?
Hello, and thanks for everything, Massimo.
 
GumRai Hello, thanks for all the advice you gave me. I modified the code, now it seems to work but would like to have from you the confirmation that is fine.
Thanks again for your patience and professionalism.
Greetings, Massimo.
int start()
{

if(Buffer1[0]!=0)
        {
         Buffer1[0]=Low[0]-1*myPoint;
        }
        
        
        if(Buffer2[0]!=0)
        {
         Buffer2[0]=High[0]+1*myPoint;
        }
        
        
  static datetime BarStart=0;
   static bool check=false;
    if(BarStart!=Time[0])
     {
      BarStart=Time[0];
      check=true;
     }
   if(check && TimeCurrent()>=Time[0]+3)
     {
      check=false;
      //Check Condition
    //_________________________________
 
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, 0) < 30
           )
        {
         Buffer1[0] = Low[0]; 
        }
      else
        {
         Buffer1[0] = 0;
        }
        
      //Indicator Buffer 2
      if(iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, 0) > 70
      
      )
        {
         Buffer2[0] = High[0];
        }
      else
        {
         Buffer2[0] = 0;
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
 
It should be ok now as the code is outside of any condition block, so will be checked every tick
Reason: