Showing gaps

 

Hi,

I tried the following code to show my gaps:

for(counter = GapsDistance; counter >1; counter--)
{
   if((iClose(NULL,PERIOD_D1,counter)-iOpen(NULL,PERIOD_D1,counter-1)) > GapsMin*pips2dbl && (iClose(NULL,PERIOD_D1,counter)-iOpen(NULL,PERIOD_D1,counter-1))<GapsMax*pips2dbl )
         {
            double low_value = iLow(NULL,PERIOD_D1,iLowest(NULL,PERIOD_D1,MODE_LOW,counter,0));            
            if(low_value > iClose(NULL,PERIOD_D1,counter))
               {               
                  ObjectCreate("Gaps_"+counter, OBJ_RECTANGLE, 0, iTime(NULL,PERIOD_D1,counter), iOpen(NULL,PERIOD_D1,counter-1), Time[0], iClose(NULL,PERIOD_D1,counter) );
                  ObjectSet("Gaps_"+counter, OBJPROP_COLOR, Gray);
                  ObjectSet("Gaps_"+counter, OBJPROP_RAY, true );
                  ObjectSet("Gaps_"+counter, OBJPROP_RAY, False);               
               }       
         }
         if((iOpen(NULL,PERIOD_D1,counter-1)-iClose(NULL,PERIOD_D1,counter)) > GapsMin*pips2dbl  && (iClose(NULL,PERIOD_D1,counter)-iOpen(NULL,PERIOD_D1,counter-1))<GapsMax*pips2dbl)
         {
            double high_value = iHigh(NULL,PERIOD_D1,iHighest(NULL,PERIOD_D1,MODE_HIGH,counter,0));
            if(high_value < iClose(NULL,PERIOD_D1,counter))
               {            
                  ObjectCreate("Gaps_"+counter, OBJ_RECTANGLE, 0,  iTime(NULL,PERIOD_D1,counter), iOpen(NULL,PERIOD_D1,counter-1), Time[counter]+line_adjustment+text_shift, iClose(NULL,PERIOD_D1,counter) );
                  ObjectSet("Gaps_"+counter, OBJPROP_COLOR, Gray);
                  ObjectSet("Gaps_"+counter, OBJPROP_RAY, true );
                  ObjectSet("Gaps_"+counter, OBJPROP_RAY, False);                      
               }                  
         }
}


My code doesn't work, but I can't understand how.

Does anybody see an error??

 
Your 2nd if where you compare Open and Close prices . . . it is if (Open - Close > GapsMin && Close - Open < Gap) shouldn't it be if (Open - Close > Gap && Open - Close < GapsMax)
 

Yes, you are right!

But what can I do, that the rectangle starts on the right candle also in M15, H1,...

 
sunshineh:

Yes, you are right!

But what can I do, that the rectangle starts on the right candle also in M15, H1,...

I don't know what you are trying to do so I can't tell you what you should do . . . perhaps you could explain and show a image to illustrate.
 

When I replace the following line:

if(true) //low_value > iClose(NULL,PERIOD_D1,counter))

I get this picture

:

My aim is it to get the rectangle from the open gaps in the past.

 
sunshineh:


My aim is it to get the rectangle from the open gaps in the past.

The gaps between Highs and Lows ? so why are you checking Opens and Closes ?
 
I want to show both kinds of gaps (High-Low) and (Open-Close).