Got "OrderSend error 130" no Idea what to do =\

I edited this post because I realized my mistake.

I want to check the High and Low points between several hours, and use there difference (of the High and Low) for my orders.

Edited: I learned Java a bit and I made that short function to show you what I mean (hope you familiar with Java so you can understand me):

int currectHigh=0;
int nextHigh=0;

currectHigh=reader.nextInt();

for (int i=1 ; i<13 ; i++)
{
nextHigh=reader.nextInt();
If (currect<next)
{
currectHigh=nextHigh;
}
}
The idea is you enter your first bar high (currectHigh) and then enter the “for” loop 12 times (I want to check 12 hours), and each time compare the currect High to the next one you enter and if the next one is bigger, we change the value of “currectHigh” to “nextHigh” (the line “currectHigh=nextHigh;”)

And make all that again for the low of these 12 hours.
I really hope you understood me, if not please relay only to the first part of the post.

Thanks.

double
   My_High = High[iHighest(NULL,0,MODE_HIGH,12,0)],
   My_Low = Low[iLowest(NULL,0,MODE_LOW,12,0)];

Thanks you very much =]
Im starting to learn MQL4 seriosly now, and that functions will help me.

Okay, since I knew Java’s basics pretty good, I got MQL4 quite fast and created this code for Melodica System:

int start()
{
//----
if (Hour()==11:01)
{
double My_High = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,12,-1)];
double My_Low = Low[iLowest(NULL,PERIOD_H1,MODE_LOW,12,-1)];
double HL = My_High-My_Low;

  OrderSend(Symbol(),OP_BUYSTOP,0.01,My_High+2,0,My_Low,Ask+HL,NULL,0,10:00,CLR_NONE);
  }

//----
return(0);
}

Still didnt add the sell stop order.

I’m having some problem with it - I got that messege when I try to test it on MT4 :
TestGenerator: unmatched data error (volume limit 810 at 2010.05.12 17:00 exceeded).

I wont be surprised if there is a lot to add to this code.

Can someone help me with it please?

Okay so Im not sure why, but now I dont get the error I told you before, instead, the system just doest open any trade for me.
This is the new code :

int error,error2;
if (Hour()==11:01)
{
double My_High = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,12,-1)];
double My_Low = Low[iLowest(NULL,PERIOD_H1,MODE_LOW,12,-1)];
double HL = My_High-My_Low;

  OrderSend(Symbol(),OP_BUYSTOP,0.01,My_High+2*Point,0,My_Low,Ask+HL,NULL,0,10:00,CLR_NONE);
  error=GetLastError();
  Print (error);
  OrderSend(Symbol(),OP_SELLSTOP,0.01,My_Low-2*Point,0,My_High,Bid-HL,NULL,0,10:00,CLR_NONE);
  error2=GetLastError();
  Print (error2);
  }

//----
return(0);
}

Thanks for reading =]

I’ve gotten that error before and it’s a nasty one imo cause it sometimes is a catchall for undefined coding errors which makes it really hard to pinpoint. Couple of times I had something wrong with the parameters of a function and that error came up. Once it was I had the parameters in the wrong order, and another time it seemed to be a hidden character in the editor and after I deleted the whole line and retyped it, it was fine.

In your case, well, it could be the shift parameter being -1? I think -1 is to the right of the current bar meaning it’s looking for a bar that doesnt exist yet? The current bar is alway 0, +1 is the one to the left, +2 is 2 to the left etc. Just a thought. :slight_smile:

Yes!! you are right Im sure of that.
Im going to fix it right now and tell you if it worked.

Thanks for your respond.

Edit:

Thanks to Sweet Pip, I solved the last problem that the EA didnt try to open any trades.

Now Im getting new error every time the EA tries to open an order, actually two errors:
"symbol name for OrderSend function must be a string."
and
"OrderSend error 4062."
one after the other.

What is that mean?

You can get a list of errors in the MetaEditor. Which will at least give you a clue as to the problem.
Heres how:
If you don’t see a vertical split screen then click the “book icon” at the top. You should see a 3-tab panel which has "Files Dictionary Search"
type error in the search box
select “error codes” from the list and scroll down til you see the error you are looking for.

In this case looks like you have the wrong data type for a Symbol variable.

I did exacly what you sais and typed the error number. Got thins - “String parameter expected” witch is very similar to what the MetaTrader it self posted.

I tried to change the Symbol parameter to “GBPUSD” but still got the same messege. Also I saw that people always use “Symbol()” just like I do.
Ill post the code of this order again:

OrderSend(Symbol(),OP_BUYSTOP,0.01,My_High+2*Point,0,My_Low,Ask+HL,NULL,12345,10:00,CLR_NONE);
error=GetLastError();
Print (error);

Any idea? =

The 5062 error is due to the expiration time is expecting a string.
The 130 errors are all due to having the wrong prices for SL and TP.
Pending orders can be very tricky in MT4 .

I have added Print statements so that the result can be monitored.
Click on the Journal tab in the Strategy Tester after clicking Start.

I have also put the BP, SL and TP into vars prior to the SendOrder as this way you can monitor them.

double My_High = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,12,-1)];
double My_Low = Low[iLowest(NULL,PERIOD_H1,MODE_LOW,12,-1)];
double HL = My_High-My_Low; 

double BP=My_High+2*Point;
double SL=My_Low;
double TP=Ask+HL*Point;

Print("My_High:"+My_High+" My_Low:"+My_Low+" HL:"+HL);
Print("BP:"+BP+" SL:"+SL+" TP:"+TP);
OrderSend(Symbol(),OP_BUYSTOP,1.00,BP,0,SL,TP,NULL,12345,"10:00",CLR_NONE);

Hi there,

Firstly, I don’t know how your code is ever finding this line to be true :-

if (Hour()==11:01)

Hour() returns an integer and somehow 11:01 returns a value of zero, which is an integer, but I suspect MQL is actually returning it as an empty_value. The code produces a false everytime for me.

If you wish to trade once a day on the hour of 11, then use the New_Bar function :-

bool New_Bar()
{
   static datetime New_Time=0;
   if(New_Time!=Time[0]){
      New_Time=Time[0];
      return(true);
   }
   return(false);
}

Now to trade once at the hour of 11, simply say :-

if(New_Bar==true){
   if(Hour() == 11){
      ...................here is my code
   }
}

The problem that you are experiencing with Symbol() is not actually related to the Symbol() but rather to the expiration of 10:00. Once again, MQL does not understand this.

Replace your expiration with the following :-

iTime(Symbol(),PERIOD_H1,0) + 82800

Next question, who is your broker?

1 Like

Thanks for your very detail post.

I changed the expiration with the line you told me and now I dont get the error - for start.

I tried to add the New_bar function you gave me but then the MT4 wouldnt open any trade - if I remove that function the MT4 open a lot of trades in some signle days.

My correct code looks like this now:

int error,error2;

if (Hour()==11)
{
double My_High = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,12,1)];
double My_Low = Low[iLowest(NULL,PERIOD_H1,MODE_LOW,12,1)];
double HL = My_High-My_Low;

  OrderSend(Symbol(),OP_BUYSTOP,0.01,My_High+2*Point,0,My_Low,Ask+HL,NULL,12345,iTime(Symbol(),PERIOD_H1,0) + 82800,CLR_NONE);
  error=GetLastError();
  Print (error);
  OrderSend(Symbol(),OP_SELLSTOP,0.01,My_Low-2*Point,0,My_High,Bid-HL,NULL,12345,iTime(Symbol(),PERIOD_H1,0) + 82800,CLR_NONE);
  error2=GetLastError();
  Print (error2);
  }

What should I do? or where and how should I add the New_Bar function?

For your question, Im still trading in Demo account.

Place the New_Bar() function at the end of the EA, outside of the Start() function.

If that doesn’t work, then post the full code with the New_Bar function, so I can check if it is correct.

