same old, good friend - error 130. - page 2

 

If you want to use SL & TP, make sure you normalize them in the OrderSend. Same thing with LotSize and in fact any double. Normalize price to 4 or 5 digits depending on your broker, lots to 2. eg:

OrderSend(Symbol(),OP_BUY,NormalizeDouble(LotSize,2),Ask,Slippage,close_d,NormalizeDouble(TP,5),"BUY",MagicNumber,0,clrGreen); 
 

Hi,

here is the one example code for buy order with fixed risk /calculated from x percent of balance and from SL/

 

 void BuyOrderRiskFixed102()

{

    double lotsize = MarketInfo(Symbol(),MODE_LOTSIZE) / AccountLeverage();

    double pipsize = 1 * 10;

    double maxlots = AccountFreeMargin() / 100 * BalanceRiskPercent102 / lotsize * pipsize;

    if (BuyStoploss102 == 0) Print("OrderSend() error - stoploss can not be zero");

    double lots = maxlots / BuyStoploss102 * 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);

    }

    double SL = Ask - BuyStoploss102*PipValue*Point;

    if (BuyStoploss102 == 0) SL = 0;

    double TP = Ask + BuyTakeprofit102*PipValue*Point;

    if (BuyTakeprofit102 == 0) TP = 0;

    

    int ticket = -1;

    if (ECNBroker102)

    ticket = OrderSend(Symbol(), OP_BUY, lotvalue, Ask, BuySlippage102, 0, 0, "BUY strategy 1", 1, 0, Green);

    else

    ticket = OrderSend(Symbol(), OP_BUY, lotvalue, Ask, BuySlippage102, SL, TP, "BUY strategy 1", 1, 0, Green);

    if (ticket > -1)

    {

        if (ECNBroker102)

        {

            OrderSelect(ticket, SELECT_BY_TICKET);

            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Green);

            if (ret == false)

            Print("OrderModify() error - ", ErrorDescription(GetLastError()));

        }

        Arrow93();

        

    }

    else

    {

        Print("OrderSend() error - ", ErrorDescription(GetLastError()));

    }

}


 

woah, thanks guys - ill take a note here, for sure.

much appreciated.