![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Reverting to a modified PM2
Version 2 seems to work the best of all the versions thus far. It lacks the Trend that will make the Margin safer, but the execution is best. I have added tidbits to update the code to include some of the updates that Neo has posted...
Neo -
I would like to implement a Trend to this version. I have been using a LWMA to achieve this. However, the close routines go all to hell with the introduction of the MA... Maybe you might have some ideas to incorporate it into the EA successfully.
Don
I'll take a look....
Close routines
What I have noticed with the PM2a is that the opposites work only when the price is at the very extremes. Higher than the HighestBuy or lower than the LowestSell... when the positive sell are above the MidPoint, the losing sell is NOT closing. same for the low buys not closing out the high buy... who would of thought simply adding a iMA would screw it up so badly...![](https://c.mql5.com/forextsd/smiles/frown.png)
Don
Best time Frame
Version 2 seems to work the best of all the versions thus far. It lacks the Trend that will make the Margin safer, but the execution is best. I have added tidbits to update the code to include some of the updates that Neo has posted...
Neo -
I would like to implement a Trend to this version. I have been using a LWMA to achieve this. However, the close routines go all to hell with the introduction of the MA... Maybe you might have some ideas to incorporate it into the EA successfully.
DonGood morning Don,
Firstly, sorry for my bad english, i don't speak good english.
Secondly, thanks to share your work with us.
So i'm very interest about your EA, so i want to test it in live on a demo account (3000$ Lot: 0.1), just want to run it while 3 at 5 months to see the results, so i want to know what is your best timeframe to run it.
Thanks
Ok...found part of the problem, at least! The MinWait computation in the "Close in profit" functions is not fully supported in Strategy Test mode so replace the functions with these:
void CloseBuysinProfit()
{
double BuyProfit, LastBuyTime;
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY)
{
BuyProfit = OrderProfit() + OrderSwap() + OrderCommission();
if (OrderOpenTime() > LastBuyTime) LastBuyTime = OrderOpenTime();
if ((IsTesting() || TimeCurrent() - LastBuyTime >= MinTime) && BuyProfit > 0) OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
}
}
}
return;
}
//+-----------------------------------------------+
//| Closes all Sells in Profit
//+-----------------------------------------------+
void CloseSellsinProfit()
{
double SellProfit, LastSellTime;
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL)
{
SellProfit = OrderProfit() + OrderSwap() + OrderCommission();
if (OrderOpenTime() > LastSellTime) LastSellTime = OrderOpenTime();
if ((IsTesting() || TimeCurrent() - LastSellTime >= MinTime) && SellProfit > 0) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red);
}
}
}
return;
}
Neo
cool.
I have replace those subroutines. I will try to add in the LWMA now and see if the closes work better...
Don
Close routines
The addition of the LWMA still screws up the closes. Frustrating.
All I did was create an LWMA variable.
extern int MAPeriod = 1200;
double Trend = iMA(NULL, 0, MAPeriod, 0, MODE_LWMA, MODE_CLOSE, 0);
And then call it up in the Buy and Sell trade criteria.
if (Ask HighestBuy + (TrendSpacing * Point)&& Ask > Trend)
if (Bid > HighestSell + (Spacing * Point) || Bid < LowestSell - (TrendSpacing * Point)&& Bid < Trend)
Don
Time Frame?
Good morning Don,
Firstly, sorry for my bad english, i don't speak good english.
Secondly, thanks to share your work with us.
So i'm very interest about your EA, so i want to test it in live on a demo account (3000$ Lot: 0.1), just want to run it while 3 at 5 months to see the results, so i want to know what is your best timeframe to run it.
ThanksI use 1M time frame as there isn't any indicators involved.
I am trying to incorporate a LWMA and still will use a 1M tf.
Don
I use 1M time frame as there isn't any indicators involved.
I am trying to incorporate a LWMA and still will use a 1M tf.
DonHi Don !!
I an shure that is a very good idea. I am backtesting in 30 min TF and getting interesting results (profit factor 3+ but a little high drawdown). I will forward test in that TF and post my results latter.
Regards,
Version 4
Well, I have tried to clean up and update the code, to include updates from NEO, as well as add the LWMA. Here it is explained.
Trend is the internal value that is checked against the bid/ask. It uses the MAPeriod.
MAPeriod - A friend of mine determined that he liked using 15M TF 80 LWMA to place the orders, I converted it to a 1M TF 1200 LWMA (15*80) Buys above this and sells below.
Everything else is pretty much the same.
The close routines are still screwing up a bit. Sometimes the positive buys above the midpoint will close out a losing sell, sometimes not. same for the sells below the midpoint. Errrr. Can still use some help with this aspect.
Don