Please can someone help with error 130.

 

I am using the following code to open trades based on signals from a custom indicator (attached)

When the indicator paints a green symbol i want to open open a long position on the open of the next bar and vice versa for a red symbol.

I know I have lots of work to get this to happen but all i want to get this to do at the moment is open a position on signal, but I cant get it to trade. I keep getting error 130. Even when i set SL and TP to 0.

Please can someone help me with this code. I have had various people try and explain but without a working example it is hard to progress and learn.


Thanks


#include <stdlib.mqh>

extern int dist2=6;
extern int SignalBar=2;
input double lots=3;
input double TakeProfit=160;  
input double sl=50;




int start()

        {
Alert(MarketInfo(Symbol(), MODE_STOPLEVEL));
      
   bool uptrend=iCustom(NULL,0,"super_signals_v2_alert",1,1)!=EMPTY_VALUE;
   bool downtrend=iCustom(NULL,0,"super_signals_v2_alert",0,1)!=EMPTY_VALUE;
   

      
      Comment(uptrend,"    ",downtrend);
      if(downtrend)
        {
         bool ticket=OrderSend(Symbol(),OP_SELL,3,Bid,3,sl,0);
         
        }
        
      
      else if(uptrend) 
        {
         ticket=OrderSend(Symbol(),OP_BUY,3,Ask,3,sl,0);
         
        }
        return(0);
       
        }
 
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 obsolescence. 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.


B.T.W. dont use a bool for OrderSend you use an int

see Here

 
ryangillSL:


I know I have lots of work to get this to happen but all i want to get this to do at the moment is open a position on signal, but I cant get it to trade. I keep getting error 130. Even when i set SL and TP to 0.


But you ARE setting a SL, default input 50

If you send a buy order at 1.5000 with SL at 50.0000 it will not be accepted.

 
GumRai:

But you ARE setting a SL, default input 50

If you send a buy order at 1.5000 with SL at 50.0000 it will not be accepted.


Hi,thanks for the reply, the with that in mind setting the SL and TP to 0 as default should eradicate error 130?

However I still get error 130.

How would i adjust the code taking into account 1:200 account and could someone please explain normalize and how this is used in my current circumstance.

Thank you for your help.


#include <stdlib.mqh>

extern int dist2=6;
extern int SignalBar=2;
input double lots=3;


int start()

        {
Alert(MarketInfo(Symbol(), MODE_STOPLEVEL));
      
   bool uptrend=iCustom(NULL,0,"super_signals_v2_alert",1,1)!=EMPTY_VALUE;
   bool downtrend=iCustom(NULL,0,"super_signals_v2_alert",0,1)!=EMPTY_VALUE;
   

      
      Comment(uptrend,"    ",downtrend);
      if(downtrend)
        {
         bool ticket=OrderSend(Symbol(),OP_SELL,3,Bid,3,0,0);
         
        }
        
      
      else if(uptrend) 
        {
         ticket=OrderSend(Symbol(),OP_BUY,3,Ask,3,0,0);
         
        }
        return(0);
       
        }
 
i don't see in your code GetLastError why do you think it's error 130
 
