Zool pointed out this bug here http://www.stevehopwoodforex.com/phpBB3 ... 37#p154237
My quick and easy fix merely shifted the problem further down the line, so that >1 trades that should have the same take profit had instead my 100 pip tp individually.
This is a classic case of LUC calling for coffee. For those of you not around from the start of my career as a coder, LUC stands for the Law of Unintended Consequences i.e. a change in the code here necessitates a change there, which in turn demands a change there............
LUC threw some epic benders at my place in the early years and I recoded entire EA's rather than keep on doling out massive amounts of food and drink to LUC and all his friends and relatives, and their friends and relatives..........................
In a strange sort of a way, it is pleasant to know that he is still lurking in the background waiting to catch me out.
DIYers, undo the change you made a few hours ago (as in my post following Zool's). Zool pointed me in the right direction but did not quite have the full solution, so copy this over the top of the existing function:
Code: Select all
void CheckPricesAreStillValid()
{
//Examine pending trades and adjust the price if the peak has moved by 1 pip or more.
if (!BetterOrderSelect(LatestTradeTicketNo, SELECT_BY_TICKET, MODE_TRADES) )
return;
double price = 0, newPrice = 0;
bool modify = false;
double take = 0, stop = 0;
//A buy stop will be above the lowest trade line
if (OrderType() == OP_BUYSTOP)
{
price = ObjectGet(plTradeLineName, OBJPROP_PRICE1);
if (OrderOpenPrice() - price > (1 / factor) )
{
modify = true;
newPrice = price + (PendingTradeBuffer / factor);
stop = CalculateStopLoss(OP_BUY, newPrice);
take = CalculateTakeProfit(OP_BUY, newPrice);
}//if (OrderOpenPrice() - price > (1 / factor) )
}//if (OrderType() == OP_BUYSTOP)
//A sell stop will be below the highest trade line
if (OrderType() == OP_SELLSTOP)
{
price = ObjectGet(phTradeLineName, OBJPROP_PRICE1);
if (price - OrderOpenPrice() > (1 / factor) )
{
modify = true;
newPrice = price - (PendingTradeBuffer / factor);
stop = CalculateStopLoss(OP_SELL, newPrice);
take = CalculateTakeProfit(OP_SELL, newPrice);
}//if (OrderOpenPrice() - price > (1 / factor) )
}//if (OrderType() == OP_SELLSTOP)
if (!modify)
return;
bool result = ModifyOrder(OrderTicket(), newPrice, stop, take, OrderExpiration(), clrNONE, __FUNCTION__, oop);
}//void CheckPricesAreStillValid()
Great to see lots of people getting in on the entertainment. A quick warning though. A couple of you have come close to getting into trouble by asking questions that showed clearly that you could not be arsed to read the user guide. That makes you a dimwit in my eyes.
I have been known to take a robust approach to dimwits. You were lucky today that I was in a good mood. The sun was shining. Do not count on this lasting indefinitely. It does rain from time to time here in the UK, so hard as I try not to, I do have the occasional slightly grumpy mood.
In doubt about whether you should ask your question? Stay quiet.