Forex Factory (https://www.forexfactory.com/forum.php)
-   Platform Tech (https://www.forexfactory.com/forumdisplay.php?f=69)
-   -   Error #130... what else right? (https://www.forexfactory.com/showthread.php?t=217271)

decidence Jan 23, 2010 5:27pm | Post# 1

Error #130... what else right?
 
This seems like the bane of all OrderSend errors. I can't seem to figure out why the Stop loss price is not calculating properly. I've tried multiplying it by 10 etc but it always gives the same error and printout.

Error: EURGBP,M1: Enter Price: 0.74660000 Stop Loss: 0.74705000 Take Profit: 0.74600000


Inserted Code
void EnterTrade( double risk, int sl, int tp )
{
   RefreshRates();

   double SL, TP;
   int dollarsAtRisk = AccountEquity() * Risk;
   g_PositionSize = NormalizeDouble( (dollarsAtRisk / sl), 1 );
   
   if( g_ConfirmLong == true )
   {
      SL = Ask - (sl * Point);
      TP = Ask + (tp * Point);
      
      g_TradeID = OrderSend( Symbol(), OP_BUY, g_PositionSize, Ask, Slippage, NormalizeDouble( SL, Digits ), NormalizeDouble( TP, Digits ), TradeComment, 0, 0, Green );
      
      Print( "Enter Price: " + Ask + " Stop Loss: " + SL + " Take Profit: " + TP );
      
      if( g_TradeID < 0 )
      {
         Print( "OrderSend failed with error#", GetLastError() );
         ResetVars();
         return(0);
      }
sl and tp are passed by value integers of 45 and 60.

doc816 Jan 23, 2010 6:33pm | Post# 2

I may be wrong but, try to NormalizeDouble(Ask) for entry price as well.

hayseed Jan 23, 2010 6:36pm | Post# 3

guessing here
 
we have to recreate your entire ea in our minds and then guess at what could be causing the problem when only a small part of the code is shown.....

my guess would be you have some sort a compainion function for the shorts....

maybe a g_ConfirmShort == true condition

and it has

g_TradeID = OrderSend( Symbol(), OP_BUY, g_PositionSize, Ask, Slippage, NormalizeDouble( SL, Digits ), NormalizeDouble( TP, Digits ), TradeComment, 0, 0, Green );

instead of OP_SELL.... but that's just a guess.....h

decidence Jan 23, 2010 7:16pm | Post# 4

nah the else is this...

Inserted Code
   else
   {
      SL = Bid + (sl * Point);
      TP = Bid - (tp * Point);
   
      g_TradeID = OrderSend( Symbol(), OP_SELL, g_PositionSize, Bid, Slippage, NormalizeDouble( SL, 4 ), NormalizeDouble( TP, 4 ), TradeComment, 0, 0, Green );
      
      Print( "Enter Price: " + Bid + " Stop Loss: " + SL + " Take Profit: " + TP );
      
      if( g_TradeID < 0 )
      {
         Print( "OrderSend failed with error#", GetLastError() );
         ResetVars();
         return(0);
      }

hayseed Jan 23, 2010 7:54pm | Post# 5

all ok
 
1 Attachment(s)
both the buys and sells go thru for me, stoplosses and takeprofits are sent correctly..... had to modify a few things but nothing that would have resulted in correcting your error.....

without knowing more, it's difficult to trouble shoot......h
deced.mq4

decidence Jan 23, 2010 7:56pm | Post# 6

What kind of info do you need?

This is happening for me in the Strategy Tester and I am using FXPro which is a 5 digit broker, is there anything else that would help?

hayseed Jan 23, 2010 8:17pm | Post# 7

4
 
just notice te sell had 4 instead of digits.... NormalizeDouble( SL, 4 ),

what is ResetVars(); doing.....h

decidence Jan 23, 2010 8:24pm | Post# 8

Nothing really important, just resets the main loop to start looking for a new trade that meets my rules.

Inserted Code
void ResetVars()
{
   g_SignalLong      = false;
   g_SignalShort     = false;
   g_ConfirmLong     = false;
   g_ConfirmShort    = false;
   g_LookLong        = false;
   g_LookShort       = false;
   g_MonitoringTrade = false;
}

hayseed Jan 23, 2010 8:28pm | Post# 9

math
 
hey decidence..... the only way i can reproduce the error is by changing the OP_SELL to OP_BUY.... which reproduces it perfectly..... but that has been ruled out.....

one thing might help would be to change Enter Price to Buying Enter Price and Selling Enter Price so as to better distinguish between orders....h




Inserted Code
 
if( g_ConfirmLong == true )
   {
      SL = Ask - (sl * Point);
      TP = Ask + (tp * Point);
 
      g_TradeID = OrderSend( Symbol(), OP_BUY, 0.1, Ask, 3, NormalizeDouble( SL, Digits ), NormalizeDouble( TP, Digits ), 0, 0, 0, Green );
 
      Print( "Buying Enter Price: " + Ask + " Stop Loss: " + SL + " Take Profit: " + TP );
 
      if( g_TradeID < 0 )
      {
         Print( "OrderSend failed with error#", GetLastError() );
         //ResetVars();
         return(0);
      }
 
   }
 
     else
 
      {
      SL = Bid + (sl * Point);
      TP = Bid - (tp * Point);
 
      g_TradeID = OrderSend( Symbol(), OP_SELL, 0.1, Bid, 3, NormalizeDouble( SL, 4 ), NormalizeDouble( TP, 4 ), 0, 0, 0, Green );
 
 
      Print( "Selling Enter Price: " + Bid + " Stop Loss: " + SL + " Take Profit: " + TP );
 
 
      if( g_TradeID < 0 )
      {
         Print( "OrderSend failed with error#", GetLastError() );
         //ResetVars();
         return(0);
      }
    }

decidence Jan 23, 2010 8:38pm | Post# 10

I changed the "4" in the sell order to "Digits" to match up with the buy order, and made that change you suggested. Still got the error though.

2010.01.23 17:37:27 2008.02.01 01:36 EURGBP,M1: Selling Enter Price: 0.74660000 Stop Loss: 0.74705000 Take Profit: 0.74600000


Its like it's doing the digit math wrong or something, since you can see it's setting the SL to 4.5 pips instead of 45 which is what's passed in to the function.

hayseed Jan 23, 2010 8:52pm | Post# 11

450 600
 
try changing 45 and 60 to 450 and 600..... perhaps the spread or mode_stoplevel are getting in the way..... increasing should rule those out......h

decidence Jan 23, 2010 9:06pm | Post# 12

So I did this...

Inserted Code
      SL = Ask - (sl * 10 * Point);
      TP = Ask + (tp * 10 * Point);

and vice versa for sell orders, and that worked, yay! But it seems very unreliable depending on the broker someone might use my EA on.

hayseed Jan 23, 2010 9:12pm | Post# 13

450 and 600
 
no, change the 45 to 450 and 60 to 600.... where ever sl and tp are declared.... do not use (sl * 10 * Point); .....h

decidence Jan 24, 2010 3:27am | Post# 14

Thanks for all the help, time to start tweaking my settings for backtesting. Really sucks that the spreads are locked in at their highest levels over the weekend =(

mladen Jan 25, 2010 2:52am | Post# 15

...
 
decidence

The most probable cause for the error you are having is that your broker is an ECN / STP broker
When opening orders on ECN / STP broker you have to do it in 2 steps instead of the usual 1 :

1. open an order WITHOUT SL and/or TP
2. Modify the order opened that way by setting your SL and/or TP


CoVal Jan 25, 2010 7:51am | Post# 16

decidence

The most probable cause for the error you are having is that your broker is an ECN / STP broker
When opening orders on ECN / STP broker you have to do it in 2 steps instead of the usual 1 :

1. open an order WITHOUT SL and/or TP
2. Modify the order opened that way by setting your SL and/or TP

no, the author wrote that it was FxPro, and that's a MM not ECn....

I guess that the problem is that you try to set the SL or TP too close to the Ask or Bid price.... especially that you deal with eurgbp.... there is usually given margin you have to respect + the spread....

tristin Apr 1, 2011 3:57pm | Post# 17

My Issue Is Fixed
 
The post about sending the order without stops and targets and then using OrderModify worked for me, thanks!

John

tristin Apr 3, 2011 12:00pm | Post# 18

I spoke too soon...
 
That fixed my problem with executing trades in my demo account - but now my tester is giving 130 errors. Is there a consistent way to send the same set of trades to my demo account and allow me to test with that same EA?


© Forex Factory