bool ticket=OrderSend(..............    // ????
check if OrderSend return true/false... ??
 

This is what I have.


I get this error on backtest:


2014.05.08 13:08:00.353 2013.11.27 03:45 tester EURUSD,M15: OrderSend error 130

#include <stdlib.mqh>

extern int dist2=6;
extern int SignalBar=2;
input double lots=3;
input double TakeProfit=160;  
input double sl=50;
input double tp=250;
extern int MagicNumber=45645;




int start()

        {
Alert(MarketInfo(Symbol(), MODE_STOPLEVEL));
      
   bool uptrend=iCustom(NULL,0,"super_signals_v2_alert",1,1)!=EMPTY_VALUE;
   bool downtrend=iCustom(NULL,0,"super_signals_v2_alert",0,1)!=EMPTY_VALUE;
   

      
      Comment(uptrend,"    ",downtrend);
      if(downtrend)
        {
         int ticket = OrderSend(Symbol(), OP_SELL, lots * 2, Bid, 3, Ask + sl * Point, 0,NULL, MagicNumber, 0, Red); 
         Sleep(20000);
        }
        
      
      else if(uptrend) 
        {
         ticket = OrderSend(Symbol(), OP_BUY, lots * 2, Ask, 3, Bid - sl * Point, Bid + tp * Point,NULL, MagicNumber, 0, Blue); 
         Sleep(20000);
        }
        return(0);
       
        }
 

are you using 5 digit broker or 4

i think 50 points is to close try 500

 

I can place trades now but only buy and not when the signals are fired as desired:

Can someone please have a look at the indicator to see what I mean, buyt when green paint at next bar and vice versa for sell. only one trade in each direction with oposite signal closing the position.


//+------------------------------------------------------------------+
//|                                            Tester.mq4            |
//|                                                                  |
//+------------------------------------------------------------------+

#include <stdlib.mqh>

extern int dist2=6;
extern int SignalBar=2;
input double lots=3; 
input double sl=500;
input double tp=1300;
extern int MagicNumber=45645;
int total = OrdersTotal(); 




int start()

        {
Alert(MarketInfo(Symbol(), MODE_STOPLEVEL));
      
   bool uptrend=iCustom(NULL,1,"super_signals_v2_alert",1,1);
   bool downtrend=iCustom(NULL,1,"super_signals_v2_alert",1,1);
   

      
      Comment(uptrend,"    ",downtrend);
      
      if(uptrend)
      
        {
         int ticket = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Ask + sl * Point, Ask + tp * Point,NULL, MagicNumber,1, Red); 
         Sleep(20000);
        }
        
      
      if(downtrend) 
      
        {
         ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Bid - sl * Point, Bid + tp * Point,NULL, MagicNumber, 0, Blue); 
         Sleep(20000);
        }
        return(0);
       
        }
 
   bool uptrend=iCustom(NULL,1,"super_signals_v2_alert",1,1);
   bool downtrend=iCustom(NULL,1,"super_signals_v2_alert",1,1);

it's the same

you have to do it like before

   bool uptrend=iCustom(NULL,0,"super_signals_v2_alert",1,1)!=EMPTY_VALUE;
   bool downtrend=iCustom(NULL,0,"super_signals_v2_alert",0,1)!=EMPTY_VALUE;
 

Thanks,


I cant get the trade entry right. Here is the logic from the indicator,

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_width1 4
#property indicator_color2 Lime
#property indicator_width2 4

extern int SignalGap = 4;

extern bool SoundON=true;
extern bool EmailON=false;

int dist=24;
double b1[];
double b2[];
int flagval1 = 0;
int flagval2 = 0;

int init()  {
   SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,1);
   SetIndexArrow(1,233);
   SetIndexArrow(0,234);
   SetIndexBuffer(0,b1);
   SetIndexBuffer(1,b2);
   return(0);
}
int start() {
   int counted_bars=IndicatorCounted();
   int k,i,j,limit,hhb,llb;
   
   if (counted_bars<0) return(-1);
   if (counted_bars>0) counted_bars--;
   limit=Bars-1;
   if(counted_bars>=1) limit=Bars-counted_bars-1;
   if (limit<0) limit=0;

   for (i=limit;i>=0;i--)   {
      hhb = Highest(NULL,0,MODE_HIGH,dist,i-dist/2);
      llb = Lowest(NULL,0,MODE_LOW,dist,i-dist/2);

      if (i==hhb)
      {
         if (i == 1 && flagval1==0)
         {
           flagval1=1;
           flagval2=0;
           if (SoundON) Alert( SELL HERE AT OPEN OF NEXT BAR)
         }
         b1[i]=High[hhb]+SignalGap*Point;
      }
      if (i==llb)
      {
         if (i == 1 && flagval2==0)
         {
           flagval2=1;
           flagval1=0;
           if (SoundON) Alert("BUY HERE AT OPEN OF NEXT BAR";
         }
         b2[i]=Low[llb]-SignalGap*Point;
      }
   }
   return(0);
}

I think i may have the wrong settings in the EA as I want to enter trades only on these signals, one trade open at any one time in one direction.


How would I transfer the above conditions into the EA code?