Help needed with Ordersend error 130

 

Below is my buy function. If I set variable order_type to 1 (for market order), it works, so I know my stoploss and takeprofit functions as working. The problem must be in the determination of price for the op_buylimit order. I am trying to calculate my order price by decreasing Ask by a percentage of the length (pct_of_length) of the candle body (at bar 1). I have tried a slew of coding variations (some including NormalizeDouble), but I cannot get beyond the error 130. Can anyone help? I am using IBFX, by the way.

Thanks in advance!

bool place_buy_order() {
int ticket, length_in_pips, offset_in_pips;
double buy_limit_price;
// pct_of_length is an external integer, currently set to 10
if ( order_type == 2 && pct_of_length > 0 )
{
length_in_pips = MathAbs(High[1]-Low[1]) * MathPow(10,Digits);
offset_in_pips = MathRound(length_in_pips * (pct_of_length/100));
buy_limit_price = Ask - offset_in_pips * Point;
ticket = OrderSend(Symbol(),OP_BUYLIMIT,LotSize(),buy_limit_price,0,stoploss("b",buy_limit_price),takeprofit("b",buy_limit_price),"",MAGICMA,0,Blue);
}
else
// market order
ticket = OrderSend(Symbol(),OP_BUY,LotSize(),Ask,Slippage,stoploss("b",Ask),takeprofit("b",Ask),"",MAGICMA,0,Blue);

if ( ticket == -1 ) return(false); else return(true);
}

 
Error 130 means your SL or TP is too close to the market price.
 
520fx wrote >>
Error 130 means your SL or TP is too close to the market price.

Or it's on the wrong side of price. I didn't have the time to try to decipher the code so I'm not sure which is the case. You can use a print statement adjacent to the OrderSend command to help troubleshoot.

- Tovan

 
tovan:

Or it's on the wrong side of price. I didn't have the time to try to decipher the code so I'm not sure which is the case. You can use a print statement adjacent to the OrderSend command to help troubleshoot.

- Tovan

tovan

i am new i have the same problem

with my ea - it work fine on the gbpusd but if i try to run it on the gpbjpy it also give me the same 130 error

so i have change the sl and tp. is it the entry point that is to close to the price

then the other is the print statement i dont know how to place that into my script to troiubleshoot it

can you be so kind and send me an example of how and where to place it

- johan

 
delcor wrote >>

tovan

i am new i have the same problem

with my ea - it work fine on the gbpusd but if i try to run it on the gpbjpy it also give me the same 130 error

so i have change the sl and tp. is it the entry point that is to close to the price

then the other is the print statement i dont know how to place that into my script to troiubleshoot it

can you be so kind and send me an example of how and where to place it

- johan

Hi Johan,

Here's a snippet of code with an example on how to use the Print function:

Print("Bid=", Bid, " Ask=", Ask, " Type of Order=", Mode, " StopLoss=", sl, " TakeProfit=", tp);
int TicketCheck=OrderSend(Symbol(), Mode, Lots, Price, Slippage, sl, tp, VER, MagicNumber, 0, Color);

This can help you find problems in execution. Sometimes you will be surprised by what you see in the Print output and it will lead you to bugs in your code. When my code won't run right I usually start with Print statements in the areas that don't seam to be working properly.

When you run the Strategy Tester you can watch these Print statements go by in the "journal" tab, or (better) you can open the log file after testing is complete at c:\Program Files\<Whatever your MetaTrader is called>\tester\logs

The Strategy Tester continues to use the same log - only starting a new one on a new day. So if you want to have a clean log with only one test run then you need to close MetaTrader and delete the log file before you test again.

The description of your problem sounds like your stop-loss is too close to the price. Many brokers require a greater offset with GBPJPY because of its volitility. You can use the following command to determine the minimum distance that your stop-loss must be placed from price:

MinimumStopLossOffset = MarketInfo( Symbol(), MODE_STOPLEVEL)

The response will be in pips so if you use that in your calculation then you would multiply it by Point.

Hope this helps.

- Tovan

 
tovan:

Hi Johan,

Here's a snippet of code with an example on how to use the Print function:

This can help you find problems in execution. Sometimes you will be surprised by what you see in the Print output and it will lead you to bugs in your code. When my code won't run right I usually start with Print statements in the areas that don't seam to be working properly.

When you run the Strategy Tester you can watch these Print statements go by in the "journal" tab, or (better) you can open the log file after testing is complete at c:\Program Files\<Whatever your MetaTrader is called>\tester\logs

The Strategy Tester continues to use the same log - only starting a new one on a new day. So if you want to have a clean log with only one test run then you need to close MetaTrader and delete the log file before you test again.

The description of your problem sounds like your stop-loss is too close to the price. Many brokers require a greater offset with GBPJPY because of its volitility. You can use the following command to determine the minimum distance that your stop-loss must be placed from price:

The response will be in pips so if you use that in your calculation then you would multiply it by Point.

Hope this helps.

- Tovan

thanks this helps a lot

this is what i get

2009.04.05 22:24:56 2008.08.15 00:00 jbGBPJPYoD1v1 GBPJPYm,Daily: Bid=204.86 Ask=204.95 Type of Order=1 StopLoss=500 TakeProfit=2000
2009.04.05 22:24:56 2008.08.14 00:00 jbGBPJPYoD1v1 GBPJPYm,Daily: OrderSend error 130

2009.04.05 22:24:56 2008.08.14 00:00 jbGBPJPYoD1v1 GBPJPYm,Daily: Bid=203.77 Ask=203.86 Type of Order=1 StopLoss=500 TakeProfit=2000

is the bid and ask price to close and if it is where will i change it

 
delcor wrote >>

thanks this helps a lot

this is what i get

2009.04.05 22:24:56 2008.08.15 00:00 jbGBPJPYoD1v1 GBPJPYm,Daily: Bid=204.86 Ask=204.95 Type of Order=1 StopLoss=500 TakeProfit=2000
2009.04.05 22:24:56 2008.08.14 00:00 jbGBPJPYoD1v1 GBPJPYm,Daily: OrderSend error 130

2009.04.05 22:24:56 2008.08.14 00:00 jbGBPJPYoD1v1 GBPJPYm,Daily: Bid=203.77 Ask=203.86 Type of Order=1 StopLoss=500 TakeProfit=2000

is the bid and ask price to close and if it is where will i change it

Hi Johan,

It looks like your Stop-Loss and Take-Profit are the problem. They need to be currency values, not pip values.

For instance, if you want a Stop-Loss of 500 pips above the Bid price of 204.95 then your Stop-Loss would be (204.95 + (500 * Point)). The Point multiplication converts pips to the correct decimal equivalent for the currency you are working with (the window you have the EA in).

Same for Take-Profit: ((2000 * Point) - Ask).

Hope this solves your problem.

- Tovan

 
tovan:

Hi Johan,

It looks like your Stop-Loss and Take-Profit are the problem. They need to be currency values, not pip values.

For instance, if you want a Stop-Loss of 500 pips above the Bid price of 204.95 then your Stop-Loss would be (204.95 + (500 * Point)). The Point multiplication converts pips to the correct decimal equivalent for the currency you are working with (the window you have the EA in).

Same for Take-Profit: ((2000 * Point) - Ask).

Hope this solves your problem.

- Tovan

Hi Tovan

thank you for all your help so far

this is the command for a buy and the sell is the same

res=OrderSend(strSymbol,OP_BUY,LotsOptimized(),Ask,Real.Slippage,Ask-Real.StopLoss*Point,Ask+Real.TakeProfit*Point,strComment,MAGICMA,0,Blue);
return;

so the actual price is "ask"

and hear i cot ask-real.StopLoss*Point

i had some one helping me code this EA and because i am new to this type of programming i want to learn what was programmed

i know you are busy - i need some one just to help me with some explanation on some of this coding

i have done the Ea course and understand most of it but there is just some other coding that bog my mind

can i corospond with you via email or skype?

 
delcor wrote >>

Hi Tovan

thank you for all your help so far

this is the command for a buy and the sell is the same

res=OrderSend(strSymbol,OP_BUY,LotsOptimized(),Ask,Real.Slippage,Ask-Real.StopLoss*Point,Ask+Real.TakeProfit*Point,strComment,MAGICMA,0,Blue);
return;

so the actual price is "ask"

and hear i cot ask-real.StopLoss*Point

i had some one helping me code this EA and because i am new to this type of programming i want to learn what was programmed

i know you are busy - i need some one just to help me with some explanation on some of this coding

i have done the Ea course and understand most of it but there is just some other coding that bog my mind

can i corospond with you via email or skype?

My e-mail is tovan(at)ieee(dot)org Feel free to write, but no guarantees about how quick I'll respond. I'm in the U.S., in Arizona, which is on U.S. Pacific time right now (GMT-7 with no daylight savings correction - same as GMT-8 this time of year). So I'm on my way to sleep as soon as I send this.

By the way, my earlier example was for a short position (since your order type was 1 - that's a sell). That's why I used the Bid price.

Also, I see that you're using a variable to carry the currency type. Be careful using the Point command with currencies other that the one in your window (that your EA is attached to). The Point value is different for the JPY crosses versus others as you probably know. So, for instance, if you're attached to a EURUSD chart and you're operating on USDJPY, I believe that the point value will still be for the EURUSD in this case. Now that I think about it I've never actually done that, but I think that's what will happen. Otherwise, I think everything in your code looks correct. I'm not familiar with the notation Real.Slippage, but I assume that this works for you? I don't know what the "Real." means so I don't know how the order of operation will work there. Once again, use the Print command if you have any problems...

Later,

Tovan

 
tovan:

My e-mail is tovan(at)ieee(dot)org Feel free to write, but no guarantees about how quick I'll respond. I'm in the U.S., in Arizona, which is on U.S. Pacific time right now (GMT-7 with no daylight savings correction - same as GMT-8 this time of year). So I'm on my way to sleep as soon as I send this.

By the way, my earlier example was for a short position (since your order type was 1 - that's a sell). That's why I used the Bid price.

Also, I see that you're using a variable to carry the currency type. Be careful using the Point command with currencies other that the one in your window (that your EA is attached to). The Point value is different for the JPY crosses versus others as you probably know. So, for instance, if you're attached to a EURUSD chart and you're operating on USDJPY, I believe that the point value will still be for the EURUSD in this case. Now that I think about it I've never actually done that, but I think that's what will happen. Otherwise, I think everything in your code looks correct. I'm not familiar with the notation Real.Slippage, but I assume that this works for you? I don't know what the "Real." means so I don't know how the order of operation will work there. Once again, use the Print command if you have any problems...

Later,

Tovan

Hi tovan

did you get my email with the EA's


johan

Reason: