Dreaded error 130 ...

 

Hello,

I`m getting this nasty error 130, I've triple checked that I`m normalizing everything for my Stop loss, I really don`t see where it's coming from :

2011.01.30 14:45:57 2010.12.17 23:59 EA_v01 AUDUSD,H4: OrderSend error 130

double size;

size = 0.01;

entry = NormalizeDouble(High[1],Digits)+ (2 * Point);

SL = NormalizeDouble(High[1],Digits)- (30*Point);

TP = NormalizeDouble(entry+iATR(NULL,1440,14,0),Digits);

RefreshRates();

Ticket=OrderSend(Symbol(),OP_BUYSTOP,size,entry,20,SL,TP,NULL,0,time+3600*12);//Opening Buy 1

Can anybody see what's wrong ?? My SL "seems" to be kosher ..

 
are you using a 5 digit broker?
 
indeed ! goMarkets
 

I suspect that you have not downloaded the D1 data for the period you are testing. That will result in your TP = entry + 0 and that would be an invalid stop.

I know the documentation says you should normalise your stops but any normalise error would result in an error 129 which is an invalid price, not error 130. Invalid stops are caused by poorly calculated stops ie your TP is less than entry + stoplevel or SL is above entry - stoplevel for a buy. Vice versa for sell. In your case with no 1440 data, the iATR will = 0(default for no data) which means your TP = entry.

Your refreshrates is useless where it is sitting beacuse you have already calculated all your prices. You only need refreshrates if you have extensive code, or if you are working with multiple orders in a loop.

 

@kenny, thanks for your answer, I've downloaded all the data for all the timeframes, I'm still getting the error though, something must be wrong somewhere else in my code, part of it is that it seems to be trading much more than it should, I need to find a way to ensure that it's only trading once per bar, never really had the problem before ..

 

Alright, this is what I don`t get, I've added the datetime thingy to make sure it's only trading once per bar,so that's all good .

I've also downloaded all the data ( in all timeframes ) to get 90% modeling quality, and I've added this Print statement :

Print("entry: "+DoubleToStr(entry,5)+"Stop Loss : "+DoubleToStr(SL,5)+"Take Profit : "+DoubleToStr(TP,5));

To make sure that i'm not dealing with erroneous values :

This is a sample of what I'm getting :

2011.01.30 22:27:05 2010.12.17 20:00 EA_v01 AUDUSD,H4: 130

2011.01.30 22:27:05 2010.12.17 20:00 EA_v01 AUDUSD,H4: entry: 0.98760Stop Loss : 0.98358Take Profit : 0.99986

2011.01.30 22:27:05 2010.12.17 20:00 EA_v01 AUDUSD,H4: OrderSend error 130

The weird thing is that sometimes the order will go through, like here :

2011.01.30 22:27:05 2010.12.08 20:00 Tester: stop loss #17 at 0.97935 (0.97688 / 0.98339)

2011.01.30 22:27:05 2010.12.08 20:00 Tester: order #17, buy 0.01 AUDUSD is opened at 0.98337

2011.01.30 22:27:05 2010.12.08 20:00 EA_v01 AUDUSD,H4: 0

2011.01.30 22:27:05 2010.12.08 20:00 EA_v01 AUDUSD,H4: entry: 0.98337 Stop Loss : 0.97935Take Profit : 0.99707

2011.01.30 22:27:05 2010.12.08 20:00 EA_v01 AUDUSD,H4: open #17 buy stop 0.01 AUDUSD at 0.98337 sl: 0.97935 tp: 0.99707 ok

 

Then I would investigate the entry price relative to the Ask price, taking the spread into account. Your tester is using the current spread and if the new bar opens just a fraction above the high of the previous bar, especially with a big spread, you could have a situation where you are trying to place a buystop below the (tester calculated) Ask price.

Try something like this :-

entry_base = MathMax(High[1],Ask);
entry = NormalizeDouble(entry_base + (2 * Point), Digits);
 
entry = NormalizeDouble(High[1],Digits)+ (2 * Point);
SL = NormalizeDouble(High[1],Digits)- (30*Point); 
  1. You can't open limit/stops closer than MarketInfo(Symbol(), MODE_STOPLEVEL)*Point from market. On IBFX that's 3 pips, 30 points.
  2. You can't set stops closer to the entry price than the same amount.
  3. On ECN brokers you must open the order and then set the stops.
  4. Adjust your TP, SL, entry, 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
    

Reason: