BuyStop SellStop Order error, please help!!!

 
I'm making an EA that makes pending orders for breakout strategies. However during backtesting orders couldn't be sent. It kept displaying the following 3 errors:
"OrderSend error 130"
"OrderSend error 4107" but I'd already allowed dll imports
and
"invalid takeprofit for OrderSend Function"
I've tested and checked it many times, still couldn't manage to fix it.

The value of takeprofit is 15 and is certainly viable because I've previously made successful orders both manually and by using another script.

One strange thing was that I'd tried to print the values of "high" and "low" and the outcome were both 5-digit while the mt4 itself is a 6-digit one. I don't know whether this has anything to deal with the errors.

Could anyone please help me?

int CurrentTime = Hour()*100 + Minute();
double high = High[iHighest(0,0,MODE_HIGH,8,1)];
double low = Low[iLowest(0,0,MODE_LOW,8,1)];
if (CurrentTime >= start || CurrentTime < end)
  {
  if(GateB==0)
    {
    Buy=OrderSend(Symbol( ) ,OP_BUYSTOP,Lots,high,Slip,low,high+Point*TakeProfit,"",0,0,Blue);
    GateB=1;
    }
  }  
 
The Print function outputs 4 decimal places by default. So use DoubleToStr with a parameter of 5 to output 5 decimal place values eg. Print(DoubleToStr(myPrice,5));
When dealing with a 5 decimal places broker, you will need to multiply your stop offsets by 10.
You should also check whether your broker allows stops to be set in the order send - otherwise you need to open, select and modify. You can easily check this by testing with a manual order.

CB
 
You are specifing your stops in Pips, but on a 5 digit broker a pip is NOT a Point. You must either change your stops and slippage or have the EA do it:
//++++ 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; }
also you can not set stops closer than
MarketInfo( Symbol(), MODE_STOPLEVEL )*Point
On IBFX, that's is 30 (3 pips) but you were using 15 Points, thus the 130 error.
Both Hour() and Minute() return the hour, minute of the last known server time when the expert started running. They will remain constant throughout the EA run
https://docs.mql4.com/dateandtime/TimeHour For your test you could use TimeHour(TimeCurrent())*100+TimeMinute(TimeCurrent()) or more simplier
string start = "17:35", end = "23:00";
if (TimeCurrent() >= strToTime(start) && TimeCurrent() <= strToTime(end)) {
   //.. trading is allowed
Note the && there, when you used || that allows all times.
Note, also you can not use datetime start = D'12:30' as that's 12:30 of the date you compiled.
Note if you want to test for a period that goes through midnight the above will not work.
 
Thanks guys for your kind response,
however my script runs well and properly.
The variable CurrentTime is an integer, not the function TimeCurrent().
e.g. if I set CurrentTime = 900, the trade will start exactly at server time 09:00
int CurrentTime = Hour()*100 + Minute();
and I'm using a 5-digit broker (GoMarket), just don't know why the outcome is 4-digit.

I've finally figured out the problem, it seemed that errors will occur for SendOrder() if i use more than three or more levels of "if()".
i.e.
if()
  {
  if()
    {
    if()
      {
      SendOrder();}
    }
  }  
Is it a setting of MQL4?
 
lmyyyks:
I've finally figured out the problem, it seemed that errors will occur for SendOrder() if i use more than three or more levels of "if()".
Is it a setting of MQL4?

No. You can have more than 3 levels with no problem. Either there's a logic error or one of the 'if' expressions is never true.


The variable CurrentTime is an integer, not the function TimeCurrent().
e.g. if I set CurrentTime = 900, the trade will start exactly at server time 09:00

What was hinted is that u should use native datetime format instead of 'inventing' your own time convention... But that's up to u.


and I'm using a 5-digit broker (GoMarket), just don't know why the outcome is 4-digit.

Did u try DoubleToStr() as CB suggested?
Reason: