Error 130 Issues - page 2

 

See Also

 https://www.mql5.com/en/forum/143607  for how you can make ordersend / orderclose work as well for 4 as for 5 digit broker

 

//+------------------------------------------------------------------+
//|                                                    Simple EA.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//Literally copying Ferrus Format to a tee

extern string Label1="===General Trade Settings===";
extern int   TakeProfit=25;
extern int    StopLoss=10;
extern int    TrailingStop=0;
extern int    Slippage=2;
extern double  Lot=0.1;
//---------Time Filter--------//

extern string Label5="===Moving Average Settings===";
extern int    MA_Period=200;
extern int    MA_Shift=0;
extern int    MA_Type=1;
extern int    MA_Price=0;



//-------Initialize EA Orders Accounting-----//



int start()
{
//--------------Bar CHeck------//
double EMA=iMA(NULL,PERIOD_M1,MA_Period,MA_Shift,MA_Type,MA_Price,0);
double BarClose;
BarClose=iClose(Symbol(),PERIOD_M1,0);                                         //<<==  BarClose = Bid;
//---------Adjusting for every digit broker-------------//
int mypoint;

if (Digits==3||Digits==5){ mypoint=10;}
else {mypoint=1;}
//------------Taking Trades----------//
if(BarClose>EMA)
{
double SLB=Bid-StopLoss*Point*mypoint;
double TPB=Bid+TakeProfit*Point*mypoint;
int buy= OrderSend(Symbol(),0,Lot,Ask,Slippage,SLB,TPB);     // 1   <<==OrderSend(Symbol(),0,Lot,Ask,Slippage * mypoint ,SLB,TPB);
}                                                            // 2   trades period chart   

if(BarClose<EMA)
{
double SLS=Ask+StopLoss*Point*mypoint;
double TPS=Ask-TakeProfit*Point*mypoint;

int sell= OrderSend(Symbol(),1,Lot,Bid,Slippage,SLS,TPS);   // 1   <<==OrderSend(Symbol(),0,Lot,Bid,Slippage * mypoint ,SLB,TPB);
}                                                            //2   << trades one minute period         Same as BUY ????

int err=GetLastError();
Alert(err);

return(0);
}

 If Bid is moving around EMA you will have open a lot of trades in a short period with each crossing

 

Here you go. Hope this is helpful.. I know what it's like trying to learn this stuff. I was lost for a while too. I just started recording some videos and posting them on youtube to try and help someone. if you search for Mql4 lessons .. you will find them.... keep learning....

.......Trade Safely....

JimDandy.

//+------------------------------------------------------------------+
//|                                                    Simple EA.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//Literally copying Ferrus Format to a tee

extern string Label1="===General Trade Settings===";
extern int   TakeProfit=25;
extern int    StopLoss=10;
extern int    TrailingStop=0;
extern int    Slippage=2;
extern double  Lot=0.1;
//---------Time Filter--------//

extern string Label5="===Moving Average Settings===";
extern int    MA_Period=200;
extern int    MA_Shift=0;
extern int    MA_Type=1;
extern int    MA_Price=0;



//-------Initialize EA Orders Accounting-----//



int start()
{
   //--------------Bar CHeck------//
   double EMA=iMA(NULL,PERIOD_M1,MA_Period,MA_Shift,MA_Type,MA_Price,0);
   double BarClose;
   BarClose=iClose(Symbol(),PERIOD_M1,0);
   //---------Adjusting for every digit broker-------------//
   int mypoint;
   
   if (Digits==3||Digits==5){ mypoint=10;}
   else {mypoint=1;}
   //------------Taking Trades----------//
   int total = OrdersTotal();
   if(total<1)// You only want to check to open orders. If you have none open. 
   {          //Otherwise it will open an order on every tick...
      if(BarClose>EMA)
      {
         double SLB=Bid-StopLoss*Point*mypoint;
         double TPB=Bid+TakeProfit*Point*mypoint;
         int buy = OrderSend(Symbol(),0,Lot,Ask,Slippage,SLB,TPB);
         //if order succeeds, int buy will be ticket number of order just placed.
         //if this was an ecn broker you can not send tp and sl along with order, you use zeros.
         //but if order succeeds .. you use the 'buy' (ticketnumber) of order just placed to select it then modify it.
         //if(buy>0)OrderSelect(buy,SELECT_BY_TICKET,MODE_TRADES)      //select the order you just placed 
         //OrderModify(OrderTicket(),OrderOpenPrice(),SLB,TPB,0,Green);//put in your SLB and TPB
         if(buy>0)  Print("BUY order opened : ",OrderOpenPrice());//if ticket number exists. Print.
         else       Print("Error opening BUY order : ",GetLastError());//otherwise get the error.
      }

      if(BarClose<EMA)
      {
         double SLS=Ask+StopLoss*Point*mypoint;
         double TPS=Ask-TakeProfit*Point*mypoint;
         int sell = OrderSend(Symbol(),1,Lot,Bid,Slippage,SLS,TPS);
         if(sell>0)  Print("SELL order opened : ",OrderOpenPrice());
         else        Print("Error opening BUY order : ",GetLastError()); 
      }
   }

//int err=GetLastError();You don't want this here it will run every tick.
//Alert(err);  Even if there is no error.

return(0);
}
//+------------------------------------------------------------------+
Files:
 

Also you might want to move that digit check into the init() function so that it does not run every tick.

int mypoint;
int init()
{
   //---------Adjusting for every digit broker-------------//
     
   if (Digits==3||Digits==5){ mypoint=10;}
   else {mypoint=1;}
   return (0);
}
 
Jimdandy:

Also you might want to move that digit check into the init() function so that it does not run every

 
ZacharyRC:

Thank you for the input  Jimdandy.



I am currently viewing your webpages. So far, error 130 is still happening, so I will try to figure it out. Oanda is not an ECN, so I should be able to adjust the stops in the OrderSend().

 
deVries:

See Also

 https://www.mql5.com/en/forum/143607  for how you can make ordersend / orderclose work as well for 4 as for 5 digit broker

 

 If Bid is moving around EMA you will have open a lot of trades in a short period with each crossing


Thank you deVries, making those changes today.
 
RaptorUK:

If your Broker is not an ECN you caan send the TP & SL with the OrderSend() so you don't need to do the OrderModify(), you do need to make sure your SL isn't too close . . .

Read this:   Requirements and Limitations in Making Trades  what is your Stoplevel ?  is it greater than 10 ?


what is your Stoplevel ?  is it greater than 10 ?
 
RaptorUK:

what is your Stoplevel ?  is it greater than 10 ?

Hey RaptorUK:



Yes it is larger than 10. Do you think it has something to do with my trade criteria? I just wanted to make an EA to get the hang of putting in stops but its proved to be a great learning opportunity.

 
ZacharyRC:

Hey RaptorUK:


Yes it is larger than 10. Do you think it has something to do with my trade criteria? I just wanted to make an EA to get the hang of putting in stops but its proved to be a great learning opportunity.


As I said before . . .

 

Read this:   Requirements and Limitations in Making Trades  

 

Order Type
Open PriceStopLoss (SL)TakeProfit (TP)
Buy
Modification is prohibited
Bid-SL ≥ StopLevelTP-Bid ≥ StopLevel
Sell
Modification is prohibitedSL-Ask ≥ StopLevelAsk-TP ≥ StopLevel
 

Your SL and TP have to be further away from the entry price than the Stoplevel.

With a Stoplevel of greater than 10 your SL is bad,  with a Stoplevel greater than 25 your TP is also bad.

extern int   TakeProfit=25;
extern int    StopLoss=10;
Reason: