Drawing Arrows with ObjectCreate()

 

Hi All! I am trying to display Arrows for EACH day on a chart with different Periods.. The code below is logically correct. However, I only get two arrors printed on bar=0. Can anyone suggest if I am doing something wrong or if there is a limitation to using ObjectCreate function.

Заранее благодарю :)


int start()
{
int chartPeriod = Period();
int numOfBarsPerDay = (24*60) / chartPeriod;
for(int i=0; i<Bars; i=i+numOfBarsPerDay )
{
datetime time1=iTime(0,0,i);
double priceH=iHigh(Symbol(),PERIOD_D1,i);
double priceL=iLow(Symbol(),PERIOD_D1,i);
ObjectSet("highLine"+i,OBJPROP_COLOR,LimeGreen);

ObjectSet("lowLine"+i,OBJPROP_COLOR,Crimson);

ObjectCreate("highLine"+i,OBJ_ARROW,0, time1,priceH);
ObjectCreate("lowLine"+i,OBJ_ARROW,0, time1,priceL);
}
return(0);
}
 

each object has a unique identifier. you need to change that for each object you want to draw.

Normally this is implemented by adding a counter:

ObjectCreate("highLine"+counter,OBJ_ARROW,0, time1,priceH);
ObjectCreate("lowLine"+counter,OBJ_ARROW,0, time1,priceL);

ObjectSet("highLine"+counter,OBJPROP_COLOR,LimeGreen);

ObjectSet("lowLine"+counter,OBJPROP_COLOR,Crimson);
counter++;


//z

 
sambazone:

Hi All! I am trying to display Arrows for EACH day on a chart with different Periods.. The code below is logically correct. However, I only get two arrors printed on bar=0. Can anyone suggest if I am doing something wrong or if there is a limitation to using ObjectCreate function.

Заранее благодарю :)


int start()
{
int chartPeriod = Period();
int numOfBarsPerDay = (24*60) / chartPeriod;
for(int i=0; i<Bars; i=i+numOfBarsPerDay )
{
datetime time1=iTime(0,0,i);
double priceH=iHigh(Symbol(),PERIOD_D1,i);
double priceL=iLow(Symbol(),PERIOD_D1,i);
}
return(0);
}

  1. ObjectSet("highLine"+i,OBJPROP_COLOR,LimeGreen);
    ObjectSet("lowLine"+i,OBJPROP_COLOR,Crimson);
    
    ObjectCreate("highLine"+i,OBJ_ARROW,0, time1,priceH);
    ObjectCreate("lowLine"+i,OBJ_ARROW,0, time1,priceL);
    Create before setting. You're creating an arrow but don't set what arrow

  2. int numOfBarsPerDay = (24*60) / chartPeriod;
    for(int i=0; i<Bars; i=i+numOfBarsPerDay )
    This won't work as there are variable bars in a day, especially Sunday is only two hours long. Furthermore you use iHigh(Symbol(),PERIOD_D1,i) but i in your code is shift of the current timeframe, not D1 bars. Use iBars(PERIOD_D1) to control the loop in D1 shift, iTime(PERIOD_D1) to get the time.
 

Ok, after giving it more thought.. here is the final version that works..

The indicator works on ALL time frames drawing day's low and day's high arrows on a chart..

Thanks a lot for your input!

int start()

{

double priceH,priceL;

int chartPeriod = Period();

int numOfBarsDay = (24*60) / chartPeriod;

int limit;

int counted_bars=IndicatorCounted();

//---- check for possible errors

if(counted_bars<0) return(-1);

//---- the last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(int i=0; i<limit; i=i+numOfBarsDay)

{

datetime time1=iTime(0,0,i);

int ShiftHigh=iHighest(Symbol(),0,MODE_HIGH,numOfBarsDay,i);

int ShiftLow=iLowest(Symbol(),0,MODE_LOW,numOfBarsDay,i);

priceH=High[ShiftHigh];

priceL=Low[ShiftLow];

ObjectCreate("highLine"+i,OBJ_ARROW,0, time1, priceH);

ObjectSet("highLine"+i,OBJPROP_COLOR,LimeGreen);

ObjectCreate("lowLine"+i,OBJ_ARROW,0, time1, priceL);

ObjectSet("lowLine"+i, OBJPROP_COLOR,Crimson);

}

return(0);

}

Reason: