- No way to open manual trades in the tester - not possible.
- post the code
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);
}
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
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 lengthstring 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" };
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 useint 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; } }
-
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 -
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 ;-)
- condition for choosing between Longs and ShortsThis is implicit in #3 first version, and explicitly outlined in #3 second version.
- opening multiple tradesThus the static counter and the current time >= trade time[counter]. Never look again at a previously opened array item.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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!