Great EA in backtest! - page 114

 
DudeWorks:
also heres a file write sample, its right out of the MT editor...

This will allow ya to log to a csv file, modify for your output you wish.

int handle;

datetime orderOpen=OrderOpenTime();

handle=FileOpen("c:\cyberia_log.csv", FILE_CSV|FILE_WRITE, ';');

if(handle>0)

{

FileWrite(handle, Close[0], Open[0], High[0], Low[0], TimeToStr(orderOpen));

FileClose(handle);

}

I'm on IBFX live, I can forward test live for ya on micro lots. However i have other live trades on the account so I'd have to strip out the CT results seperately.

PM me for email address

I have to get all this printed to the file as well as whatever indicators I evaluate....currently it's just printing these to the journal.

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, SlipPage, StopLoss, Bid - (TakeProfit * Point), "NeuroCluster-testing-AI-LS1", MagicNumber, 0, Green);

if(ticket > 0)

{

if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))

{

int handle;

datetime orderOpen=OrderOpenTime();

handle=FileOpen("C:\cyberia_log.csv", FILE_CSV|FILE_WRITE, ';');

if(handle>0)

{

FileWrite(handle,"Hour: ",TimeHour(CurTime())," Minute: ",TimeMinute(CurTime()));

FileWrite(handle,"SellPossibilityMid*SellPossibilityQuality:", SellPossibilityMid*SellPossibilityQuality);

FileWrite(handle,"BuyPossibilityMid*BuyPossibilityQuality:", BuyPossibilityMid*BuyPossibilityQuality);

FileWrite(handle,"UndefinedPossibilityMid*UndefinedPossibilityQuality:", UndefinedPossibilityMid*UndefinedPossibilityQuality);

FileWrite(handle,"UndefinedSucPossibilityQuality:", UndefinedSucPossibilityQuality);

FileWrite(handle,"SellSucPossibilityQuality:", SellSucPossibilityQuality);

FileWrite(handle,"BuySucPossibilityQuality:", BuySucPossibilityQuality);

FileWrite(handle,"UndefinedPossibilityQuality:", UndefinedPossibilityQuality);

FileWrite(handle,"SellPossibilityQuality:", SellPossibilityQuality);

FileWrite(handle,"BuyPossibilityQuality:", BuyPossibilityQuality);

FileWrite(handle,"UndefinedSucPossibilityMid:", UndefinedSucPossibilityMid);

FileWrite(handle,"SellSucPossibilityMid:", SellSucPossibilityMid);

FileWrite(handle,"BuySucPossibilityMid:", BuySucPossibilityMid);

FileWrite(handle,"UndefinedPossibilityMid:", UndefinedPossibilityMid);

FileWrite(handle,"SellPossibilityMid:", SellPossibilityMid);

FileWrite(handle,"BuyPossibilityMid:", BuyPossibilityMid);

FileClose(handle);

}

not sure exactly how to do this...yet is this correct? this isn't generating a file. it must not be right.

2006.11.08 11:21:54 2006.10.06 12:08 Cyberia Trader1.9 R2.2 AlertEuro EURUSDm,H1: error(4101): wrong file name

2006.11.08 11:21:54 2006.10.06 12:08 Cyberia Trader1.9 R2.2 AlertEuro: absolute file path "C:\cyberia_log.csv" is not allowed

????

what's wrong about it?

 

ok that's better....

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, SlipPage, StopLoss, Bid - (TakeProfit * Point), "NeuroCluster-testing-AI-LS1", MagicNumber, 0, Green);

if(ticket > 0)

{

if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))

{

datetime sorderOpen=OrderOpenTime();

handle=FileOpen("cyberia_log.csv", FILE_CSV|FILE_WRITE, ';');

if(handle!=-1)

{

FileWrite(handle,"Hour: ",TimeHour(CurTime())," Minute: ",TimeMinute(CurTime()));

FileWrite(handle,"SellPossibilityMid*SellPossibilityQuality:", SellPossibilityMid*SellPossibilityQuality);

FileWrite(handle,"BuyPossibilityMid*BuyPossibilityQuality:", BuyPossibilityMid*BuyPossibilityQuality);

FileWrite(handle,"UndefinedPossibilityMid*UndefinedPossibilityQuality:", UndefinedPossibilityMid*UndefinedPossibilityQuality);

FileWrite(handle,"UndefinedSucPossibilityQuality:", UndefinedSucPossibilityQuality);

FileWrite(handle,"SellSucPossibilityQuality:", SellSucPossibilityQuality);

FileWrite(handle,"BuySucPossibilityQuality:", BuySucPossibilityQuality);

FileWrite(handle,"UndefinedPossibilityQuality:", UndefinedPossibilityQuality);

FileWrite(handle,"SellPossibilityQuality:", SellPossibilityQuality);

FileWrite(handle,"BuyPossibilityQuality:", BuyPossibilityQuality);

FileWrite(handle,"UndefinedSucPossibilityMid:", UndefinedSucPossibilityMid);

FileWrite(handle,"SellSucPossibilityMid:", SellSucPossibilityMid);

FileWrite(handle,"BuySucPossibilityMid:", BuySucPossibilityMid);

FileWrite(handle,"UndefinedPossibilityMid:", UndefinedPossibilityMid);

FileWrite(handle,"SellPossibilityMid:", SellPossibilityMid);

FileWrite(handle,"BuyPossibilityMid:", BuyPossibilityMid);

FileClose(handle);

}

else

{

int err;

err=GetLastError();

Print("error(",err,"): ",ErrorDescription(err));

return(0);

}

ok this is generating a file but the file only contains 1 entry not EVERY order....oy

 
DudeWorks:
I'll code it for ya, give me til tonight, tell me what else you want to dump

Along with the cyberia logics above...

I'm thinking of testing the bears and bulls powers indicator, the cci, the 3 values of the adx, the macd and stochastic, the rsi, and a 1MA based on close running in the current bar.(the MA of the close) If there are other indicators which you think might work to be evaluated, go ahead and dump them too. You get the idea I'm just wanting to generate a profile so the more angles the better really...up to a point I guess.

There is one other thing I have to add. A piece of work I did on another EA that saves the account equity value when an order opens and then compares it to the account equity value when the order closes and determines if the trade was a winner or a loser...I need this data dump to include the outcome of the trades like that too so we know which category to put the trade in when we analyze it.

I think I'm going to rework that to go off the orderopenprice and ordercloseprice instead since multiple trades may change the account equity...wait a minute....

I'm half way there already I've got this in the code already just needs a little more tweaking...

/////////////record outcomes/////////////////

void RecordLongOutcomes()

{

if(Bid<OrderOpenPrice())

{

OrderSelect(OrderTicket(),SELECT_BY_POS,MODE_TRADES);

Print(" Loser Long ",OrderTicket()," Opened: ",OrderOpenPrice()," Closed: ", Bid);

}

return (0);

}

void RecordShortOutcomes()

{

if(Ask>OrderOpenPrice())

{

OrderSelect(OrderTicket(),SELECT_BY_POS,MODE_TRADES);

Print(" Loser Short ",OrderTicket()," Opened: ",OrderOpenPrice()," Closed: ", Bid);

}

return(0);

}

 

so what were working toward here..also same Idea I had a while back but was too lazy to do it... is to log all the variables and indicator values at the time of each order so we can see exactly whats happening at each order to determin correlations

I've been curious which possibilities were at when it finally gave an order signal so this should really display..

However the width of each row might be pretty wide but I think we can get in if we make so we only log the indicators that are actually selected.

MT4 file width is 64 fields I think.. so thats plenty to paly with.

I pm'd my email to ya

 
DudeWorks:
so what were working toward here..also same Idea I had a while back but was too lazy to do it... is to log all the variables and indicator values at the time of each order so we can see exactly whats happening at each order to determin correlations

I've been curious which possibilities were at when it finally gave an order signal so this should really display..

However the width of each row might be pretty wide but I think we can get in if we make so we only log the indicators that are actually selected.

MT4 file width is 64 fields I think.. so thats plenty to paly with.

I pm'd my email to ya

Precisely! Precision is indeed what we are looking for in our filters and this just might reveal how to make it work to us.

ok great, I'll send you my Patient project to explore but don't let that distract you from getting this data dump, ok?

I welcome having a developer with more experience around when I get stuck. I'm still a novice really, with not alot of experience yet.

As for the output. Nothing you put out of this platform is likely to exceed the dimensions of excel. What I do need is for it to be easily identifiable so when I import it into excel I can see what I'm working with rather than just a bunch of undocumented numbers all smushed together separated by delimiters. I need data labels with each value. We are looking at 15 CT fields plus 8 indicators, CCI, RSI, 1MA, bearspower, bullspower,adx(threevalues) plus however you do the macd and stochastics if you figure 6 for that then the total fields = 29 plus the results of winning (see previous post) or losing =30 the open and close and the time add 3 Grand Total=33 as I count it.

33 fields / order. that ought to reveal something eh? One other little favor, if you can make that datetime actually print out (print to file) something a human can understand for datetime instead of the intergervalue the computer uses that would help too.

 

Something about this gave me the error message...

'invalid ticket for OrderClose function' until I turned off the OrderSelect.

but I think you can see what I'm trying to get out of it.

/////////////record outcomes/////////////////

void RecordLongOutcomes()

{

//OrderSelect(OrderTicket(),SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)

{

if(OrderType()==OP_BUY)

{

if(OrderOpenPrice() + Spread < OrderClosePrice())

{

datetime borderOpen=OrderOpenTime();

handle=FileOpen("cyberia_log.csv", FILE_CSV|FILE_WRITE, ';');

if(handle!=-1)

{

FileWrite(handle,"Winning Long OrderTicket: ",OrderTicket()," Opened @: ",OrderOpenPrice()," Closed @: ",OrderClosePrice()," Order Open Time: ",borderOpen);

FileClose(handle);

Print(" Winning Long ",OrderTicket()," Opened: ",OrderOpenPrice()," Closed: ", Bid);

}

else

{

int err;

err=GetLastError();

Print("error(",err,"): ",ErrorDescription(err));

return(0);

}

}

else

{

datetime buyorderOpen=OrderOpenTime();

handle=FileOpen("cyberia_log.csv", FILE_CSV|FILE_WRITE, ';');

if(handle!=-1)

{

FileWrite(handle,"Losing Long OrderTicket: ",OrderTicket()," Opened @: ",OrderOpenPrice()," Closed @: ",OrderClosePrice()," Order Open Time: ",buyorderOpen);

FileClose(handle);

Print(" Losing Long ",OrderTicket()," Opened: ",OrderOpenPrice()," Closed: ", Bid);

}

else

{

int err1;

err=GetLastError();

Print("error(",err1,"): ",ErrorDescription(err1));

return(0);

}

}//if win or lose

}//if buy

}//if symbol and magic number

return (0);

}//record long outcomes

void RecordShortOutcomes()

{

//OrderSelect(OrderTicket(),SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)

{

if(OrderType()==OP_SELL)

{

if(OrderOpenPrice() - Spread > OrderClosePrice())

{

datetime borderOpen=OrderOpenTime();

handle=FileOpen("cyberia_log.csv", FILE_CSV|FILE_WRITE, ';');

if(handle!=-1)

{

FileWrite(handle,"Winning Short OrderTicket: ",OrderTicket()," Opened @: ",OrderOpenPrice()," Closed @: ",OrderClosePrice()," Order Open Time: ",borderOpen);

FileClose(handle);

Print(" Winning Short ",OrderTicket()," Opened: ",OrderOpenPrice()," Closed: ", Bid);

}

else

{

int err3;

err3=GetLastError();

Print("error(",err3,"): ",ErrorDescription(err3));

return(0);

}

}

else

{

datetime sellorderOpen=OrderOpenTime();

handle=FileOpen("cyberia_log.csv", FILE_CSV|FILE_WRITE, ';');

if(handle!=-1)

{

FileWrite(handle,"Losing Short OrderTicket: ",OrderTicket()," Opened @: ",OrderOpenPrice()," Closed @: ",OrderClosePrice()," Order Open Time: ",sellorderOpen);

FileClose(handle);

Print(" Losing Short ",OrderTicket()," Opened: ",OrderOpenPrice()," Closed: ", Bid);

}

else

{

int err4;

err4=GetLastError();

Print("error(",err4,"): ",ErrorDescription(err4));

return(0);

}

}//if win or lose

}//if buy

}//if symbol and magic number

return (0);

}//record short outcomes
 

that code I just added to record the outcomes works well except for the filewrite()

I am now generating the file but it only has one entry which seems to be the final order run thru the tester, so what I think is happening for me is that it's overwriting each entry rather than appending it to the end of the file. If I knew how to fix that I could probably pull this data dump off now.

 
Aaragorn:
ok this is generating a file but the file only contains 1 entry not EVERY order....oy

The file is being overwritten every time you open it. One solution is to open the file in the init() function and close it in deinit()

 
tururo:
The file is being overwritten every time you open it. One solution is to open the file in the init() function and close it in deinit()

I'm not sure I understand how to use the read and write flags.

I see these in examples like this...

handle=FileOpen("cyberia_log.csv", FILE_CSV|FILE_WRITE, ';');

or

handle=FileOpen("cyberia_log.csv", FILE_CSV|FILE_WRITE, ';');

what about is this possible?

handle=FileOpen("cyberia_log.csv", FILE_CSV|FILE_READ|FILE_WRITE, ';');

you see I don't understand how to append to the end exactly.

I am not sure how to open it in the init()

THEN

append to it each new order on the end

THEN

close it in the deinit()

I imagine it is something like.

handle=FileOpen("cyberia_log.csv", FILE_CSV|FILE_READ, ';');

in the init and then

FileWrite(handle,"Order Open Time: ",sorderOpen);

FileWrite(handle,"SellPossibilityMid*SellPossibilityQuality:", SellPossibilityMid*SellPossibilityQuality);

FileWrite(handle,"BuyPossibilityMid*BuyPossibilityQuality:", BuyPossibilityMid*BuyPossibilityQuality);

FileWrite(handle,"UndefinedPossibilityMid*UndefinedPossibilityQuality:", UndefinedPossibilityMid*UndefinedPossibilityQuality);

FileWrite(handle,"UndefinedSucPossibilityQuality:", UndefinedSucPossibilityQuality);

FileWrite(handle,"SellSucPossibilityQuality:", SellSucPossibilityQuality);

FileWrite(handle,"BuySucPossibilityQuality:", BuySucPossibilityQuality);

FileWrite(handle,"UndefinedPossibilityQuality:", UndefinedPossibilityQuality);

FileWrite(handle,"SellPossibilityQuality:", SellPossibilityQuality);

FileWrite(handle,"BuyPossibilityQuality:", BuyPossibilityQuality);

FileWrite(handle,"UndefinedSucPossibilityMid:", UndefinedSucPossibilityMid);

FileWrite(handle,"SellSucPossibilityMid:", SellSucPossibilityMid);

FileWrite(handle,"BuySucPossibilityMid:", BuySucPossibilityMid);

FileWrite(handle,"UndefinedPossibilityMid:", UndefinedPossibilityMid);

FileWrite(handle,"SellPossibilityMid:", SellPossibilityMid);

FileWrite(handle,"BuyPossibilityMid:", BuyPossibilityMid); FileWrite(handle,"Winning Short OrderTicket: ",OrderTicket()," Opened @: ",OrderOpenPrice()," Closed @: ",OrderClosePrice()," Order Open Time: ",borderOpen);

and then in the deinit

FileClose(handle);

is that correct?

 
//+------------------------------------------------------------------+

//| We initialize the adviser |

//+------------------------------------------------------------------+

int init()

{

handle=FileOpen("cyberia_log.csv", FILE_CSV|FILE_WRITE, ';');

SavedBlockSell = BlockSell;

SavedBlockBuy = BlockBuy;

AccountStatus();

GetMarketInfo();

ModelingPeriod = ValuePeriod * ValuesPeriodCount; // Period of simulation in minutes

if (ValuePeriod != 0 )

ModelingBars = ModelingPeriod / ValuePeriod; // Quantity of steps in the period

CalculateSpread();

return(0);

}

I am getting an error that says "too many files open"?

Reason: