Download MetaTrader 5

EA tester + ObjectCreate() Function

To add comments, please log in or register
dani
18
dani  

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.

Carl Schreiber
6689
Carl Schreiber  

"..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!

Keith Watford
Moderator
9641
Keith Watford  

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 

whroeder1
14778
whroeder1  
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
To add comments, please log in or register