buystop error 4107 / 130

 

got the following code. for the ordersend command i want to set the open price on the value of hh5 (highest price from last 5 bars), but i keep getting error 4107 or 130. Could someone show me what im doing wrong?

   atrvalue=iATR(NULL,0,20,0)*10000;
   atrcalc=atrvalue*1.5;
   hh5=High[iHighest(NULL,0,MODE_HIGH,5,1)];
   ll5=Low[iLowest(NULL,0,MODE_LOW,5,1)];
   hhll5=(hh5-ll5)*10000;
   if (NormalizeDouble(((hh5-ll5)*10000),0)<NormalizeDouble((atrvalue*1.5),0)) rule1="BUY";
   if (NormalizeDouble(((hh5-ll5)*10000),0)>NormalizeDouble((atrvalue*1.5),0)) rule1="SELL";
   ll3=Low[iLowest(NULL,0,MODE_LOW,3,1)];

   setuphigh=iHigh(NULL,0,1);
   if (setuphigh<hh5) rule2="BUY";
   if (setuphigh>hh5) rule2="SELL";

   setupclose=iClose(NULL,0,1);
   sma20=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1);
   if (setupclose>sma20) rule3="BUY";
   if (setupclose<sma20) rule3="SELL";


   if(OrdersTotal()>0) CheckOrders();

   buytp1=NormalizeDouble((hh5*pips2dbl), Digits);

   if(OrdersTotal()==0)
   {
     if (rule1=="BUY"&& rule2=="BUY"&& rule3=="BUY")
     {
       buystop=OrderSend(Symbol(),OP_BUYSTOP,lots,Ask+buytp1,50,NULL,NULL,NULL,MagicNumber,0,Blue);
       //sellstop=OrderSend(Symbol(),OP_SELLSTOP,lots,Bid-ll5*pips2dbl,50,Bid+hh5*pips2dbl,Bid-atrcalc*pips2dbl,NULL,MagicNumber,0,Red);
     }
   }
 

btw, i have the following also in my code, if anyone was wondering :)

//++++ 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)

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

double minlot  = MarketInfo(Symbol(),MODE_MINLOT);
   if (minlot == 0.01)   lots = NormalizeDouble(lots,2);
   if (minlot == 0.1)    lots = NormalizeDouble(lots,1);
   if (minlot == 1)      lots = NormalizeDouble(lots,0);
 

try to put some TP & SL

if it's not working try to change to OP_BUYLIMIT

 

TP and SL are not necessary with FXPro, other EA's without also worked. OP_BUYLIMIT is different order, i need OP_BUYSTOP.

See this:

 

if u sure about this (sl & tp) the only thing left to say is try 0 instead of NULL for SL & TP

 
qjol:

if u sure about this (ls & tp) the only thing left to say is try 0 instead of NULL for SL & TP


doesn't matter. i have this code (also with NULL) i different EA i created, which is working (where distance is an integer with a value of 10).

To me, i suppose i use the wrong command for : buytp1=NormalizeDouble((hh5*pips2dbl), Digits); I just can't get it right :)

buystop=OrderSend(Symbol(),OP_BUYSTOP,lots,Ask+distance*pips2dbl,50,NULL,NULL,NULL,MagicNumber,0,Blue);
 

i'm sorry i can't find in your code the value of distance

 

its not here, like i said: in a previous EA of mine i used that line of code to place the pending buy and sellstops, but it was using Ask+distance*pips2dbl as the open price, where the variable distance was declared as an integer with a default value of 10 back then... :) But the distance variable is not important - it was just to show a almost identical line of code which DID work :)

I'm pretty much a noob with MQL (just 2 months busy writing different EA's now). Am i right if i guess you're pretty new to MQL too, seeing your posts and questions? NOFI ofcourse :)

 

BTW u sure u want buy ask + hh5 or u want buy @ hh5 ?

 
qjol:

BTW u sure u want buy ask + hh5 or u want buy @ hh5 ?


@hh5 good point indeed, looked over it to many times now :) it works! thanks for fixing
 
  1. ido370:
    To me, i suppose i use the wrong command for : buytp1=NormalizeDouble((hh5*pips2dbl), Digits); I just can't get it right :)

    You don't have to normalize values, but you must have the buy stop at least MarketInfo(Symbol(), MODE_STOPLEVEL)*Point away from the Ask.


  2. double minlot  = MarketInfo(Symbol(),MODE_MINLOT);
       if (minlot == 0.01)   lots = NormalizeDouble(lots,2);
       if (minlot == 0.1)    lots = NormalizeDouble(lots,1);
       if (minlot == 1)      lots = NormalizeDouble(lots,0);
    These assume minlot is a power of 10 and that the step size is equal. Previously on IBFX minlot was 0.1 but step size was 0.01 (You could have 0.10, 0.11,....) No reason a broker couldn't have a minlot of 0.05. Do it right.
       double  minLot  = MarketInfo(Symbol(), MODE_MINLOT),
               lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
    lots = MathFloor(lots/lotStep)*lotStep;
    if (lots < minLot) ... 

  3. And to answer your OP
    buytp1=NormalizeDouble((hh5*pips2dbl), Digits);
    hh5 is a price (E.G. 1.2345) times pips2dbl gives you (.000012345) zero. pips * pips2dbl gives relative points, you wanted relative points/pips2dbl
    buytp1=(hh5-Ask)/pips2dbl);
    
    OR just open with hh5+spread.
  4. Finally you must adjust TP, SL, and slippage
    //++++ 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)
    int     init(){
        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; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    
    Note the dbl/pips2dbl and the Slippage.Pips*pips2points comments, that was originally in my code.