HELP・HELP・HELP
You are opening a Sell then trying to modify it with a stoploss below the entry price and a Take profit above the entry price.
Of course you get the invalid stops error
-
Play videoPlease edit your post.
For large amounts of code, attach it.
int ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,NULL,1,0,NULL);
Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles- OrderSend takes a Color for the arrow; NULL is not a color.
for(int i=0;i<=OrdersTotal();i++)
Position total will never exist.if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true && OrderType() == OP_SELL && OrderMagicNumber() == 1)
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.double stoploss=NormalizeDouble(Bid-80*Point,Digits); double takeprofit=NormalizeDouble(Bid+80*Point,Digits);
- You buy at the ask; sell at the bid. So for sell orders, the stops are buy orders.
- 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 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 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 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- For sell orders the SL must be above the market.
Dear,why dose below program always display ” ordermodify error 130 ” ?
void OnTick()
{
//---
if(Hour() == 1 && OrdersTotal() == 0)
{
int ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,NULL,1,0,NULL);
for(int i=0;i<=OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true && OrderType() == OP_SELL && OrderMagicNumber() == 1)
{
//--- calculated SL and TP prices must be normalized
double stoploss=NormalizeDouble(Bid-80*Point,Digits); /*Digits=3*/
double takeprofit=NormalizeDouble(Bid+80*Point,Digits);
int rsp = OrderModify(OrderTicket(),OrderOpenPrice(),stoploss,takeprofit,0,NULL);
}
}
}
}
thank you!
<journal>
2016.01.11 21:20:34.160 USDJPY-a01,M30: 2160205 tick events (2342 bars, 2161205 bar states) processed in 0:00:03.307 (total time 0:00:05.928)
2016.01.11 21:20:34.160 2015.12.29 23:59 Tester: order #1 is closed
2016.01.11 21:20:30.853 2015.10.01 01:00 rr USDJPY-a01,M30: OrderModify error 130
2016.01.11 21:20:30.853 2015.10.01 01:00 rr USDJPY-a01,M30: open #1 sell 0.10 USDJPY-a01 at 119.866 ok
2016.01.11 21:20:30.851 2015.10.01 00:00 rr test started
2016.01.11 21:20:30.282 TestGenerator: spread set to 10