Script to draw rectangles (Help please!)
- Don't attach a image, insert the image
- You are created objects with the name whatever+barNumber. After the first run you will be trying to create another with the same name. Don't use barnumber, either Bars-barNumber or Time[barnumber] are unique.
Why not just get the values from the M15 time-frame?
{if(Period()==PERIOD_M5)
{
for(int y=1; y<=96; y++)
{
double top=iHigh(NULL,PERIOD_M15,y);
double bot=iLow(NULL,PERIOD_M15,y);
double bar_open=iOpen(NULL,PERIOD_M15,y);
double bar_close=iClose(NULL,PERIOD_M15,y);
datetime begin_time=iTime(NULL,PERIOD_M15,y);
datetime end_time=iTime(NULL,PERIOD_M15,y-1)-1;
string rectanglename=StringConcatenate("M15 tracker ",begin_time);
if(bar_close>=bar_open) //Previous bull on M15
{
bool draw=ObjectCreate(rectanglename,OBJ_RECTANGLE,0,begin_time,bot,end_time,top);
bool colorin=ObjectSet(rectanglename,OBJPROP_COLOR,clrSlateGray);
bool linew=ObjectSet(rectanglename,OBJPROP_WIDTH,1);
bool lines=ObjectSet(rectanglename,OBJPROP_STYLE,STYLE_SOLID);
}
if(bar_close<=bar_open) //Previous bear on M15
{
bool draw=ObjectCreate(rectanglename,OBJ_RECTANGLE,0,begin_time,bot,end_time,top);
bool colorin=ObjectSet(rectanglename,OBJPROP_COLOR,clrWhite);
bool linew=ObjectSet(rectanglename,OBJPROP_WIDTH,1);
bool lines=ObjectSet(rectanglename,OBJPROP_STYLE,STYLE_SOLID);
}
}
}You could also use CopyRates() to get the data for M15.
Note that if the open is equal to the close, both if conditions will return true.
GumRai:
Ah, amazing! Didn't even think of that. Thank you!
Why not just get the values from the M15 time-frame?
You could also use CopyRates() to get the data for M15.
Note that if the open is equal to the close, both if conditions will return true.
WHRoeder:
- Don't attach a image, insert the image
- You are created objects with the name whatever+barNumber. After the first run you will be trying to create another with the same name. Don't use barnumber, either Bars-barNumber or Time[barnumber] are unique.
Noted for next time.
Thanks
Hey guys,
Just need some help please. I would like to draw rectangles on the M5 chart. Each rectangle will represent M15. I basically want to show the previous days worth of M15 on M5. When I drop the script on the chart it only draws the attached picture, with the Highs and Lows incorrect? Below is my code.
Any help is appreciated!
if(Period()==PERIOD_M5) { for(int y=1; y<=64; y++) { double top=High[iHighest(NULL,PERIOD_M5,MODE_HIGH,(2*y)+1,(2*y)-1)]; double bot=Low[iLowest(NULL,PERIOD_M5,MODE_LOW,(2*y)+1,(2*y)-1)]; string rectanglename=StringConcatenate("M15 tracker",y); if(Close[(2*y)-1]>=Open[(2*y)+1]) //Previous bull on M15 { bool draw=ObjectCreate(rectanglename,OBJ_RECTANGLE,0,Time[(2*y)-1],bot,Time[(2*y)+1],top); bool colorin=ObjectSet(rectanglename,OBJPROP_COLOR,clrSlateGray); bool linew=ObjectSet(rectanglename,OBJPROP_WIDTH,1); bool lines=ObjectSet(rectanglename,OBJPROP_STYLE,STYLE_SOLID); } if(Close[(2*y)-1]<Open[(2*y)+1]) //Previous bear on M15 { bool draw=ObjectCreate(rectanglename,OBJ_RECTANGLE,0,Time[(2*y)-1],bot,Time[(2*y)+1],top); bool colorin=ObjectSet(rectanglename,OBJPROP_COLOR,clrWhite); bool linew=ObjectSet(rectanglename,OBJPROP_WIDTH,1); bool lines=ObjectSet(rectanglename,OBJPROP_STYLE,STYLE_SOLID); } } }