EA tester + ObjectCreate() Function

Back to topics list To post a new topic, please log in or register
avatar
4
oronz 2015.03.01 00:50
 

Hi There!!!!

Can an EA  create objects during a test?

example: I create an EA and I want to test it ,during the test it opens 3 orders.

Can it automatically creates 3 vertical lines in correspondence with the opening time of the 3 orders ?

I tried this code:

datetime opentime
string name="vlineorder";

//omitted code

void start()
{

//omitted code

if n=100  //open order condition 
 {
  OrderSend (Symbol(),OP_SELL,0.01,Bid,3,Ask+stoploss*Point,Ask-takeprofit*Point);
  opentime=Time[0];
  string time=TimeToStr(opentime,TIME_DATE|TIME_SECONDS);    
  Print ("opentime=",time);   //it shows open time order on log window
  ObjectCreate(0,name,OBJ_VLINE,0,opentime,0);
 }
}

 this EA works but  ObjectCreate function doesn't work.

 

avatar
2017
gooly 2015.03.01 01:07 #
 

"..but  ObjectCreate function doesn't work."

1) It does work, but your code is wrong!

2) Check the return of ObjectCreate(..) and if false check the error code (all to be read in the editor's reference!!)

3) You created an object but you didn't set it properties - look for examples - in the editor's reference!!

4) Follow the link in the editor's reference for "OBJ_VLINE" you'll find a perfect example!

avatar
Moderator
3404
GumRai 2015.03.01 02:48 #
 

Give objects individual names, once an object exists, a new object with the same name cannot be created

As you already create the string time 

ObjectCreate(0,name,OBJ_VLINE,0,opentime,0);

//Change to

ObjectCreate(0,name+time,OBJ_VLINE,0,opentime,0);

 although I would avoid using something like  time as a variable name in code because of the possibility of mixing with Time or time in an indicator

I would name it maybe bar_time, or open_time 

avatar
12983
WHRoeder 2015.03.01 14:38 #
 
GumRai:  although I would avoid using something like  time as a variable name in code because of the possibility of mixing with Time or time in an indicator
Agree
  1. Time[] always exists
  2. time[] exists in indicators

Back to topics list  

To add comments, please log in or register