PDA

View Full Version : Draw a rectangle



Bhavani Deshpande
11-08-2015, 02:43 PM
Hi,

I want to draw a rectangle on the chart. I have used the below code.

symbName= symbolname (1,true)
dt=itime(cstr(symbName),chartPeriod(0),1)
dt= replace (dt,"/","-")


symbolinfodouble chartsymbol(0),ChartPeriod(0),Period
Period=Period/2.0191
dt2=unixtime(itime(cstr(symbName),chartPeriod(0),1 ))+cint(3000*Period)

dt2 = dateadd ("s",dt2,"01/01/1970 00:00:00")
dt2=replace(dt2,"/","-")


dim getClose
getClose=iclose(cstr(symbname),chartPeriod(0),1)


AddObject 0,"RECT",OBJ_RECTANGLE,0,cstr(dt),cdbl(getClose),cstr(dt2) ,cdbl(getClose+.001)
ObjectSet 0,"RECT",OBJPROP_STYLE, STYLE_SOLID

I can see the object "RECT" in the object list. Once I set the property "Draw object to background" I can see the rectangle on the chart. I do not know how to set this property in code.
Please help.

Thanks

Rawan-HS
11-10-2015, 01:08 PM
Hello :)


I see that you don't use our method correctly.


symbolinfodouble chartsymbol(0),ChartPeriod(0),Period

However try the following code which is create a rectangle on the chart based the open price & close price for selected bars & over specific time.




Const COLOR_RED = 255
Public Sub main()
''''TODO: Script program start method


dim symbName
dim dt2
dim dt
Dim date
dim getClosePrice
dim getOpenPrice
dim UnixDate
dim Period
dt= GetTime(0,Bars(0)-10)
getOpenPrice= GetOpen(0,Bars(0)-10)
Period=1
UnixDate= Clng(UnixTime(Cdate(dt))) + Clng(180*Period)
dt2 = DateAdd("s", UnixDate , "01/01/1970 00:00:00")
date = day(dt2)&"/"&month(dt2)&"/"&year(dt2)&" "&hour(dt2)&":"&minute(dt2)&":"&second(dt2)
getClosePrice= GetClose(0,Bars(0)-7)


AddObject 0,"RECT",OBJ_RECTANGLE,0,cstr(dt),cdbl(getOpenPrice),cstr( date),cdbl(getClosePrice)
ObjectSet 0,"RECT",OBJPROP_STYLE, STYLE_DASHDOT
ObjectSet 0,"RECT" , OBJPROP_COLOR , COLOR_RED
'
End Sub


let me know if you need further assistance

Bhavani Deshpande
11-12-2015, 03:18 AM
Thank you very much for your help. It works..:)

Bhavani Deshpande
11-12-2015, 03:27 AM
It works perfect. But why are you subtracting 10 from Bars(0) for getTime and get openprice? I did not get that..
Many thanks for your help.

Rawan-HS
11-12-2015, 08:09 AM
Dear :)

we are subtracting 10 from bars count to get time for last 10 bars ,and about open price it just a simple you can change it with the price that you want .