Translating order code from MQL4 to MQL5 - half way there...

 
//Place a pending order sell using a fixed amount of account risk (1)

void SellPendingOrderWithRiskFixed2()
{
    double lotsize = MarketInfo(Symbol(),MODE_LOTSIZE) / AccountLeverage(); 
    double pipsize = 1 * 10; 
    double maxlots = AccountFreeMargin() / 100 * BalanceRiskPercent2 / lotsize * pipsize; 
    if (SellStoploss2 == 0) Print("OrderSend() error - stoploss can not be zero"); 
    double lots = maxlots / SellStoploss2 * 10;
    
    // calculate lot size based on current risk 
    double lotvalue = 0.001; 
    double minilot = MarketInfo(Symbol(), MODE_MINLOT);
    int powerscount = 0; 
    while (minilot < 1)
    { 
        minilot = minilot * MathPow(10, powerscount); 
        powerscount++; 
    }
    lotvalue = NormalizeDouble(lots, powerscount - 1); 
    
    if (lotvalue < MarketInfo(Symbol(), MODE_MINLOT))    // make sure lot is not smaller than allowed value 
    {
        lotvalue = MarketInfo(Symbol(), MODE_MINLOT); 
    }
    if (lotvalue > MarketInfo(Symbol(), MODE_MAXLOT))    // make sure lot is not greater than allowed value 
    {
        lotvalue = MarketInfo(Symbol(), MODE_MAXLOT); 
    }
    
    int expire = TimeCurrent() + 60 * 60; 
    double price = NormalizeDouble(Bid, NDigits) - PriceOffset2*PipValue*Point; 
    double SL = price + SellStoploss2*PipValue*Point; 
    if (SellStoploss2 == 0) SL = 0; 
    double TP = price - SellTakeprofit2*PipValue*Point;
    if (SellTakeprofit2 == 0) TP = 0; 
    if (60 == 0) expire = 0;
    int ticket = OrderSend(Symbol(), OP_SELLSTOP, lotvalue, price, 4, SL, TP, "EA Sell 3", 3, expire, Red); 
    if (ticket == -1)
    { 
        Print("OrderSend() error - ", ErrorDescription(GetLastError())); 
    }
    
} 

//Place a Sell Order with pre-defined stop and takeprofit

extern double SellStopLoss5 = 22.4;
extern double SellTakeProfit5 = 44.8;

void SellOrderOrdinary()
{
    double SL = Bid + SellStoploss5*PipValue*Point; 
    if (SellStoploss5 == 0) SL = 0; 
    double TP = Bid - SellTakeprofit5*PipValue*Point; 
    if (SellTakeprofit5 == 0) TP = 0;
    int ticket = -1; 
    if (true)
    ticket = OrderSend(Symbol(), OP_SELL, SellLots5, Bid, 4, 0, 0, "EA Sell", 1, 0, Red); 
    else 
    ticket = OrderSend(Symbol(), OP_SELL, SellLots5, Bid, 4, SL, TP, "EA Sell", 1, 0, Red); 
    if (ticket > -1) 
    { 
        if (true)
        { 
            bool sel = OrderSelect(ticket, SELECT_BY_TICKET); 
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red); 
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError())); 
        }
            
    }
    else 
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError())); 
    }
} 

//Place a sell order at market using an indicator as sl / tp.

void SellMarketNormalized()
{
    double SL = NormalizeDouble(High[1], NDigits); 
    if (High[1] == 0) SL = 0; 
    double TP = NormalizeDouble(Low[1], NDigits); 
    if (Low[1] == 0) TP = 0;
    int ticket = -1; 
    if (true) 
    ticket = OrderSend(Symbol(), OP_SELL, SellLots4, Bid, 4, 0, 0, "EA Sell Indicator", 2, 0, Red); 
    else
    ticket = OrderSend(Symbol(), OP_SELL, SellLots4, Bid, 4, SL, TP, "EA Sell Indicator", 2, 0, Red); 
    if (ticket > -1)
    { 
        if (true)
        { 
            bool sel = OrderSelect(ticket, SELECT_BY_TICKET); 
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red); 
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError())); 
        }
            
    }
    else 
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError())); 
    }
}
[/code]

I am trying to translate these three orders from MQ4 into MQ5. Can anyone help with the fixed risk one? I've done the other two:


I

void SellPendingOrderWithNormalizedStop()
{
    
    double price = NormalizeDouble( Bid()+ (fibentrymultiplier* (High(1)-Low(1))) , NDigits)  ; /* Bid() + SellStoploss5*PipValue*Point; */
    double SL = NormalizeDouble( Low(1) + (fibstopmultiplier * (High(1)-Low(1))), NDigits);  /* Ask() - SellTakeProfit5*PipValue*Point; */
    
    double TP = NormalizeDouble( Low(1) - (fibprofitpmultiplier*(High(1)-Low(1)) ) , NDigits);
    
    //--- prepare a request
    MqlTradeRequest request;
    ZeroMemory(request);
    request.action=TRADE_ACTION_PENDING;         // setting a pending order
    request.magic = 1;                  // ORDER_MAGIC
    request.symbol = Symbol();                      // symbol
    request.volume = Lots19;                          // volume in 0.1 lots
    request.sl = SL;                                // Stop Loss is not specified
    request.tp = TP;                                // Take Profit is not specified
    double TP1 = TP;
    request.deviation = 1;                         // deviation in 5 points
    request.price = price;
    //--- form the order type
    request.type = ORDER_TYPE_SELL_LIMIT;           // order type ORDER_TYPE_BUY_LIMIT, ORDER_TYPE_SELL_LIMIT, ORDER_TYPE_BUY_STOP, ORDER_TYPE_SELL_STOP
    //--- form the price for the pending order
    MqlTradeResult result;
    ZeroMemory(result);
    bool ok = OrderSend(request,result);
    // check the result
    if (ok && !IsError(result, __FUNCTION__))
    {
            
    }
 
 
 
    
}

Requested to repost this here.

Reason: