Results 1 to 5 of 5
  1. #1
    Bhavani Deshpande
    Guest

    Default Draw a rectangle

    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),c str(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

  2. #2
    Administrator Rawan-HS's Avatar
    Join Date
    Apr 2015
    Posts
    410

    Default

    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.


    Code:
    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

  3. #3
    Bhavani Deshpande
    Guest

    Default

    Thank you very much for your help. It works..

  4. #4
    Bhavani Deshpande
    Guest

    Default

    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.

  5. #5
    Administrator Rawan-HS's Avatar
    Join Date
    Apr 2015
    Posts
    410

    Default

    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 .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to draw a red color dotted horizontal line ?
    By NCD in forum VertexFX API/VTL Forum
    Replies: 4
    Last Post: 09-27-2015, 06:11 AM
  2. Replies: 2
    Last Post: 07-12-2015, 11:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •