130 Execution Error

 

I'm having trouble creating EAs because, for some reason, the OrderSend order does not work. I have tried a number of very simple EAs, using different signals, etc., and all do not work, citing a 130 execution error. Below is one of the EAs that have had this problem. I feel stupid because I am unable to figure out what I'm doing wrong, even though I have created many successful EAs in the past, but even those do not work. It makes me think that there is something on the platform that I have done wrong. The "Expert Advisers" button is pushed, and in the Tools menu, with "Options" selected, I have selected all boxes (except the disable EAs when a new account is opened or when profile changed). If anyone has any suggestions as to what I'm screwing up, I would be very grateful. Thanks.

//+------------------------------------------------------------------+
//| Test 001.mq4 |
//| Copyright © 2008, Nassau Precepts & Analytics Ltd |
//| http://www.nassauprecepts.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Nassau Precepts & Analytics Ltd"
#property link "http://www.nassauprecepts.net"


//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
double WPR0,WPR1,ticket;
double total,Lots;

WPR0=iWPR(NULL,0,14,0);
WPR1=iWPR(NULL,0,14,1);
Lots=0.1;
//----
if(WPR0>WPR1)
Print("Open buy order at: ",Bid);
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,30,Ask-100*Point,Ask+200*Point,"Test 001",10000,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
}
//+------------------------------------------------------------------+

 

You can find the list of trading error codes here.

ERR_INVALID_STOPS 130 Stops are too close, or prices are ill-calculated or unnormalized (or in the open price of a pending order). The attempt can be repeated only if the error occurred due to the price obsolescense. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.

This is a very Common Error. Doing a Simple search will give you allot of solutions for this Error.

Stop_Level=   MarketInfo(Symbol(),MODE_STOPLEVEL);
Also, allot of brokers Do-Not allow sending Stoploss and TakeProfit in the initial OrderSend. You'll have to send with value of 0 and then OrderModify.
 
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,30,Ask-100*Point,Ask+200*Point,"Test 001",10000,0,Red);
  1. Lots is never set
  2. ECN broker? TP/SL must be zero and then modified, like ubzen said