How to test between 2 specified dates (How about HISTORY...) ?

 

Hi. I am newbie. In fact this is my first post. I have a question.

Using ExpertAdvisor code, how can backtest an order between two specified time periods?

For example; here's some sample code:

   datetime dStart = D'2005.08.08 00:00:00';
   datetime dEnd = D'2007.08.09 00:00:00';

From: dStart

   ticket = OrderSend(Symbol(), OP_BUY, 1, Ask, 3, Ask-0.10, Ask+0.10, NULL, 0, 0, Green);
   Print(Ask);

To: dEnd

With code, how can I write some code to show what would've happened if I wanted to buy an order in between those 2 dates?

 

Date period is seted on the configuring before your press start button on backtest panel.

can not code inside code.

use Print(....) function

results display in one window of backtest panel

 
DxdCn:

Date period is seted on the configuring before your press start button on backtest panel.

can not code inside code.

use Print(....) function

results display in one window of backtest panel


Hmm...I'm not exactly sure what that answer means.

LOL...I am quite new to this EA code stuff.

Let me re-phrase my original question.

Using EA code, how can I print (output) results between 2 specified dates/times?

 

My question, code-wise:

   datetime dStart = D'2005.08.08 00:00:00';
   datetime dEnd = D'2007.08.09 00:00:00';
 
   while(...in between the 2 specified dates){
      ...output what would happen if I opened a buy position
   }
 

NO.

You should output it as soon as you open that position

like your code

ticket = OrderSend(Symbol(), OP_BUY, 1, Ask, 3, Ask-0.10, Ask+0.10, NULL, 0, 0, Green);
Print(Ask);//use print ...output what would happen if I opened a buy position at here.

or you can record them to somewhere and print them together later.

MT do not give mothods to find position based on dates, only shoude find positions first and then check its open-datetime.

 
DxdCn:

NO.

You should output it as soon as you open that position

like your code

ticket = OrderSend(Symbol(), OP_BUY, 1, Ask, 3, Ask-0.10, Ask+0.10, NULL, 0, 0, Green);
Print(Ask);//use print ...output what would happen if I opened a buy position at here.

or you can record them to somewhere and print them together later.

MT do not give mothods to find position based on dates, only shoude find positions first and then check its open-datetime.



No? But wait.

I actually can do this with MT's Strategy Tester.

See:

So, it should be possible to do this with EA code.

Can anyone show me code-wise how to do this?

 

that set is MT's function on interface for run EA, but not code in side EA !

you only can do like :

int total=OrdersTotal();
// write open orders
for(int pos=0;pos<total;pos++)
{

if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
if((OrderOpenTime( )>dStart)||(OrderOpenTime( )<dEnd)) //ckeck date when have got Order,
// ...output what would happen if I opened a buy position
}
----------------------------------------------------------------------

I can not imagin what your output need first: while(...in between the 2 specified dates){

I think you have to arrange your mind in other mode

 

I understand.

However, let me ask this:

Using only EA code, is it possible to retrieve past/history information? And if so, how?

For example, let's say I wanted to get the past (ask) price for USDCHF?

How would I code that?

 

use iClose(....) iHigh iLow IOpen.....

same as in indicator file.

but not ask price, since for pase time, prices data were recorded base in period, only high low open and close 4 price for one period, no tick price , so no ask for past.

int test node, ask or bid price is simulated by some math mode not real data in past.

EA test not really equal to real past, only a kind of simulation.

Reason: