im newbee here, i ran this code and keep saying "erorr 4051", idk whats wrong with this code, i already google it, and still confuse

 
//+------------------------------------------------------------------+
//|                                               ema 50 200 ATR.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#include  <CustomFunctions01.mqh>

int magicNB = 55555;
input int lots = 0.1;
int openOrderID;
double risk = 2 *(iATR(NULL,0,14,0));
double reward = 1.5 * risk;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
    double signalbuy = (iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,0)>iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0))&&
                       (Close[1]<iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1))&&
                       (Close[0]>iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,0)); 
    
    
    
    double signalsell = (iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,0)<iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0))&&
                        (Close[1]>iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1))&&
                        (Close[0]<iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,0));
                        
    if(!CheckIfOpenOrdersByMagicNB(magicNB))//if no open orders try to enter new position
    {
      if(signalbuy == true)
      {   
         double SL = Ask - risk*GetPipValue();
         double TP = Ask + reward*GetPipValue();
         Print("Entry Price buy = " + Ask);
         Print("Stop Loss Price = " + SL);
         Print("Take Profit Price = " + TP);
         
         openOrderID = OrderSend(NULL,OP_BUY,lots,Ask,10,SL,TP,NULL,magicNB);
         if(openOrderID < 0) Alert("order rejected. Order error: " + GetLastError());
       }
       else if (signalsell == true)
       {
         double SL = Bid +risk*GetPipValue();
         double TP = Bid - reward*GetPipValue();
         Print("Entry Price sell= " + Bid);
         Print("Stop Loss Price = " + SL);
         Print("Take Profit Price = " + TP);
         
         openOrderID = OrderSend(NULL,OP_SELL,lots,Bid,10,SL,TP,NULL,magicNB);
         if(openOrderID < 0) Alert("order rejected. Order error: " + GetLastError());
       }
     }
  }
//+------------------------------------------------------------------+

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2021.03.09
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
4051kucing amuk:
//+------------------------------------------------------------------+
//|                                               ema 50 200 ATR.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#include  <CustomFunctions01.mqh>

int magicNB = 55555;
input int lots = 0.1;
int openOrderID;
double risk = 2 *(iATR(NULL,0,14,0));
double reward = 1.5 * risk;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
    double signalbuy = (iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,0)>iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0))&&
                       (Close[1]<iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1))&&
                       (Close[0]>iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,0)); 
    
    
    
    double signalsell = (iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,0)<iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0))&&
                        (Close[1]>iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1))&&
                        (Close[0]<iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,0));
                        
    if(!CheckIfOpenOrdersByMagicNB(magicNB))//if no open orders try to enter new position
    {
      if(signalbuy == true)
      {   
         double SL = Ask - risk*GetPipValue();
         double TP = Ask + reward*GetPipValue();
         Print("Entry Price buy = " + Ask);
         Print("Stop Loss Price = " + SL);
         Print("Take Profit Price = " + TP);
         
         openOrderID = OrderSend(NULL,OP_BUY,lots,Ask,10,SL,TP,NULL,magicNB);
         if(openOrderID < 0) Alert("order rejected. Order error: " + GetLastError());
       }
       else if (signalsell == true)
       {
         double SL = Bid +risk*GetPipValue();
         double TP = Bid - reward*GetPipValue();
         Print("Entry Price sell= " + Bid);
         Print("Stop Loss Price = " + SL);
         Print("Take Profit Price = " + TP);
         
         openOrderID = OrderSend(NULL,OP_SELL,lots,Bid,10,SL,TP,NULL,magicNB);
         if(openOrderID < 0) Alert("order rejected. Order error: " + GetLastError());
       }
     }
  }
//+------------------------------------------------------------------+

Difficult to detect without the CustomFunctions01.mqh file. The 4051 error code originates from the parameters of the function. You can view the Runtime error file in the Help file.

Files:
4051.PNG  7 kb
 
kucing amuk:

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

Reason: