If you post your code so the people may help
Forum on trading, automated trading systems and testing trading strategies
whroeder1, 2011.07.30 18:16
I had problems when I tried using buystops with tp/sl. I thought it was comparing current price vs stops but couldn't ever verify. Could also be ECN, open first THEN set stops.extern double Take_Profit=300; // 5 digit broker? extern double Stop_Loss=150; void Buy(string symbol,string comment) { double point,ask,bid,minstoplevel; double stoploss,takeprofit; int i,digits,ticket; bool order_already_exists=false,res; double atr; for(i=OrdersTotal()-1;i>=0;i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderMagicNumber()==Expert_Id) if(OrderType()==OP_BUY) if(OrderSymbol()==symbol) order_already_exists=true; } if(!order_already_exists) { ask=MarketInfo(symbol,MODE_ASK); bid=MarketInfo(symbol,MODE_BID); point=MarketInfo(symbol,MODE_POINT); digits=MarketInfo(symbol,MODE_DIGITS); stoploss=NormalizeDouble(ask-Stop_Loss*point,digits); takeprofit=NormalizeDouble(ask+Take_Profit*point,digits); ticket=OrderSend(symbol,OP_BUY,Lots,ask,Slippage,0,0,comment,Expert_Id,0,Green); if(ticket<0) { Print("OrderSend Buy failed with error-",GetLastError()," symbol=",symbol," Lots=",Lots," price=",ask," sl=",stoploss," tp=",takeprofit); } else { res = OrderModify(ticket, 0, stoploss, takeprofit, 0); if(!res) {Print("OrderModify Error: ", GetLastError()); Print("IMPORTANT: ORDER #", ticket, " HAS NO STOPLOSS AND TAKEPROFIT");} } } } //+------------------------------------------------------------------+ void Sell(string symbol,string comment) { double point,ask,bid,minstoplevel; double stoploss,takeprofit; int i,digits,ticket; bool order_already_exists=false,res; double atr; for(i=OrdersTotal()-1;i>=0;i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderMagicNumber()==Expert_Id) if(OrderType()==OP_SELL) if(OrderSymbol()==symbol) order_already_exists=true; } if(!order_already_exists) { ask=MarketInfo(symbol,MODE_ASK); bid=MarketInfo(symbol,MODE_BID); point=MarketInfo(symbol,MODE_POINT); digits=MarketInfo(symbol,MODE_DIGITS); stoploss=NormalizeDouble(bid+Stop_Loss*point,digits); takeprofit=NormalizeDouble(bid-Take_Profit*point,digits); ticket=OrderSend(symbol,OP_BUY,Lots,bid,Slippage,0,0,comment,Expert_Id,0,Green); if(ticket<0) { Print("OrderSend Sell failed with error-",GetLastError()," symbol=",symbol," Lots=",Lots," price=",bid," sl=",stoploss," tp=",takeprofit); } else { res = OrderModify(ticket, 0, stoploss, takeprofit, 0); if(!res) {Print("OrderModify Error: ", GetLastError()); Print("IMPORTANT: ORDER #", ticket, " HAS NO STOPLOSS AND TAKEPROFIT");} } } }
You haven't given the 'minstopleve'l any value!
Make a simple calculation of your sl/tp then they should be >= it.
double point,ask,bid,minstoplevel;
-
Why did you post your MT4 question in the
Root /
MT5 General section
instead of the
MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. res = OrderModify(ticket, 0, stoploss, takeprofit, 0);
Of course you get error 130, you can't modify the open price to zero. (Select the order and use actual price.)extern double Take_Profit=300; // 5 digit broker? extern double Stop_Loss=150; stoploss=NormalizeDouble(bid+Stop_Loss*point,digits); takeprofit=NormalizeDouble(bid-Take_Profit*point,digits);
Using Points means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
How to manage JPY pairs with parameters? - MQL4 and MetaTrader 4 - MQL4 programming forum-
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't
use it. It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 and MetaTrader 4 - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 and MetaTrader 4 - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I keep getting error #130. I understand that it has to do with sl or tp however I tried many combinations including atr based and nothing works:
OrderSend Sell failed with error-130 symbol=EURTRY Lots=0.01 price=4.54817 sl=4.55851 tp=4.52749
OrderSend Sell failed with error-130 symbol=USDZAR Lots=0.01 price=13.46761 sl=13.46911 tp=13.46461
OrderSend Sell failed with error-130 symbol=USDMXN Lots=0.01 price=18.77151 sl=18.77301 tp=18.76851
OrderSend Buy failed with error-130 symbol=GBPPLN Lots=0.01 price=4.78105 sl=4.77955 tp=4.78405
OrderSend Sell failed with error-130 symbol=GBPJPY Lots=0.01 price=150.917 sl=151.067 tp=150.617
OrderSend Buy failed with error-130 symbol=USDHKD Lots=0.01 price=7.81448 sl=7.81298 tp=7.81748