multiple objects with createobject(); solution required

Examples step by step how to make your own automated strategy or user indicator
Message
Author
forextester
Posts: 33
Joined: Thu Feb 19, 2009 8:40 am

multiple objects with createobject(); solution required

#1 Postby forextester » Thu Feb 26, 2009 9:44 am

Dear Mike,

Createobject(); does not accept anything but '' or string arrays.

but in Metatrader this command does. eg

i= index etc

createobject('object ' + i );

i++;

this loop creates a new object everytime. object 1, object 2, object 3.

What do i do to make objects with ease. i cannot initialize an array of 1000 of string my self. eg name[1000].

Please provide me a simple solution.

regards and thanks,

Sheraz

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

Re: multiple objects with createobject(); solution required

#2 Postby Terranin » Thu Feb 26, 2009 11:29 am

forextester wrote:Dear Mike,

Createobject(); does not accept anything but '' or string arrays.

but in Metatrader this command does. eg

i= index etc

createobject('object ' + i );

i++;

this loop creates a new object everytime. object 1, object 2, object 3.

What do i do to make objects with ease. i cannot initialize an array of 1000 of string my self. eg name[1000].

Please provide me a simple solution.

regards and thanks,

Sheraz


Simple solution: ObjectName := 'My object ' + IntToStr(i);
or: ObjectName := format('My object %d', [i]);
Hasta la vista
Mike

forextester
Posts: 33
Joined: Thu Feb 19, 2009 8:40 am

#3 Postby forextester » Fri Feb 27, 2009 10:25 am

Thanks Mike,

it worked.

Hourof(time()) tells you the hour.

How do i find out minute of time?
Which format do i use to print time? none work although %.f returns bizarre values.

regards and thanks.

Sheraz

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

#4 Postby Terranin » Fri Feb 27, 2009 10:42 am

forextester wrote:Thanks Mike,

it worked.

Hourof(time()) tells you the hour.

How do i find out minute of time?
Which format do i use to print time? none work although %.f returns bizarre values.

regards and thanks.

Sheraz


MinuteOf

DateTimeToStr(date)
Hasta la vista

Mike

forextester
Posts: 33
Joined: Thu Feb 19, 2009 8:40 am

#5 Postby forextester » Fri Feb 27, 2009 11:24 am

thanks,

it worked.

1- How do i find day ie monday, tuesday, friday etc?

2- Do you have an updated help file?
I have purchased ver 1.0 build 12. its help file contains less than 60 % of the solutions i seek. and you have all the answers.

regards and thanks,

Sheraz

forextester
Posts: 33
Joined: Thu Feb 19, 2009 8:40 am

#6 Postby forextester » Fri Feb 27, 2009 11:34 am

Dear Mike,

I have defined a global variable
"counted_bars"
. it retains its value when i resume from pause, which is good.

but when i press connect and choose start from the first date available, the global variable still retains its value, causing problem.

How do i fix the problem.

regards and thanks.
Sheraz

Code: Select all

//---------------------------------------------------------------------------
// V line
//---------------------------------------------------------------------------
library Vline;

uses
  SysUtils, DateUtils, classes, graphics, windows, IndicatorInterfaceUnit;

var
counted_bars: double= 9;            // to detect new bar.
i: integer= 0;                      // to create multiple objects.

//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------

procedure Init; stdcall;
begin
  // define properties
  IndicatorShortName('V Line');
  SetOutputWindow(ow_ChartWindow);

end;


//---------------------------------------------------------------------------
// Deinitialize indicator
//---------------------------------------------------------------------------
procedure Done; stdcall;
begin
counted_bars:=9;
end;

//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------

procedure Calculate(index: integer); stdcall;

begin



  if (Bars < 10) then
  begin
//  Print('loaded bars are less than %.4f');
  exit;
  end;

//counted_bars:=Bars;

if (counted_bars>=Bars)   then        // exit if no new bar has come yet.
    begin
    exit;
    end
    else
    begin
    counted_bars:= counted_bars +1;
//    print(format('no of bar is %d',[Bars] ));
    end;


  // create text

      if (Hourof(Time(0)) = 5) and (Minuteof(Time(0))= 0)then
      begin

      //     create vertical line
             if not(ObjectExists('V_line' + intToStr(i)) ) then
                begin
                ObjectCreate('V_line' + intToStr(i), obj_VLine, 0, Time(0), 0);

                Print (format('Vline %d has been created', [i]));
                i:= i+1;
                end
                else
                Print (format('v_line %d already exists', [i]));

       end;
end;


exports

Init, Done, Calculate;

end.

}

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

#7 Postby Terranin » Fri Feb 27, 2009 10:01 pm

forextester wrote:thanks,

it worked.

1- How do i find day ie monday, tuesday, friday etc?

2- Do you have an updated help file?
I have purchased ver 1.0 build 12. its help file contains less than 60 % of the solutions i seek. and you have all the answers.

regards and thanks,

Sheraz


I can not attach help file for Delphi. these are standard functions. So you better find this in Delphi help file, look for DayOf() function in standard DateUtils module. I really can not (and have no time) to teach you how to program with Borland Delphi. I can only help with questions about Forex Tester API.
Last edited by Terranin on Fri Feb 27, 2009 11:39 pm, edited 1 time in total.
Hasta la vista

Mike

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

#8 Postby Terranin » Fri Feb 27, 2009 10:04 pm

forextester wrote:Dear Mike,

I have defined a global variable
"counted_bars"
. it retains its value when i resume from pause, which is good.

but when i press connect and choose start from the first date available, the global variable still retains its value, causing problem.

How do i fix the problem.

regards and thanks.
Sheraz



You can not use this variable at all. You should use only "index" that system provides to you when you entered Calcualte procedure.
1. Check if this the right bar.
2. Check if object exists on this bar.
3. If not exists - create new one and set its parameters. As a unique name you can use combination of name and date/time.
Hasta la vista

Mike

forextester
Posts: 33
Joined: Thu Feb 19, 2009 8:40 am

#9 Postby forextester » Sat Feb 28, 2009 12:40 am

Terranin wrote:
forextester wrote:thanks,

it worked.

1- How do i find day ie monday, tuesday, friday etc?

2- Do you have an updated help file?
I have purchased ver 1.0 build 12. its help file contains less than 60 % of the solutions i seek. and you have all the answers.

regards and thanks,

Sheraz


I can not attach help file for Delphi. these are standard functions. So you better find this in Delphi help file, look for DayOf() function in standard DateUtils module. I really can not (and have no time) to teach you how to program with Borland Delphi. I can only help with questions about Forex Tester API.


Sorry about that Mike,

I will try my best next time not to bother you with Delphi related questions.

thanks

forextester
Posts: 33
Joined: Thu Feb 19, 2009 8:40 am

#10 Postby forextester » Sat Feb 28, 2009 1:00 am

Terranin wrote:
forextester wrote:Dear Mike,

I have defined a global variable
"counted_bars"
. it retains its value when i resume from pause, which is good.

but when i press connect and choose start from the first date available, the global variable still retains its value, causing problem.

How do i fix the problem.

regards and thanks.
Sheraz



You can not use this variable at all. You should use only "index" that system provides to you when you entered Calcualte procedure.
1. Check if this the right bar.
2. Check if object exists on this bar.
3. If not exists - create new one and set its parameters. As a unique name you can use combination of name and date/time.


Dear Mike,

Please correct me if i am wrong.
the Calculate procedure at every single tick and the value of "index" will always be zero for the current bar.

I would appreciate a little hint about how to check if this is a new bar and not another tick, using "index" only.

thanks and regards
Sheraz

forextester
Posts: 33
Joined: Thu Feb 19, 2009 8:40 am

#11 Postby forextester » Sat Feb 28, 2009 1:30 am

Dear Mike,

a vertical line is created once a day at 5:00. after a few days i noticed that some strange labels are appearing at the start of my chart. these labels are increasing and overloading my chart.

Could you please look at my code and advice a solution?

Thanks and regards,
Sheraz
[/img]
Attachments
Vline.rar
the source code.
(812 Bytes) Downloaded 230 times
screen.jpg
the screen.
screen.jpg (47.34 KiB) Viewed 12402 times

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

#12 Postby Terranin » Mon Mar 02, 2009 10:23 pm

forextester wrote:
Terranin wrote:
forextester wrote:Dear Mike,

I have defined a global variable
"counted_bars"
. it retains its value when i resume from pause, which is good.

but when i press connect and choose start from the first date available, the global variable still retains its value, causing problem.

How do i fix the problem.

regards and thanks.
Sheraz



You can not use this variable at all. You should use only "index" that system provides to you when you entered Calcualte procedure.
1. Check if this the right bar.
2. Check if object exists on this bar.
3. If not exists - create new one and set its parameters. As a unique name you can use combination of name and date/time.


Dear Mike,

Please correct me if i am wrong.
the Calculate procedure at every single tick and the value of "index" will always be zero for the current bar.

I would appreciate a little hint about how to check if this is a new bar and not another tick, using "index" only.

thanks and regards
Sheraz


In Calculate procedure it is not always index=0. When you put indicator for the first time it will be Bars-1..0, then in Testing Mode when all bars are calculated it will be 0 to calculate only last bar.

In your case you may check if this bar meets some conditions and there is no vertical line object on this bar. You can check the object presence by giving names to objects like line2008010122:00. So, you convert Time(0) into this string and check if ObjectExists( string ).
Hasta la vista

Mike


Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 17 guests