error 130

 

I have been getting this error and I cant seem to figure out the cause.

I have been trying for the last 3 days to figure it out. I assume its because of my send order operation so I have adjusted everything I can think of. Nothing seems to stop it from appearing in my journal during backtesting.

one thing it says in the documentation is it may simply be that there is information it cannot translate. I was hoping someone could help me pinpoint the cause. I have looked through the documentation for everything related to send orders and errors. I have scoured through looking for explanations on ask and bid and and i have tried using MarketInfo() to gather data to use in order to calculate my ask and bid. I have created take profit and stop loss for both buy and sell orders. Not sure what else to try. I have done my best to try and comment my code as much as possible.

The code is supposed to identify an engulfing pattern and either buy or sell based on the trend. If there is a bull trend then buy on bull engulfing patterns if there is a bear trend then sell when there is a bear engulfing pattern.

So far not only do I get buying and selling error 130 it seems like its not obeying my if checks. it seems to buy and sell even if there is no engulfing pattern.

I appreciate you time folks.

I really am trying hard to find it on my own but I'm stumped. 


#property strict

//+------------------------------------------------------------------+
//|                         Variables 
//+------------------------------------------------------------------+

//For loop variable
int i;

//Variables to store the value of the entire candle
double totalCandleValueOne = High[1]-Low[1];
double totalCandleValueTwo = High[2]-Low[2];
double totalCandleValueThree = High[3]-Low[3];

//Variable to hold the percentage each part of the candle is of the entire candle
double topWickOne;
double bodyOne;
double bottomWickOne;
double topWickTwo;
double bodyTwo;
double bottomWickTwo;
double topWickThree;
double bodyThree;
double bottomWickThree;

//varible to test the close value of candles to find trends
double candleValue;

//variable to adjust the trend length (candles to consider to find the trend)
int trendLength =101;
int up = 0;
int down = 0;

//varible for orders
double ticket;
double pips;

//Variables for buy and sell take profit
double takeProfit = 500;
double takeProfitBuy = Ask+(takeProfit*pips);
double takeProfitSell = Bid-(takeProfit*pips);

//variables for buy and sell stop loss
double stopLoss = 150;
double stopLossSell = Bid+(stopLoss*pips);
double stopLossBuy = Ask-(stopLoss*pips);




//+------------------------------------------------------------------+
//|                           On Init
//+------------------------------------------------------------------+
int OnInit()
  {
   double ticketSize = MarketInfo(Symbol(),MODE_TICKSIZE);
   if(ticketSize == 0.00001 || ticketSize == 0.001)
   pips = ticketSize*10;
   else pips = ticketSize;
   return INIT_SUCCEEDED;
  }
  


//+------------------------------------------------------------------+
//|                          On Tick
//+------------------------------------------------------------------+
void OnTick(){
if(isNewCandle() == true){
bullEngulfingPattern();
bearEngulfingPattern();
bullTrend();
bearTrend();

//if there is a bull trend and we have found an engulfing bull candle pattern then purchase
   if(bullTrend() == true && bullEngulfingPattern() == true){
   ticket = OrderSend(Symbol(),OP_BUY,MODE_MINLOT,Ask,30,stopLossBuy,takeProfitBuy,"My order ",16384,0,clrRed);
   if(ticket < 0){ 
      Print("Ask :",Ask, "Take Profit :",takeProfit, "take profit buy: ",takeProfitBuy);
      Print("OrderSend failed with error #", GetLastError()); 
      }else Print("OrderSend placed successfully");
      
 //if there is a bear trend and we have found an engulfing bear candle pattern then sell
   if(bearTrend() == true && bearEngulfingPattern() == true){
   ticket = OrderSend(Symbol(),OP_SELL,MODE_MINLOT,Bid,30,stopLossSell,takeProfitSell,"My order ",16385,0,clrRed);
   if(ticket < 0){ 
      Print("OrderSend failed with error #", GetLastError()); 
      }else Print("OrderSend placed successfully");
}
}
}
}

/*
-------------------------------------------------------------------------------------
                                 
                                 Functions

-------------------------------------------------------------------------------------
*/

//Funtion to check for a new candle each tick
bool isNewCandle()
{
   static datetime savedCandleTime;
      if(Time[0]==savedCandleTime)
      return (false);
      else
      savedCandleTime=Time[0];
      return (true);
}



//--------------------------------------------------------------------
//               Pattern Checking Functions
//--------------------------------------------------------------------

//Function to check and see if we have a bull engulfing pattern
bool bullEngulfingPattern()
{
if((Close[1]>(Open[2])) && (Close[2] >= Open[1]))
   return (true);
   else return (false);
}

//Function to check and see if we have a bear engulfing pattern
bool bearEngulfingPattern()
{
if((Close[1]<(Open[2])) && (Close[2] >= Open[1]))
   return (true);
   else return (false);
}

//----------------------------------------------------------------------------------
//                            Trend Checking Functions
//----------------------------------------------------------------------------------

//Function to Check the last 100 candles(trendLegth) to look for a bull trend
bool bullTrend()
{
   bool retval=false;
   for(i = 1; i < trendLength; i++){
      candleValue = Close[i];
      double movingAverageValue = iMA(Symbol(), PERIOD_CURRENT, 200, 0, MODE_SMA, PRICE_CLOSE, i);
      if(movingAverageValue < candleValue)
         up++;
      else
         up = 0;
      if(up > 40)
         retval=true;
   }
   return(retval);
}

//Function to Check the last 100 candles(trendLegth) to look for a bear trend
bool bearTrend()
{
   bool retval=false;
   for(i = 1; i < trendLength; i++){
      candleValue = Close[i];
      double movingAverageValue = iMA(Symbol(), PERIOD_CURRENT, 200, 0, MODE_SMA, PRICE_CLOSE, i);
      if(movingAverageValue < candleValue){
         down++;
         }else up = 0;
            if(up > 40)
              retval=true;
   }
   return (retval);
}

//--------------------------------------------------------------------------------
//Functions to figure out what percent the the different parts of the candles are
//--------------------------------------------------------------------------------

//Functions for candle one
//---------------------------------------------------------------
double topWickOnePercent()
{
   if(Open[1] > Close[1]){
   topWickOne = (High[1] - Open[1])/totalCandleValueOne*100;
   }else if(Close[1] > Open[1]){
   topWickOne = (High[1] - Close[1])/totalCandleValueOne*100;
   }
   return(topWickOne);
}

double bodyOnePercent()
{
   if(Open[1] > Close[1]){
   bodyOne = (Open[1] - Close[1])/totalCandleValueOne*100;
   }else if(Close[1] > Open[1]){
   bodyOne = (Close[1] - Open[1])/totalCandleValueOne*100;
   }
   return(bodyOne);
}

double bottomWickOnePercent()
{
   if(Open[1] > Close[1]){
   bottomWickOne = (Close[1] - Low[1])/totalCandleValueOne*100;
   }else if(Close[1] > Open[1]){
   bottomWickOne = (Open[1] - Low[1])/totalCandleValueOne*100;
   }
   return(bottomWickOne);
}

//Functions for candle two
//---------------------------------------------------
double topWickTwoPercent()
{
   if(Open[2] > Close[2]){
   topWickTwo = (High[2] - Open[2])/totalCandleValueOne*100;
   }else if(Close[2] > Open[2]){
   topWickTwo = (High[2] - Close[2])/totalCandleValueOne*100;
   }
   return(topWickTwo);
}

double bodyTwoPercent()
{
   if(Open[2] > Close[2]){
   bodyTwo = (Open[2] - Close[2])/totalCandleValueOne*100;
   }else if(Close[2] > Open[2]){
   bodyTwo = (Close[2] - Open[2])/totalCandleValueOne*100;
   }
   return(bodyTwo);
}

double bottomWickTwoPercent()
{
   if(Open[2] > Close[2]){
   bottomWickTwo = (Close[2] - Low[2])/totalCandleValueOne*100;
   }else if(Close[2] > Open[2]){
   bottomWickTwo = (Open[2] - Low[2])/totalCandleValueOne*100;
   }
   return(bottomWickTwo);
}


//Experimental crap
//-------------------------------------------------------------------------------------------------
//Function to Check the last 100 candles(trendLegth) to look for a trend
/*bool bullTrend()
//  {
   bool retval=false;
   for(i = 1; i < trendLength; i++)
     {
      candleValue = Close[i];
      double movingAverageValue = iMA(Symbol(), PERIOD_CURRENT, 200, 0, MODE_SMA, PRICE_CLOSE, i);
      if(movingAverageValue < candleValue)
         up++;
      else
         up = 0;
      if(up > 40)
         retval=true;
     }
   return(retval);
  }
*/
 
SirFency:

I have been getting this error and I cant seem to figure out the cause.

I have been trying for the last 3 days to figure it out. I assume its because of my send order operation so I have adjusted everything I can think of. Nothing seems to stop it from appearing in my journal during backtesting.

one thing it says in the documentation is it may simply be that there is information it cannot translate. I was hoping someone could help me pinpoint the cause. I have looked through the documentation for everything related to send orders and errors. I have scoured through looking for explanations on ask and bid and and i have tried using MarketInfo() to gather data to use in order to calculate my ask and bid. I have created take profit and stop loss for both buy and sell orders. Not sure what else to try. I have done my best to try and comment my code as much as possible.

The code is supposed to identify an engulfing pattern and either buy or sell based on the trend. If there is a bull trend then buy on bull engulfing patterns if there is a bear trend then sell when there is a bear engulfing pattern.

So far not only do I get buying and selling error 130 it seems like its not obeying my if checks. it seems to buy and sell even if there is no engulfing pattern.

I appreciate you time folks.

I really am trying hard to find it on my own but I'm stumped. 


the reason u get this error is because ur OrderSend are not been setup properly . There is 2 reason that causes this error whereby 1)MODE_MINLOT 2)topLossBuy,takeProfitBuy  , as shown below ;

OrderSend(Symbol(),OP_BUY,MODE_MINLOT,Ask,30,stopLossBuy,takeProfitBuy,"My order ",16384,0,clrRed);

to overcome this problem u need to setup ur ordersend something like this ;

double lot=0.01;
ticket = OrderSend(Symbol(),OP_BUY,lot,Ask,30,Ask-(stopLoss*Point),Ask+(takeProfit*Point),"My order ",16384,0,clrRed);

regards

Cosmas

 
//Variables to store the value of the entire candle
double totalCandleValueOne = High[1]-Low[1];
double totalCandleValueTwo = High[2]-Low[2];
double totalCandleValueThree = High[3]-Low[3];
⋮
//Variables for buy and sell take profit
double takeProfit = 500;
double takeProfitBuy = Ask+(takeProfit*pips);
double takeProfitSell = Bid-(takeProfit*pips);

//variables for buy and sell stop loss
double stopLoss = 150;
double stopLossSell = Bid+(stopLoss*pips);
double stopLossBuy = Ask-(stopLoss*pips);
Global and static variables work exactly the same way in MT4/MT5/C/C++.
  1. They are initialized once on program load.
  2. They don't update unless you assign to them.
  3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5 (or MT4 with strict which you should always use.)

    MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:

    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
  4. Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
              external static variable - MQL4 programming forum
 
Thank you guys. That was killing me. Now on to my next issues.
Reason: