Strategy tester with manual entries

 

Hello,


Based on another non MT4 system i have a list of entries. I have written an EA that manages closing the positions and wanted to test it in Strategy tester.


I think there a 2 options:

[1] manually open trades when strategy tester plots the candles, can it be done in any way?

[2] I tried creating an array with dates and time of entries, but when running it, strategy tester does not use data from the array,


Which one do you think is the best one and how do i do it?


Thanks in advance!

 
DareFX:

[2] I tried creating an array with dates and time of entries, but when running it, strategy tester does not use data from the array,

Check for errors in the logic of your code. There is no reason why this should not work, other than some mistake you made.
 
  1. No way to open manual trades in the tester - not possible.
  2. post the code
 
WHRoeder:
  1. No way to open manual trades in the tester - not possible

WHR is correct.

However, I have worked around this by checking for specific times and triggering specific trades (rather than indicator crossing etc)

For a long list of trades, these orders might be read from say a CSV file.

 

psudo code

void manualtrades() {

if time==somedatetime1 then OpenOrder()

if time==somedatetime2 then OpenOrder()

if time==somedatetime3 then OpenOrder()

}

gets a bit more complcated if you want to manually close them too!

(edit: On second thoughts this is too simple, hoping for exact matching of time may not work and opening it up to a period requires checking order not alredy placed)

 

hi


you can write EA that open trades when for example you add arrow or other object to the chart, in this way you will be able to open trades "manually" during backtesting.


regards

Romek

 

Hi,


thanks for the reply ....

I might have corrected it ... but since i am a newbie here (and to MQL and programming) I am looking for feedback on what I could do better. Thanks in advance!


CODE:

datetime TickTime;


string TradesHistoryDirection [4];
string TradesHistoryDateTime [4];

int ArrayLength = 4;

int init()
{
TradesHistoryDirection [1] = "L"; TradesHistoryDateTime [1] = "2010.08.17 00:20:00";
TradesHistoryDirection [2] = "L"; TradesHistoryDateTime [2] = "2010.08.17 01:30:00";
TradesHistoryDirection [3] = "L"; TradesHistoryDateTime [3] = "2010.08.17 01:40:00";
TradesHistoryDirection [4] = "L"; TradesHistoryDateTime [4] = "2010.08.17 02:00:00";
return(0);
}

int start()
{
int i=0;
string X = TimeToStr(TimeCurrent(),TIME_DATE | TIME_SECONDS);
for( i=1; i<=ArrayLength; i++)
{
datetime TickTime = StrToTime(TradesHistoryDateTime[i]);
Comment(TickTime," ",TimeCurrent());
{
if(TickTime == TimeCurrent())
{
if(TradesHistoryDirection[i]=="L")
{
OrderSend(Symbol(),OP_BUY,0.1,Ask,0,0,0,0,0,0,Green);
}
if(TradesHistoryDirection[i]=="S")
{
OrderSend(Symbol(),OP_SELL,0.1,Bid,0,0,0,0,0,0,Green);
}
}
}
}
return(0);
}

 
Ickyrus:

psudo code

void manualtrades() {

if time==somedatetime1 then OpenOrder()

if time==somedatetime2 then OpenOrder()

if time==somedatetime3 then OpenOrder()

}

gets a bit more complcated if you want to manually close them too!

(edit: On second thoughts this is too simple, hoping for exact matching of time may not work and opening it up to a period requires checking order not alredy placed)


the trades are closing in some sort of trailing stop - i.e. portion of trade closed when TP17 reached and then incrementals - this section works and works OK on live account.

I am using a non MT4 based system for manually opening the trades but I am wondering if I could close them better ;-) that is why I wanted to create this EA. Currently I have 2000 trades in my log that I wanted to test

 

  1. string TradesHistoryDirection [4];
    string TradesHistoryDateTime [4];
    TradesHistoryDirection [1] = "L"; TradesHistoryDateTime [1] = "2010.08.17 00:20:00";
    TradesHistoryDirection [2] = "L"; TradesHistoryDateTime [2] = "2010.08.17 01:30:00";
    TradesHistoryDirection [3] = "L"; TradesHistoryDateTime [3] = "2010.08.17 01:40:00";
    TradesHistoryDirection [4] = "L"; TradesHistoryDateTime [4] = "2010.08.17 02:00:00";
    You declare the array to contain 4 items. Those are indexed 0 through 3. array[4] is beyond the array.
    Also there's no need to specify the length
    string TradesHistoryDirection[] = { "2010.08.17 00:20:00", "2010.08.17 01:30:00",
                                        "2010.08.17 01:40:00", "2010.08.17 02:00:00" };

  2. for( i=1; i<=ArrayLength; i++)
    {
        datetime TickTime = StrToTime(TradesHistoryDateTime[i]);
        Comment(TickTime," ",TimeCurrent());
        {                   // <- useless bracket
            if(TickTime == TimeCurrent())
    TimeCurrent will most likely NEVER be EXACTLY equal which is why it doesn't work. If you're running on M1 or M5 then comparing to Time[0] would work.
    I'd would make sure the array is sorted by time and use
    int start(){
       static int nextTrade=0;
       if(nextTrade < ArraySize(TradesHistoryDateTime){
           datetime TickTime = StrToTime(TradesHistoryDateTime[nextTrade]);
           if (TickTime <= TimeCurrent()){
               OrderSend(...
               nextTrade++;
    }  }   }
    or use a sentinel and simplify
    string Trades[] = { "2010.08.17 00:20:00", "L",
                        "2010.08.17 01:30:00", "L",
                        "2010.08.17 01:40:00", "L",
                        "2010.08.17 02:00:00", "L",
                        "9999.01.01 00:00:00", "X" };
                                        
    int start(){
        static int nextTrade=0;
        datetime TickTime = StrToTime(Trades[nextTrade]);
        if (TickTime <= TimeCurrent()){
            if (Trades[nextTrade+1] == "L"){ OrderSend(...
            nextTrade+=2;
    }   }
 
WHRoeder:

  1. You declare the array to contain 4 items. Those are indexed 0 through 3. array[4] is beyond the array.
    Also there's no need to specify the length
  2. TimeCurrent will most likely NEVER be EXACTLY equal which is why it doesn't work. If you're running on M1 or M5 then comparing to Time[0] would work.
    I'd would make sure the array is sorted by time and use or use a sentinel and simplify

Thanks for reply ... I am trying to understand what you wrote ;-)


And I think i still need to add a If ... condition for choosing between Longs and Shorts. Funny enough I got to a version that was working as I wanted it to work but at for whatever reason it was opening multiple trades for item number 3 in the array. It was really strange. Anyway - i am going to play with the code and come back with questions.
 
  1. condition for choosing between Longs and Shorts
    This is implicit in #3 first version, and explicitly outlined in #3 second version.

  2. opening multiple trades
    Thus the static counter and the current time >= trade time[counter]. Never look again at a previously opened array item.
Reason: