My Expert Close Position is not working New comment Paulo Carvalho 2014.12.29 21:07 Sell and Buy Functions is working perfectly but EA is not even calling the ExpertClosePosition.Could Any Body help me?Tanks a lot void OnTick() { if(CanTrade) { if(TradeOrAlert) { // Check trading conditions if (iMACD_MAIN_Value[0] < iMACD_SIGNAL_Value[0]) { SELL(Symbol(),Symbol_LS_0,Symbol_TP_0,Symbol_SL_0,Symbol_TS_0,"") ; } if (iMACD_MAIN_Value[0] > iMACD_SIGNAL_Value[0]) { BUY(Symbol(),Symbol_LS_0,Symbol_TP_0,Symbol_SL_0,Symbol_TS_0,"") ; } if(iETADX_Value[0]> 40) { if(iMACD_MAIN_Value[0]<iMACD_MAIN_Value[1] || iMACD_MAIN_Value[0]>iMACD_MAIN_Value[1]) { ExpertClosePosition(Symbol()); } } } } } // Set Parameters For Expert Close Positionbool ExpertClosePosition (string symbol_ecp){ CSymbolInfo symInfo; CTrade trade; CPositionInfo posInfo; ulong ticket_ecp; HistorySelect(0, TimeCurrent()); // open a list of ORDERS and DEALS int ordersnumb_ecp = HistoryDealsTotal(); // count the total numbers of DEALS in history select for(int p = ordersnumb_ecp-1; p >= 0; p--) { ticket_ecp = HistoryDealGetTicket(p); // Set a especific DEAL NR in list for work if(ticket_ecp == 0) { Print(_Symbol," Error on ticket for set EXpertClosePosition!"); break; } } // ------------------------------------------------- if(HistoryDealGetInteger(ticket_ecp,DEAL_ENTRY)==DEAL_ENTRY_IN) { // Set Buy Trailing in pips if(HistoryDealGetInteger(ticket_ecp,DEAL_TYPE)==DEAL_TYPE_BUY) { ClosePosition(symbol_ecp,POSITION_TYPE_BUY,MagicNumberLong); Sleep(SleepTime); return(0); } // Set Sell Trailing in pips if(HistoryDealGetInteger(ticket_ecp,DEAL_TYPE)==DEAL_TYPE_SELL) { ClosePosition(symbol_ecp,POSITION_TYPE_SELL,MagicNumberShort); Sleep(SleepTime); return(0); } return(true); } else { return(false); } } History Select Mt5 Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes Questions from Beginners MQL5 MT5 MetaTrader 5 New comment
Sell and Buy Functions is working perfectly but EA is not even calling the ExpertClosePosition.
Could Any Body help me?
Tanks a lot
void OnTick()
{
if(CanTrade)
{
if(TradeOrAlert)
{
// Check trading conditions
if (iMACD_MAIN_Value[0] < iMACD_SIGNAL_Value[0])
{
SELL(Symbol(),Symbol_LS_0,Symbol_TP_0,Symbol_SL_0,Symbol_TS_0,"") ;
}
if (iMACD_MAIN_Value[0] > iMACD_SIGNAL_Value[0])
{
BUY(Symbol(),Symbol_LS_0,Symbol_TP_0,Symbol_SL_0,Symbol_TS_0,"") ;
}
if(iETADX_Value[0]> 40)
{
if(iMACD_MAIN_Value[0]<iMACD_MAIN_Value[1] || iMACD_MAIN_Value[0]>iMACD_MAIN_Value[1])
{
ExpertClosePosition(Symbol());
}
}
}
}
}
// Set Parameters For Expert Close Position
bool ExpertClosePosition (string symbol_ecp)
{
CSymbolInfo symInfo;
CTrade trade;
CPositionInfo posInfo;
ulong ticket_ecp;
HistorySelect(0, TimeCurrent()); // open a list of ORDERS and DEALS
int ordersnumb_ecp = HistoryDealsTotal(); // count the total numbers of DEALS in history select
for(int p = ordersnumb_ecp-1; p >= 0; p--)
{
ticket_ecp = HistoryDealGetTicket(p); // Set a especific DEAL NR in list for work
if(ticket_ecp == 0)
{
Print(_Symbol," Error on ticket for set EXpertClosePosition!");
break;
}
}
// -------------------------------------------------
if(HistoryDealGetInteger(ticket_ecp,DEAL_ENTRY)==DEAL_ENTRY_IN)
{
// Set Buy Trailing in pips
if(HistoryDealGetInteger(ticket_ecp,DEAL_TYPE)==DEAL_TYPE_BUY)
{
ClosePosition(symbol_ecp,POSITION_TYPE_BUY,MagicNumberLong);
Sleep(SleepTime);
return(0);
}
// Set Sell Trailing in pips
if(HistoryDealGetInteger(ticket_ecp,DEAL_TYPE)==DEAL_TYPE_SELL)
{
ClosePosition(symbol_ecp,POSITION_TYPE_SELL,MagicNumberShort);
Sleep(SleepTime);
return(0);
}
return(true);
}
else
{
return(false);
}
}