open pending order and modify in mq5

 

Hlw

i hv enough knowledge in mq4 programming but in mq5 i m almost new

asking some help in place order


my mq4 code here:


// ---------------------------------------------------------------- New pending order if condition match---------------------------------------------------------------------------------

if ( conditon 1 met ) { int tk1=OrderSend(Symbol(),OP_BUYSTOP,lot,Ask+gap*Point,0,0,0,comment,magic1,0,clrBlue); }

if ( conditon 2 met  ) { int tk2=OrderSend(Symbol(),OP_SELLSTOP,lot,Bid-gap*Point ,0,0,0,comment,magic1,0,clrRed); }


// ---------------------------------------------------------------- Modify Orders---------------------------------------------------------------------------------

for(int b=OrdersTotal()-1;b>=0;b--){

         if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))                 

if(Period() == 5 && && OrderMagicNumber()== magic1 && OrderSymbol()==Symbol()){

if (OrderType()==OP_BUYSTOP  ){

if ( OrderOpenPrice()- Ask >gap*Point) { 

double priceNew=(Ask+gap*Point);

int tk3 = OrderModify(OrderTicket(),priceNew ,0,0,CLR_NONE);

}  }


if (OrderType()==OP_SELLSTOP  ){

if (Bid-OrderOpenPrice()>gap*Point) {                                  

double priceNew1=(Bid-gap*Point);

int tk4 = OrderModify(OrderTicket(),priceNew1,0,0,CLR_NONE);

}  } 



if (OrderType()==OP_BUY   && Bid < OrderOpenPrice()  ){                             

int tk3 = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()- SL*Point,0,CLR_NONE); 

}


if (OrderType()==OP_SELL   && Ask > OrderOpenPrice()){

int tk3 = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+ SL*Point,0,CLR_NONE); 

} } } 


my mq5 code here:





#include <Trade\PositionInfo.mqh>

#include <Trade\Trade.mqh>

#include <Trade\SymbolInfo.mqh>  

CPositionInfo  m_position;                   // trade position object

CTrade         m_trade;                      // trading object

CSymbolInfo    m_symbol;                     // symbol info object

// ------------------- where to put magic number? if want to trade open -----------------------------------------------------

if ( conditon 1 met ) {  bool tk1= m_trade.Buy(lot,m_symbol.Name(),MODE_ASK,0.0,0.0,"Buy "); }

if
( conditon 2 met ) { int tk2= m_trade.Sell(lot,m_symbol.Name(),MODE_BID,0.0,0.0,"Sell"); } // ------------------- i m in trouble in order modify code ----------------------------------------------------- for(int b=OrdersTotal()-1;b>=0;b--) { ulong ticket=OrderGetTicket(b); if(OrderSelect(ticket) ){ if(Period() == 5 && OrderGetInteger(ORDER_MAGIC) == magic1 && OrderGetString(ORDER_SYMBOL)==Symbol()){ if (OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_STOP ){ if ( PositionGetDouble(POSITION_PRICE_OPEN)- MODE_ASK >gap*Point) { double priceNew=(MODE_ASK +gap*Point); bool kkkk = PositionModify( ticket,priceNew,0,0,PositionGetDouble(POSITION_PRICE_OPEN)); } //-------------- same also sell stop , buy and sell code required -------------------------------------------------------------- ??????????????????????????????????


i cant modify pending and open orders..........so many error code after compile

 

To modify pending order i use

m_trade.OrderModify(TICKET,PRICE,SL,TP,ORDER_TIME_GTC,0);

for magic i use this in OnInit function

m_trade.SetExpertMagicNumber(magic1);
Reason: