Why is this not working ? SendOrder, stoploss ?

 

Hi,

I'm trying to implement a simple function that send order at the market price and fix the stop loss from an absolute "bet value" (ie an ammount of money in the account currency).


I don't understand why it doesn't work with USDJPY but it seems to work with other symbols like USDCHF, EURUSD, GPBUSD...

With USDJPY, GetLastError() gives me an error 130

Here is my code:


double StopLossPips(string symbol, double bet, double lots){

    double tickvalue = MarketInfo(symbol, MODE_TICKVALUE);
    double lotsize   = MarketInfo(symbol, MODE_LOTSIZE);
    double spread    = MarketInfo(symbol, MODE_SPREAD);
    
    return( bet/(lots * lotsize * tickvalue) );
} 


int MarketPriceOrderSend(string symbol, int cmd, double volume, int slippage_points, double absolute_stoploss, double absolute_takeprofit){
    
    double stoploss_pips, takeprofit_pips, price, stoploss, takeprofit, spread, point;
    
    spread = MarketInfo(symbol, MODE_SPREAD);
    point = MarketInfo(symbol, MODE_POINT);
    
    int digits = MarketInfo(symbol, MODE_DIGITS);
    
    stoploss_pips = StopLossPips(symbol, absolute_stoploss, volume);
    takeprofit_pips = StopLossPips(symbol, absolute_takeprofit, volume);
    
    if(cmd == OP_BUY){
        price = MarketInfo(symbol, MODE_ASK);
        stoploss = price - stoploss_pips - (spread * point);
        takeprofit = price + takeprofit_pips  + (spread * point);        
    }
    else{
        if(cmd == OP_SELL){
            price = MarketInfo(symbol, MODE_BID);
            stoploss = price + stoploss_pips  + (spread * point);
            takeprofit = price - takeprofit_pips  - (spread * point);  
        }
        else{
            return(-1);
        }
    }
    
    return(OrderSend(symbol, cmd, volume, price, slippage_points * point, NormalizeDouble(stoploss, digits), NormalizeDouble(takeprofit, digits)));
    
}



int start(){


    if(MarketPriceOrderSend(Symbol(), OP_SELL, 0.01, 2, 20, 80) == -1){
        LogMessage(DoubleToStr(GetLastError(),0));
    }    

    return(0);
}


Any help will be grandly appreciated.

 

Check that your SL and TP are past the minimum allowable.

MarketInfo(Symbol(),MODE_STOPLEVEL);

V

Reason: