Help: Back testing Errors on Expert Strategy

 

Hello, sorry I am brand new to MQL4 and am running into some errors. I am coding a simple Bollinger Band strategy that will go back and forth in buy and sell positions. I think my problem is in how I am telling it to open buy and sell orders.

My Code:

int length = 11;
int mult = 2;

int OnInit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double basis = iMA(NULL,0,length,0,MODE_SMA,PRICE_CLOSE,0);
   double stdev = iStdDev(NULL,0,length,0,MODE_EMA,PRICE_CLOSE,0);
   double dev = mult * stdev;
   double upper = basis + dev;
   double lower = basis - dev;
   double ask = Ask;
   double shares = 10; // 1000/open[0]  1000/bid ?
   double stoploss = ask - ask*.0071;
   double takeprofit = ask + ask*.0041;
   
   if( Close[0] > lower)
   {
      order = OrderSend(NULL,OP_BUY,shares,Ask,0,stoploss,takeprofit,NULL,0,0,NULL);
   }
   else if (Close[0] < upper)
   {
      order = OrderSend(NULL,OP_SELL,shares,Ask,0,stoploss,takeprofit,NULL,0,0,NULL);
   }
   
  }

These are the errors I am getting when I run the backtest (picture attached). My demo account has $10000 USD in it.

Any help is appreciated. Thanks!

Bollinger Bands ®
Bollinger Bands ®
  • www.mql5.com
Bollinger Bands ® technical indicator (BB) is similar to Envelopes. The only difference is that the bands of Envelopes are plotted a fixed distance (%) away from the moving average, while the Bollinger Bands are plotted a certain number of standard deviations away from it. Standard deviation is a measure of volatility, therefore Bollinger Bands...
Files:
Capture.JPG  155 kb
 
  1. Colton: Hello, sorry I am brand new to MQL4

    Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.


  2. order = OrderSend(NULL,OP_BUY,shares,Ask,0,stoploss,takeprofit,NULL,0,0,NULL);

    Be careful with NULL.

    1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
    2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
    5. Cloud Protector Bug? - MQL4 programming forum 2020.07.25

  3. Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

Reason: