Help - EA does not open Buy order

Hello Everyone,

Please I am still learning to code EA with MQL5 language however I wrote a code that involved selection of closed orders. There was no error when I run it but during implementation the EA failed to open buy order while opening of sell order was okay.

The position select for sell is meant to open new sell orders when trade continues to trend downwards and open first buy when it trends upwards. Afterwards subsequent buy will be opened by buy select as trade continues to trend upwards.

In a nutshell, apart from first sell order which serves as reference point for price, the EA is meant to always open buy order when price goes up by take profit (TP) value and open sell when it reverses by same value. In each case, if there is any open order due to close according to set TP value, EA must wait for its closing before opening new order along trend direction.

The code is pasted below, kindly assist and thanks in advance for your assistance:

// Sell when there is no Open Order

if (PositionsTotal()==0)

trade.Sell (Lot,NULL,Bid,0, (Bid-TP * _Point),NULL);

HistorySelect(0, TimeCurrent());

Print("Last deal price = "+DoubleToString(HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-1),DEAL_PRICE),_Digits));

if (PositionsTotal()==3)

for(int i=PositionsTotal()-1; i>=0; i--)

if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties

{

if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)

if (m_position.PriceOpen() m_position.PriceCurrent() + (TP * _Point))

trade.Sell (Lot,NULL,Bid,0, (Bid-TP * _Point),NULL);

}

else

{

if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)

if (m_position.PriceOpen() < m_position.PriceCurrent() - (TP * _Point))

trade.Buy (Lot,NULL,Ask,0, (Ask+TP * _Point),NULL) ;

}

}
CodeFx
CodeFx
Help - EA does not open Buy order
Hello Everyone,   Please I am still learning to code EA with MQL5 language however I wrote a code that involved selection of closed orders. There was no error when I run it but during implementation the EA failed to open buy order while opening
CodeFx
MQL5.communityに登録されました