multiple orders - error 130
- RefreshRates AFTER sleeping and THEN calculate entry price.
- On 5 digit brokers you must adjust TP, SL, AND SLIPPAGE
- On ECN brokers you must OrderSend and THEN set the stops.
- You can not set pending orders closer to market than MarketInfo(Symbol(), MODE_STOPLEVEL)*Point On IBFX that's 3 pips 30 points
- MarketInfo(Symbol(), MODE_ASK) is equivalent to just Ask.
- MarketInfo(Symbol(),MODE_SPREAD)*Point/pips2dblMI(spread) is in points. *Point/pips2dbl is the same as /pips2points On IBFX the spread is 2.2 which is less than the stoplevel.
- On buy orders you must add the spread to your entry price (highest high+spread*2). On sells you don't (Lowest low-spread)
- Once you open, you do not want to open more orders on the next tick. Add once per bar code.
thanks for your input, this is the complete code i have, with some change you suggested (refresh after sleep). BUt there's still a lot of error 130 now. Can you point me where i go wrong?
//+------------------------------------------------------------------+ //| Timetrader.mq4 | //| Copyright © 2011, Ido Kasse | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, Ido Kasse" #property link "" int MagicNumber; extern double lots = 0.1; double hh14, ll14, ll9, hh9; double buyentry14, sellentry14, buyentry9, sellentry9, spread; static datetime barStart; //++++ These are adjusted for 5 digit brokers. double pips2points, // slippage 3 pips 3=points 30=points pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) //Close orders void CloseOrders() { for(int i=OrdersTotal()-1; i>=0; i--) { OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_SELL&& OrderMagicNumber()==MagicNumber) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),NULL, Yellow); if(OrderType()==OP_SELLSTOP&& OrderMagicNumber()==MagicNumber) OrderDelete(OrderTicket()); if(OrderType()==OP_BUY&& OrderMagicNumber()==MagicNumber) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),NULL, Yellow); if(OrderType()==OP_BUYSTOP&& OrderMagicNumber()==MagicNumber) OrderDelete(OrderTicket()); } } //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //DIGIT FIX if (Digits == 5 || Digits == 3) { // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } //CREATE MAGICNUMBER - GLOBAL. string id = WindowExpertName() + Symbol() + Period(); // If there isn't already a Global Variable with the id in wich search for the MagicNumber create it if(!GlobalVariableCheck(id)) { MagicNumber=WindowHandle(Symbol(),0); GlobalVariableSet(id,MagicNumber); } else // Get the MagicNumber for the unique id { MagicNumber = GlobalVariableGet(id); } //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- //RUN ONCE PER BAR if (barStart < Time[0]) //start of new bar { barStart = Time[0]; //CALCULATIONS hh14=High[iHighest(NULL,0,MODE_HIGH,14,1)]; ll14=Low[iLowest(NULL,0,MODE_LOW,14,1)]; hh9=High[iHighest(NULL,0,MODE_HIGH,9,1)]; ll9=Low[iLowest(NULL,0,MODE_LOW,9,1)]; spread=MathCeil(MarketInfo(Symbol(),MODE_SPREAD)*Point/pips2dbl)*(pips2points*Point); double stoplevel=MarketInfo(Symbol(), MODE_STOPLEVEL)*pips2dbl; //PLACE ORDERS if (Hour()==9 && Minute()==30) { CloseOrders(); while(IsTradeContextBusy()) Sleep(100);RefreshRates(); buyentry14=NormalizeDouble((hh14+5*pips2dbl),Digits); sellentry14=NormalizeDouble((ll14-5*pips2dbl),Digits); OrderSend(Symbol(),OP_BUYSTOP,lots,buyentry14,100,sellentry14,Ask+20*pips2dbl,NULL,MagicNumber,0,CLR_NONE); while(IsTradeContextBusy()) Sleep(100);RefreshRates(); buyentry14=NormalizeDouble((hh14+5*pips2dbl),Digits); sellentry14=NormalizeDouble((ll14-5*pips2dbl),Digits); OrderSend(Symbol(),OP_SELLSTOP,lots,sellentry14,100,buyentry14,Bid-20*pips2dbl,NULL,MagicNumber,0,CLR_NONE); } //PLACE ORDERS if (Hour()==16 && Minute()==15) { CloseOrders(); while(IsTradeContextBusy()) Sleep(100); RefreshRates(); buyentry9=NormalizeDouble((hh9+5*pips2dbl),Digits); sellentry9=NormalizeDouble((ll9-5*pips2dbl),Digits); OrderSend(Symbol(),OP_BUYSTOP,lots,buyentry9,50,sellentry9,Ask+20*pips2dbl,NULL,MagicNumber,0,CLR_NONE); while(IsTradeContextBusy()) Sleep(100); RefreshRates(); buyentry9=NormalizeDouble((hh9+5*pips2dbl),Digits); sellentry9=NormalizeDouble((ll9-5*pips2dbl),Digits); OrderSend(Symbol(),OP_SELLSTOP,lots,sellentry9,50,buyentry9,Bid-20*pips2dbl,NULL,MagicNumber,0,CLR_NONE); } } //---- return(0); } //+------------------------------------------------------------------+
i'm trying to send 2 stop orders after each other, but i get a lot of error 130's.
this is the code i use:
So what should i change to get rid of the errors? Right now only the first order is taken it seems