I still need to know what broker you are trading with…

edit : I jusr realised there is an error in the code I posted
To use New-Bar, use this code :-

if(New_Bar[B]()[/B]==true){
   if(Hour() == 11){
      ...................here is my code
   }
}

Every thing seems to be Okay, except that the functionts iHighest and iLowest returns values like for example 1.5343000 - for some reason the function adds “000” and because of that the price is invalid in MT4(it sends error saying that).

How do I currect this?
Tried to multiply My_High in “Point” function but it does the opposite.

You need to Normalise your doubles :-

NormaliseDouble(My_High+2*Point ,Digits);

At last the EA opens pending orders.

Two questions:

  1. should I use NormalizeDouble also for TP and SL values? because I did.
  2. I still get the OrderSend error 130 sometimes ? :S

Want me to post the whole code?

Thanks !!

  1. Yes
    2 Try changing the High & Low calculations to :-
double My_High = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,12,[B]0[/B])];
double My_Low = Low[iLowest(NULL,PERIOD_H1,MODE_LOW,12,[B]0[/B])];

Didnt help.
Ill just post the code I think its necessary :

int start()
{
//----

int error,error2;
if (New_Bar()==true)
{
if (Hour()==11)
{
double My_High = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,12,1)];
Print (NormalizeDouble(My_High ,Digits)+" This is the Highest");
double My_Low = Low[iLowest(NULL,PERIOD_H1,MODE_LOW,12,1)];
double HL = My_High-My_Low;

  OrderSend(Symbol(),OP_BUYSTOP,Lots,NormalizeDouble(My_High+2*Point ,Digits),0,NormalizeDouble(My_Low,Digits),Ask+HL,NULL,12345,iTime(Symbol(),PERIOD_H1,0) + 82800,CLR_NONE);
  error=GetLastError();
  Print (error);
  OrderSend(Symbol(),OP_SELLSTOP,Lots,NormalizeDouble(My_Low-2*Point ,Digits),0,NormalizeDouble(My_High,Digits),Bid-HL,NULL,12345,iTime(Symbol(),PERIOD_H1,0) + 82800,CLR_NONE);
  error2=GetLastError();
  Print (error2);
  }

}
//----
return(0);
}
//±-----------------------------------------------------------------+
bool New_Bar()
{
static datetime New_Time=0;
if(New_Time!=Time[0])
{
New_Time=Time[0];
return(true);
}
return(false);
}

Your problem is with your TakeProfit. It needs to be calculated relative to your order price, not the current price.

Yeah I totaly blow it there… no idea what I was thinking.

now every thing seem to work pretty good - still got some 130 error messeges but much less.
This is the code right now :

int start()
{
//----

int error,error2;
if (New_Bar()==true)
{
if (Hour()==11)
{
double My_High = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,12,1)];
Print (NormalizeDouble(My_High ,Digits));
double My_Low = Low[iLowest(NULL,PERIOD_H1,MODE_LOW,12,1)];
double HL = My_High-My_Low;

  OrderSend(Symbol(),OP_BUYSTOP,Lots,NormalizeDouble(My_High+2*Point ,Digits),0,NormalizeDouble(My_Low,Digits),NormalizeDouble(My_High,Digits)+NormalizeDouble(HL,Digits),NULL,12345,iTime(Symbol(),PERIOD_H1,0) + 82800,CLR_NONE);
  error=GetLastError();
  Print (error);
  OrderSend(Symbol(),OP_SELLSTOP,Lots,NormalizeDouble(My_Low-2*Point ,Digits),0,NormalizeDouble(My_High,Digits),NormalizeDouble(My_Low,Digits)-NormalizeDouble(HL,Digits),NULL,12345,iTime(Symbol(),PERIOD_H1,0) + 82800,CLR_NONE);
  error2=GetLastError();
  Print (error2);
  }

}

Another question, how do I apply trailing stop to each position witch effected (the trailing stop effected) by the variable “HL”?

Its tricky because HL changes every day, and its possible that older positions still opened.

Thanks.