How do you shift an Object to the left?

 

Hi Guys,

I need to shift the bars generated by the code below:

int i;

for(i=0; i<500; i++){

   string name1 = "barBody" + i;
   string name2 = "barClose" + i;
   int type = OBJ_TREND;
   int window = 0;
   datetime time1 = Time[i];
   double price1 = High[i];
   datetime time2 = Time[i];
   double price2= Low[i];
   datetime time3=0;
   double price3=0;
   color colour = Black;

   if(i==0){
      int j = 0;
      for(j=0; j<500; j++){
         string nameA = "barBody" + j;
         string nameB = "barClose" + j;
         ObjectDelete(nameA);
         ObjectDelete(nameB);
      }
   }

   if(Close[i]==Close[i+1]){
      colour = Yellow;  
   } else {     
      if(Close[i]<Close[i+1]){
         colour = Red;
      } else {
         colour = Blue;
      }
   }
   ObjectCreate(name1, type, window, time1, price1, time2, price2, time3, price3);
   ObjectSet(name1, OBJPROP_COLOR, colour);
   ObjectSet(name1, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(name1, OBJPROP_WIDTH, 2);
   ObjectSet(name1, OBJPROP_RAY, false);

   ObjectCreate(name2, type, window, time1, Close[i], time2+60, Close[i], time3, price3);
   ObjectSet(name2, OBJPROP_COLOR, colour);
   ObjectSet(name2, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(name2, OBJPROP_WIDTH, 2);
   ObjectSet(name2, OBJPROP_RAY, false);
}

As RaptorUK said on  https://www.mql5.com/en/forum/144642, I can't shorten the candle close, so the only alternative I see is to shift the bars to create a gap between them. Any other suggestions more than welcomed.

Can anyone let me know how to do this?

Many thanks in advance! 

 
  1. See my Polyline code.
  2. string nameA = "barBody" + j;
    Don't use shift number with objects. Time or running count.
 
WHRoeder:
  1. See my Polyline code.
  2. Don't use shift number with objects. Time or running count.

Thank you for pointing me in the right direction!


1. I've been trying to make something out of it for a couple of hours now. A bit above my head for now :)

2. You are more than right. I have found a nice little function that does exactly what I wanted: ObjectsDeleteAll();. So, instead of messing about with any object names, I just clean the screen before repainting.

 

Hi WHRoeder,

I've been banging my head since yesterday morning and I don't understand how to make the shift to the left work.

Also, when I apply the template at http://www.forexfactory.com/showthread.php?t=418683 I see the close of the price as a trendline and there is a gap. How did this chap do this?

Many thanks in advance for any help putting me in the right direction. 

 

You don't need a shift to the left.

Create your trendline object "name"+Time[1]. You are done. it moves with the chart.

 
Not really. The issue I have is not painting the bars (it's doing it at every tick) but to shorten the horizontal trendline so it doesn't bleed into the next bar's space. If you look at the charts created by the chap at ForexFactory, it looks like a proper bar without the open. That is what I'm trying to replicate.
 
dquelhas:
Not really. The issue I have is not painting the bars (it's doing it at every tick) but to shorten the horizontal trendline so it doesn't bleed into the next bar's space. If you look at the charts created by the chap at ForexFactory, it looks like a proper bar without the open. That is what I'm trying to replicate.

Have your tried the Indicator that you give a link to on ForexFactory ? try it and change the chart colours so you can see the real MT4 bars,  not only the bars created by the Indicator.  You will see that the indicator paints it's bar across 3 MT4 bars,  so it would paint it's open horizontal trend line from bar 1 to bar 2,  it paints it's vertical trend line at bar 2 and it's closing horizontal trendline between bar 2 and bar 3 

See the attached chart,  it is a composite of 2 charts,  one with just the Indicator (above the red line),  the second with the Indicator bars and the original MT4 bars (below the red line).  I have numbers some examples,  with 1, 2,3 to show how the Indicator bars span 3 x MT4 bars.

 

 

RaptorUK,

I use it on a daily basis :)

Many many thanks for your expert analysis.

I have no idea on how to replicate it. I guess that is why the default times are changed (to allow the objects span) and that is way above my knowledge and skills (I'm far from being a mql4 developer). Is there an easy approach to replicate what he's done? 

 
dquelhas:

RaptorUK,

I use it on a daily basis :)

Many many thanks for your expert analysis.

I have no idea on how to replicate it. I guess that is why the default times are changed (to allow the objects span) and that is way above my knowledge and skills (I'm far from being a mql4 developer). Is there an easy approach to replicate what he's done? 

The easiest way to replicate what he has done is to replicate what he has done.  The simple inescapable fact is that you can only place Objects or Object endpoints (line ends) at bar positions not in between bars. This isn't the case with MT5 though.