Debugging EA?

 

When you are working with an EA, is it possible to put the values of a created variable in a graph/log or do you need to create the same variable in an indicator in order to see the values?

Any tips on how to develop/debug EA are appreciated.

Thanks

 

Print(variable) -> this will be shown in terminal

Comment(variable) -> this will be shown on graph under OHLC comments

GlobalVariableSet(variable) -> this will be shown when U press F3

 

Write vairables to a file

Hi

I debug by writing the variables to a file. Then I open the file in excel and try to figure out if all went according to plan. It is a pretty long winded way of doing things - but it does work.

If anyone knows how to delete a file in the 'int init()' please let me know, as I always have to delete the file before running a new test. Thanks.

...

if(TP > 0)

realTP = Ask + TP * Point;

ticket = OrderSend(Symbol(),OP_BUY,lots,Ask,slippage,realSL,realTP,nameEA+" - Magic: "+magicEA+" ",magicEA,0,Red); // Buy

if(ticket < 0) {

Print("OrderSend (" + nameEA + ") failed with error #" + GetLastError() + " --> " + ErrorDescription(GetLastError()));

writetofile("8","Error buyagain?",ErrorDescription(GetLastError()));

} else {

firstbuysl = realSL;

writetofile("12za","first buy", OrderTicket());

}

void writetofile(string breakpoint1, string description1, string description2) {

int handle;

handle=FileOpen("bedug1.dat", FILE_CSV|FILE_WRITE|FILE_READ, ";");

if(handle>0){

// write data

FileSeek(handle,0,SEEK_END);

FileWrite(handle, breakpoint1, description1,description2, CurTime(), Year(), Month(), Day(),Hour(),Minute(),Seconds(), Bid, Ask,tstop, long_ma, numberofbuys, numberofsells, firstbuycheck, firstsellcheck,firstbuyprice, firstsellprice,firstbuysl, firstsellsl, isBuying, isSelling, isClosing, lasttradeprice, x,y,sell_trade_again, buy_trade_again,shortEma, longEma, isCrossed);

FileClose(handle);}

}
 

File writes from stratergy tester

Please note files writen while doing 'stratergy test' are writen to .../tester/Files

and I found a way to write the results out to a different file each time. In 'start int' one has to make a file name based on the current time - then use this file name as a file to write to. I will hopefully post this solution up here tonight.

Reason: