DislikedExit: When prices become mixed (ie. Bid in one terminal is no longer greater than ask in the other). Or TP. Or SL.Ignored
I've checked out how funcCloseOrder(OrderType(),varSignal) acts in your codes.
It seems to me that the above exit condition has not been implemented. (Close an order when prices become mixed (ie. Bid in one terminal is no longer greater than ask in the other)) Am I missing something here ?
If my understanding is correct, two functions, funcGenerateSignal() and funcCloseOrder(int varOrderType, int varSig), would be modified to the below forms (there must be better way....) (Modified pieces are commented with // D: )
//-------
int funcGenerateSignal()
{
static int varReturnValue=3;
static bool varSpread=true;
static int varDistance=0;
varDistance=MathMax(MarketInfo(Symbol(),MODE_SPREAD),MarketInfo(Symbol(),MODE_FREEZELEVEL));
if (varOtherA==0 || varOtherB==0) {return(3);}
//check spreads
if (MarketInfo(Symbol(),MODE_SPREAD) > varSpreadProtect) {varSpread=false;}
//check directions
if (Ask < varOtherB && varSpread && (varOtherB-Ask)/Point > varDistance)//long
{varReturnValue=1;}
if (Bid > varOtherA && varSpread && (Bid-varOtherA)/Point > varDistance)//short
{varReturnValue=2;}
if (Ask < varOtherB && varSpread && (varOtherB-Ask)/Point < varDistance)//long
{varReturnValue=0;}
if (Bid > varOtherA && varSpread && (Bid-varOtherA)/Point < varDistance)//short
{varReturnValue=0;}
if (Bid <= varOtherA && varSpread && OrdersTotal()!=0) // D: for closing order when Bid in this terminal is no longer greater than Ask in another terminal
{varReturnValue=5;}
if (Ask >= varOtherB && varSpread && OrdersTotal()!=0) // D: for closing order when Ask in this terminal is no longer greater than Bid in another terminal
{varReturnValue=5;}
return(varReturnValue);
}
bool funcCloseOrder(int varOrderType, int varSig)
{
static bool varReturnValue=false;
if (varOrderType==OP_BUY && varSig==5)//( || D: varSig==3 is changed to 5.
{
varReturnValue=CloseAll(Symbol(),varOrderMagicNumber,varOrderType,10,varSlippage," ");
}
if (varOrderType==OP_SELL && varSig==5)//( || D: varSig==3 is changed to 5.
{
varReturnValue=CloseAll(Symbol(),varOrderMagicNumber,varOrderType,10,varSlippage," ");
}
return(varReturnValue);
}
//------
One more thing I suggest is to add one more condition for excuting procOpenOrder(varSignal).
Inside start(),
if (varNoOrder && varOtherA != 0 && varOtherB != 0)
{
varFridayOK=funcFridayOK();
varTimeOK=funcCheckTime(10);
if (varStopEA || !varTimeOK || RefreshRates()==true) {return(0);} // D: Added one more condition to check whether the predefined variables such as Ask, Bid.. are still valid. If new tick has came during the operation, don't make any order.
procOpenOrder(varSignal);
}
Please let me know what you think of them.
-D