Hi I try create Expert Adviser in mql5. I want after open position save the ticket of that position on some arrays and then close the position with that tickets,But the trade is not open. how can i fix this? please help. this is my open trade code:
void OpenTrade(ENUM_ORDER_TYPE ENType,ENUM_SYMBOL_INFO_DOUBLE ESID,
double Volume, double SL, double roham_line, int roham_deviation,int witch_roham)
{
bool result;
MqlTradeRequest MTRequest;//= {1}; // i got error from here
MqlTradeResult MTResult;
MTRequest.action = TRADE_ACTION_DEAL;
MTRequest.type = ENType;
MTRequest.symbol = _Symbol;
MTRequest.type_filling = ORDER_FILLING_FOK;
MTRequest.price = SymbolInfoDouble(_Symbol,ESID);
if(ENType == ORDER_TYPE_BUY)
{
MTRequest.sl = roham_line - (SL *_Point) - SYMBOL_SPREAD;
}
else
if(ENType == ORDER_TYPE_SELL)
{
MTRequest.sl = roham_line + (SL *_Point) + SYMBOL_SPREAD;
}
MTRequest.volume = Volume;
MTRequest.deviation = roham_deviation;
result = OrderSend(MTRequest,MTResult);
if(result == true)
{
if(ENType == ORDER_TYPE_BUY)
{
if(witch_roham == 1)
{
for(int i=0; i<10; i++)
{
if(roham1BuyArray[i]==0)
{
roham1BuyArray[i] = MTResult.deal;
break;
}
}
}
else
if(witch_roham == 2)
{
for(int i=0; i<10; i++)
{
if(roham2BuyArray[i]==0)
{
roham2BuyArray[i] = MTResult.deal;
break;
}
}
}
else
if(witch_roham == 3)
{
for(int i=0; i<10; i++)
{
if(roham3BuyArray[i]==0)
{
roham3BuyArray[i] = MTResult.deal;
break;
}
}
}
}
else
if(ENType == ORDER_TYPE_SELL)
{
if(witch_roham == 1)
{
for(int i=0; i<10; i++)
{
if(roham1SellArray[i]==0)
{
roham1SellArray[i] = MTResult.deal;
break;
}
}
}
else
if(witch_roham == 2)
{
for(int i=0; i<10; i++)
{
if(roham2SellArray[i]==0)
{
roham2SellArray[i] = MTResult.deal;
break;
}
}
}
else
if(witch_roham == 3)
{
for(int i=0; i<10; i++)
{
if(roham3SellArray[i]==0)
{
roham3SellArray[i] = MTResult.deal;
break;
}
}
}
}
}
}
and this is close with tickets function:
void BuyRoham(double roham_line)
{
for(int i = 0 ; i< 10 ; i++)
{
if(roham1SellArray[i] != 0)
{
//close sell with for
CT.PositionClose(roham1SellArray[i],ULONG_MAX);
roham1SellArray[i] =0;
}
}
OpenTrade(ORDER_TYPE_BUY,SYMBOL_ASK,roham1_Volume,roham1_StopLossPoint,roham_line,roham1_deviation_point,1);
}
the BuyRoham function call after buy signal detected. in the body of this function all of the cell position should close with ticket and the open one buy position. are this function correct or not too?