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

8773

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); `
937

Hi,

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

{

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);

}

if (BuyStoploss102 == 0) SL = 0;

if (BuyTakeprofit102 == 0) TP = 0;

int ticket = -1;

if (ECNBroker102)

else

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()));

}

}

749

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

much appreciated.