How many reasons could there be for an EA to close a trade Long, but not close a Mirror Image trade Short?
I'm developing a "full time" EA that is intended to open/close a position then open a new position in the opposite direction. The 1st 3 legs work (Open Long, Close Long, Open Short) but the final step of Closing Short eludes me.
The sections of Closing code have been reviewed extensively and they check out fine (as mirror images).
I think the glitch is in an area that I frankly have no familiarity with ... and have not been able to find an answer in the research.
I've pasted the questionable code for the end of the EA below. Since my untrained eye tells me that this favors the Long direction I've tried various rewrites ... with no success.
Any suggestions would be appreciated.
//-----------------------------------++++++++++++
bool OrderFind(int magicnolong)
{
glbOrderType = -1;
glbOrderTicket = -1;
int total = OrdersTotal();
bool res = false;
for(int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == magicnolong && OrderSymbol() == Symbol())
{
glbOrderType = OrderType();
glbOrderTicket = OrderTicket();
glbOpenPrice = OrderOpenPrice();
glbStopPrice = OrderStopLoss();
res = true;
}
}
return(res);
}
I'm developing a "full time" EA that is intended to open/close a position then open a new position in the opposite direction. The 1st 3 legs work (Open Long, Close Long, Open Short) but the final step of Closing Short eludes me.
The sections of Closing code have been reviewed extensively and they check out fine (as mirror images).
I think the glitch is in an area that I frankly have no familiarity with ... and have not been able to find an answer in the research.
I've pasted the questionable code for the end of the EA below. Since my untrained eye tells me that this favors the Long direction I've tried various rewrites ... with no success.
Any suggestions would be appreciated.
//-----------------------------------++++++++++++
bool OrderFind(int magicnolong)
{
glbOrderType = -1;
glbOrderTicket = -1;
int total = OrdersTotal();
bool res = false;
for(int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == magicnolong && OrderSymbol() == Symbol())
{
glbOrderType = OrderType();
glbOrderTicket = OrderTicket();
glbOpenPrice = OrderOpenPrice();
glbStopPrice = OrderStopLoss();
res = true;
}
}
return(res);
}