Trading using reverse trades in metatrader 3

 
For me trading for a short time period and using expert advisor to reverse trades ( closing an old possition and opening a new one opposite at the same price), makes a big difference during between backtesting and live trading.
For example in live trading : I am buying eur/usd at 1.2654 and i want to sell it at 1.2667 . When I'm using expert advisor for automated trading , price lets say moves to 1.2665, then 1.2666, and when price hits 1.2667 buying possition is closed (if price would move to 1.2668 only then sell possition will be opened ).If price moves down by one pip, sell possition is not opened. It has to move again at price 1.2667 to be executed. (Selling possition is not pendding in order's section) .
Are there some inputs or ideas how to fix, solve this problem. Is it possible?
And sorry for my eanglish.

There is some simple code:
/*[[
Name := eur/usd
Author := Copyright © 2005, juce, regentas@yahoo.com
Link := niuniu
Notes := eur/usd
Lots := 1
Stop Loss := 50
Take Profit := 50
Trailing Stop := 0
]]*/
Defines: ema1(3),ema2(6),risklevel(12),ema_diff(2.5);
var: temp(0),lotss(0),slippage(0),i(0);

lotss=Ceil((Balance*risklevel*PriceAsk)/100000);
temp=(iMAEx(ema1,MODE_EMA,0,PRICE_CLOSE,0)-iMAEx(ema2,MODE_EMA,0,PRICE_CLOSE,0))/point;
///////////////////
if temp<-ema_diff then {
for i=1 to TotalTrades {
if ord(i,VAL_TYPE)=OP_SELL then
CloseOrder(ord(i,VAL_TICKET),ord(i,VAL_LOTS),ask,slippage,FireBrick)
else if ord(i,VAL_TYPE)=OP_SELLSTOP then
DeleteOrder(ord(i,VAL_TICKET),red);
};
if TotalTrades<1 then {
SetOrder(OP_BUY,lotss,ask,Slippage,ask-StopLoss*point,ask+TakeProfit*Point,SkyBlue);
};
};

if temp>ema_diff then {
for i=1 to TotalTrades {
if ord(i,VAL_TYPE)=OP_BUY then
CloseOrder(ord(i,VAL_TICKET),ord(i,VAL_LOTS),bid,slippage,Gray)
else if ord(i,VAL_TYPE)=OP_BUYSTOP then
DeleteOrder(ord(i,VAL_TICKET),red);
};
if TotalTrades<1 then {
SetOrder(OP_SELL,lotss,bid,Slippage,bid+StopLoss*point,bid-TakeProfit*Point,white);
};
};
////////////
 
hi Stevenson,

hmm i had a problem with the backtesting in mt3 too.
i think you used the ohlc mode - that one will return excellent results with the right system, but its worth nothing... ohlc puts in the open - then the high - if your system closes positions very early it will close the position at the highest level possible -> high win.
try using the slow 1-point system...

but now to your problem...
save the price where you want to close your order to a variable and then set this variable to be the new buy/sell signal..
i hope i understood your problem right...

does that system work? by now i dont understand how that should work;)

shrak
 
Hi Shrak,

I'm not using ohlc mode during backtesting. I use only slow 1-point system ... .
Code which i have pasted, is not a trading system or profitabal strategy. It's just a simple algorithm how to close and open a new one trade as a reverse trade. It's just a small part of my system's code.
I can get the same result by testing it manualy on different brokers platform ,with a broker which do not allow to hedge, with the same currency pair. For example i am selling eur/usd 1 lot , when price meets my target, i close it by using an opossite 2 lots buying possition. when this trade gets executed i am buying 1 lot eur/usd possition. This can be done only if broker does not allow hedging possitions by the same pair. In fact I don't know any broker (who's platfors is matatrader) who wouldn't allow hedging. There wouldn't be any probblem then.

As you mentioned :
"save the price where you want to close your order to a variable and then set this variable to be the new buy/sell signal.."
I think this is the only way too. But then platform might get slower, and still there is no guaranty that will work in the proper way. But maybe there is some simple way how to put these columns that they will work as i want.

Waiting for comments.
 
another easy way would be:
when a position is closed you directly set a pending buy order.. i dont know which one it is, buylimit or buystop, but i think one of them can open a position as soon as price trades through it=)
then you dont need the new variable - ... but that pending order would cause totaltrades to be at least equal 1... i dont know if that would make you system fail...

hmm i would use the variable, its the more secure way - and... if you're not using something slower than a pentium 500mhz, you wont even notice the lower speed...

my actual system consists of 25vars, 20strings, 3ini's, 427executions...
the backtesting on the daily chart is done in under 1:30...

the only thing that really makes a system slow are loops... variables and simple codelines dont really slow a system down...

besides, at least 100 exe's in my code do have nothing to do with the trading, they just log the systems performance and write a comment to the chart, telling me how good the system really is...=)

if you post your complete system i can try to optimize it... if you dont want everybody to read it, you can also e-mail it to me...
sometimes its possible to convert a loop into a simple line of code....
for example...
var: x(0);
for x = 0 to 50 {
x = x+x
};

you can simply write
x = 50*(50+1)/2

that would make the system 50times faster...

i can also send you some of my systems, a few work good=)
my e-mail address is backshrak@gmx.de

mail me

shrak
 
little mistake...
this one is correct
var: sum(0);
var: x(0);
for x = 0 to 50 {
sum += x;
}

the version in my first post wouldnt have any use...
 
Hey,

Sorry for late replay. It seems to me, that you do not quite understant, what type of problem i have. I would sugest, open some demo account , and enable expert advisor to trade some currency which do not have slipage , like eur/jpy (timeframe 15min,30min,1h). After the day ends , do a backtest and you will see how the trades do not fit (especially opening price).

And thank you for your comments.
 
Stevenson,

NO backtest in MT3 is accurate, this is because it simulates data instead of using using actual tick data.
Hopefully MT4 strategy tester will fix this problem.

Only way to find out how your expert works is to test it in real time demo mode....

GT................
 
mpfx,

Of course ,you will not get 100 % accurate results. But if you will test on 15 minutes or 30 minutes, it will be pretty the same as backtested.
Its a bit hard to explaine but:
as i said before , metatrader closes trades accurately. With this one part everything is ok. But the next one part when metatrader has to open a trade is something wrong. When trade is closed , metatrader doesn't even consider to open or not a trade until price moves up or down. If moves by one pip to my desired side trade is opended at the same price or one pip beter. And if it moves to the other side after closing possition , the other possition might never be opened if price will not meet the last trade's price.

I trade also through other brokers, the same strategy using metatrader's data. And i put all trades manually, and after then i do a backtest for a comparing trade results , and it's almost the same .
I think the main problem with enabled expert advisor is that it do not refresh prices , datas, all calculations, if price do not move. I mean after single one pip movement metatrader can do only one operation , like : close trade, modify trade or open a new one. It wil never do all these operations at the same time and at the same price . That's the main problem i think is. And i have no idea , is it possible to do something about that.
 
i am trading demo accounts already;)

hmm i never backtested a day i traded a demo account - you may be right...
on the 1min period it could be quite accurate - on the 15 minute period or more i cant be accurate.....

imagine... it takes for example 1 minute to backtest the 1min.period -
lets say it takes 5 minutes to backtest the 30min.period .... its 5 times more time, but it would be about a 1000 times more data to be tested... - your backtesting would take a long long long time.... i also hope they fix that - .... in addition i hope they build in 2 fields for the timeframe one wants to backtest the strategy;) i implemented that in every of my experts but it would be better to be hard-coded into metatrader...

sry that i couldnt help you much
Reason: