undeclared identifier, help needed

 

Firsr of all hello everyone.

I'm form Poland and I'm new in this topic, so please just be gentle;)

Anyway, I'v started to learn how to build EA few days ago. So I'v started to read theory and I thought that practice from the beginning  would give me some benefits too. I understand basic instructions but I'm still in very beginning of this trip.

I checked some videos on youtube and found this:

https://www.youtube.com/watch?v=H0GjjPl1Qjw

So after rewriting all the code like in the movie I have some errors, and although it should just work i doesn't. I'm checking and checking and can't find anything...

The errror are:

'sl' - undeclared identifier    Ichiyou.mq5    189    41

'entry' - undeclared identifier    Ichiyou.mq5    190    33

'sl' - undeclared identifier    Ichiyou.mq5    190    39

'entry' - undeclared identifier    Ichiyou.mq5    192    30

'sl' - undeclared identifier    Ichiyou.mq5    192    36


in the code it seems that everythig is declared as it should...but..


//+------------------------------------------------------------------+
//|                                                      Ichiyou.mq5 |
//|                               Copyright 2024, xxxxxxxxxxxxxxxxxx |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, Sebastian Szewczyk"
#property link      "https://www.mql5.com"
#property version   "1.00"
/*+------------------------------------------------------------------+

Strategy Rules
   BUY:
   - Price moves from Below the Cloud to Up
   - Cloud in the future turns Green (SenkouSpanA > SenkouSpanB)
   - Tenkansen is above KijunSen
   - ChikouSpan is above Cloud 26 bars behind (is above SenkouSpanA and B 26 bars behind)
   - Stoploss below KijunSen
   - Take Profit 2x risk

   SELL:
   - Same as Buy condition in Reverse
/+------------------------------------------------------------------+*/


#include <Trade\Trade.mqh>
CTrade         trade;

#include <Indicators\Trend.mqh>
CiIchimoku ichimoku;

// User Input
input ENUM_TIMEFRAMES   Timeframe   = PERIOD_CURRENT;  // Timeframe for the EA
input ulong             InpMagic    = 8234;            // Magic Number for EA
input double            RiskPercent = 2;               // Risk per Trde (% of Capital)

// Bool Conditions
bool     FutureCloudGreen = false,  FutureCloudRed = false;
bool     PriceaboveCloud = false,   PricebelowCloud = false;
bool     TenkanaboveKijun = false,  TenkanbelowKijun = false;
bool     ChikouaboveCloud = false,  ChikoubelowCloud = false;


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {

   trade.SetExpertMagicNumber(InpMagic);

   ichimoku = new CiIchimoku();
   ichimoku.Create(_Symbol,Timeframe,9,26,52);


   return (INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {


  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {

   if(!IsNewBar())
      return;

   ichimoku.Refresh(-1);

   double SpanAx1 = ichimoku.SenkouSpanA(1);
   double SpanAx2 = ichimoku.SenkouSpanA(2);
   double SpanAx26 = ichimoku.SenkouSpanA(26);
   double SpanAf26 = ichimoku.SenkouSpanA(-26);

   double SpanBx1 = ichimoku.SenkouSpanB(1);
   double SpanBx2 = ichimoku.SenkouSpanB(2);
   double SpanBx26 = ichimoku.SenkouSpanB(26);
   double SpanBf26 = ichimoku.SenkouSpanB(-26);

   double Tenkan  = ichimoku.TenkanSen(1);
   double Kijun   = ichimoku.KijunSen(1);
   double Chikou  = ichimoku.ChinkouSpan(26);

   double Closex1 = iClose(_Symbol,Timeframe,1);
   double Closex2 = iClose(_Symbol,Timeframe,2);

// Chcecking Conditions

// Future Cloud is Green or Red
   if(SpanAf26>SpanBf26)
     {
      FutureCloudGreen=true;
      FutureCloudRed=false;
     }
   if(SpanBf26>SpanAf26)
     {
      FutureCloudGreen=false;
      FutureCloudRed=true;
     }

// Exit Cloud Up OR Exit Cloud Below
   if(PriceaboveCloud==false && (Closex2<SpanAx2 || Closex2<SpanBx2) && Closex1>SpanAx1 && Closex1>SpanBx1)
     {
      PriceaboveCloud=true;
      PricebelowCloud=false;
     }
   if(PriceaboveCloud==false && (Closex2>SpanAx2 || Closex2<SpanBx2) && Closex1<SpanAx1 && Closex1<SpanBx1)
     {
      PriceaboveCloud=false;
      PricebelowCloud=true;
     }

// Tenkan above Kijun or Tenkan below Kijun
   if(Tenkan>Kijun)
     {
      TenkanaboveKijun=true;
      TenkanbelowKijun=false;
     }
   if(Tenkan<Kijun)
     {
      TenkanaboveKijun=false;
      TenkanbelowKijun=true;
     }

// Chikou above or below Cloud 26 bars back
   if(Chikou>SpanAx26 && Chikou>SpanBx26)
     {
      ChikouaboveCloud = true;
      ChikoubelowCloud = false;
     }
   if(Chikou<SpanAx26 && Chikou<SpanBx26)
     {
      ChikouaboveCloud = false;
      ChikoubelowCloud = true;
     }

// Close of price is in the Cloud
   if(SpanAx1>SpanBx1 && Closex1>SpanBx1 && Closex1<SpanAx1)
     {
      PriceaboveCloud=false;
      PricebelowCloud=false;
     }
   if(SpanBx1>SpanAx1 && Closex1>SpanAx1 && Closex1<SpanBx1)
     {
      PriceaboveCloud=false;
      PricebelowCloud=false;
     }

// Chikou is in the Cloud
   if(SpanAx26>SpanBx26 && Chikou>SpanBx26 && Chikou<SpanAx26)
     {
      ChikouaboveCloud=false;
      ChikoubelowCloud=false;
     }
   if(SpanBx26>SpanAx26 && Chikou>SpanAx26 && Chikou<SpanBx26)
     {
      ChikouaboveCloud=false;
      ChikoubelowCloud=false;
     }


   Comment("\n PriceaboveCloud: "+PriceaboveCloud+
           "\n Tenkan>Kijun: "+TenkanaboveKijun+
           "\n ChikouaboveCloud: "+ChikouaboveCloud+
           "\n FutureCloudGreen: "+FutureCloudGreen+
           "\n \n"+
           "\n PricebelowCloud: "+PricebelowCloud+
           "\n Tenkan<Kijun: "+PricebelowCloud+
           "\n ChikoubelowCloud: "+ChikoubelowCloud+
           "\n FutureCloudRed: "+FutureCloudRed+
          );

// Buy Condition
   if(FutureCloudGreen==true && PriceaboveCloud==true && TenkanaboveKijun==true && ChikouaboveCloud==true) 
     {
     
      double entry   = Closex1;
      double sl      = Kijun - 50*_Point;
      double tp      = entry + (entry - sl)*2;
      double lots    = calcLots(entry-sl);

      trade.Buy(lots,_Symbol,entry,sl,tp,"Zaidi Brothers");
      SetAllConditionstofalse();
     }

   if(FutureCloudRed==true && PricebelowCloud==true && TenkanbelowKijun==true&& ChikoubelowCloud==true)
     {
      double entry   = Closex1;
      double sl      = Kijun + 50*_Point;
      double tp      = entry - (entry - sl)*2;
      double lots    = calcLots(entry-sl);

      trade.Sell(lots,_Symbol,entry,sl,tp,"Zaidi Brothers");
      SetAllConditionstofalse();
     }
 }


//+------------------------------------------------------------------+

   bool IsNewBar()
     { 
      static datetime previousTime = 0;
      datetime currentTime = iTime(_Symbol,PERIOD_CURRENT,0);
      if(previousTime!=currentTime)
        {
         previousTime=currentTime;
         return true;
        }
      return false;
     }

   double calcLots(double slPoints)
     {
      double risk = AccountInfoDouble(ACCOUNT_BALANCE) * RiskPercent / 100;

      double ticksize = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
      double tickvalue = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE);
      double lotstep = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);

      double moneyPerLotstep = slPoints / ticksize * tickvalue * lotstep;
      double lots = MathFloor(risk / moneyPerLotstep) * lotstep;

      double minvolume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
      double maxvolume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);

      if(maxvolume!=0)
         lots = MathMin(lots,maxvolume);
      if(minvolume!=0)
         lots = MathMax(lots, minvolume);

      lots = NormalizeDouble(lots,2);
      return lots;
     }

   void SetAllConditionstofalse()
     {
      FutureCloudGreen = false;
      FutureCloudRed = false;
      PriceaboveCloud = false;
      PricebelowCloud = false;
      TenkanaboveKijun = false;
      TenkanbelowKijun = false;
      ChikouaboveCloud = false;
      ChikoubelowCloud = false;
     }
//+------------------------------------------------------------------+


I would be grateful for your help.

Sebastian

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2024.09.02
  • 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
 
sebasbox:

The errror are:

'sl' - undeclared identifier    Ichiyou.mq5    189    41

'entry' - undeclared identifier    Ichiyou.mq5    190    33

'sl' - undeclared identifier    Ichiyou.mq5    190    39

'entry' - undeclared identifier    Ichiyou.mq5    192    30

'sl' - undeclared identifier    Ichiyou.mq5    192    36


in the code it seems that everythig is declared as it should...but..


First you need to fix the other errors you have not listed..  then things will become clearer...

 
Paul Anscombe #:
You should also use #property strict

#property strict does not affect anything in MQL5

 
Vladislav Boyko #:

#property strict does not affect anything in MQL5

yes of course, I always develop one code for both mql4 and mql5, hence I always put it in and forget its relevence to MT4 :) it never hurts to be consistent anyway :)

 
Thank you for replays guys, but unfortunately I still don't know how to fix it. I need to read more, because right now it seem to be black magic for me..
 
ok, fixed, once again thank you for the replays
 

here you are, this should work:

#include <Trade\Trade.mqh>

   CTrade         trade;

 

 #include <Indicators\Trend.mqh>

 CiIchimoku ichimoku;

 

 //Useer Input

 input ENUM_TIMEFRAMES  Timeframe   = PERIOD_CURRENT;

 input ulong   InpMagic = 8234;

 input double  RiskPercent =2;

 

 

 bool FutureCloudGreen  =false,  FutureCloudRed  =false;

 bool PriceaboveCloud  =false,  PricebelowCloud  =false;

 bool TenkanaboveKijun  =false,  TenkanbelowKijun  =false;

 bool ChikouaboveCloud  =false,  ChikoubelowCloud  =false;

 

 int OnInit(){

 

   trade.SetExpertMagicNumber(InpMagic);

   

   ichimoku = new CiIchimoku();

   ichimoku.Create(_Symbol,Timeframe,9,26,52);

   

   return(INIT_SUCCEEDED);

   }

 

 void OnDeinit(const int reason){

 

 }

 

 void OnTick(){

 

 if(!IsNewBar()) return;

 ichimoku.Refresh(-1);

 

 double SpanAx1 = ichimoku.SenkouSpanA(1);

 double SpanAx2 = ichimoku.SenkouSpanA(2);

 double SpanAx26 = ichimoku.SenkouSpanA(26);

 double SpanAf26 = ichimoku.SenkouSpanA(-26);

 

  double SpanBx1 = ichimoku.SenkouSpanB(1);

 double SpanBx2 = ichimoku.SenkouSpanB(2);

 double SpanBx26 = ichimoku.SenkouSpanB(26);

 double SpanBf26 = ichimoku.SenkouSpanB(-26);

 

 double Tenkan = ichimoku.TenkanSen(1);

 double Kijun = ichimoku.KijunSen(1);

 double Chikou = ichimoku.ChinkouSpan(26);

 

 double Closex1 = iClose(_Symbol,Timeframe,1);

 double Closex2 = iClose(_Symbol,Timeframe,2);

 

 //Checking Conditions

 if(SpanAf26>SpanBf26){

 FutureCloudGreen=true;

 FutureCloudRed=false;}

 

 if(SpanBf26>SpanAf26){

 FutureCloudGreen=false;

 FutureCloudRed=true;}

 

 //Exit Cloud

 if(PriceaboveCloud==false && (Closex2<SpanAx2 || Closex2<SpanBx2) && Closex1>SpanAx1 && Closex1>SpanBx1){

 PriceaboveCloud=true;

 PricebelowCloud=false;}

 

 if(PricebelowCloud==false && (Closex2>SpanAx2 || Closex2>SpanBx2) && Closex1<SpanAx1 && Closex1<SpanBx1){

 PriceaboveCloud=false;

 PricebelowCloud=true;}

 

 //Tenkan

 if(Tenkan>Kijun){

 TenkanaboveKijun=true;

 TenkanbelowKijun=false;}

 

  if(Tenkan<Kijun){

 TenkanaboveKijun=false;

 TenkanbelowKijun=true;}

 

 

 //Chikou

 

 if(Chikou>SpanAx26 && Chikou>SpanBx26){

 ChikouaboveCloud=true;

 ChikoubelowCloud=false;}

 

 if(Chikou<SpanAx26 && Chikou<SpanBx26){

 ChikouaboveCloud=false;

 ChikoubelowCloud=true;}

 

 //Price in the cloud

 if(SpanAx1>SpanBx1 && Closex1>SpanBx1 && Closex1<SpanAx1){

 PriceaboveCloud=false;

 PricebelowCloud=false;}

 

 if(SpanBx1>SpanAx1 && Closex1>SpanAx1 && Closex1<SpanBx1){

 PriceaboveCloud=false;

 PricebelowCloud=false;}

 

 //Chikou in the cloud

 if(SpanAx26>SpanBx26 && Chikou>SpanBx26 && Chikou<SpanAx26){

 ChikouaboveCloud=false;

 ChikoubelowCloud=false;}

 

 if(SpanBx26>SpanAx26 && Chikou>SpanAx26 && Chikou<SpanBx26){

 ChikouaboveCloud=false;

 ChikoubelowCloud=false;}

 

Comment("\n FutureCloudRed:",FutureCloudRed,

"\n PricebelowCloud:",PricebelowCloud,

"\n TenkanbelowKijun:",TenkanbelowKijun,

"\n ChikouaboveCloud:",ChikouaboveCloud); 

 //Buy Condition

 if(FutureCloudGreen==true && PriceaboveCloud==true && TenkanaboveKijun==true && ChikouaboveCloud==true){

 double entry  = Closex1;

 double sl = Kijun - 50*_Point;

 double tp = entry + (entry - sl)*2;

 double lots = calcLots(entry - sl);

 

 trade.Buy(lots,_Symbol,entry,sl,tp,"Buy");

 SetAllConditionstofalse();

 }

 

  //Sell Condition

     if(FutureCloudRed==true && PricebelowCloud==true && TenkanbelowKijun==true&& ChikoubelowCloud==true)

     {

      double entry   = Closex1;

      double sl      = Kijun + 50*_Point;

      double tp      = entry - (sl - entry)*2;

      double lots    = calcLots(sl - entry);


      trade.Sell(lots,_Symbol,entry,sl,tp,"Sell");

      SetAllConditionstofalse();

     }

  

 

 }

 //----------------------------------------------------------

 

 bool IsNewBar(){

 static datetime previousTime = 0;

 datetime currentTime = iTime(_Symbol,PERIOD_CURRENT,0);

 if(previousTime!=currentTime){

 previousTime=currentTime;

 return true;

 }

 return false;

 }

 

 double calcLots(double slPoints){

 double risk = AccountInfoDouble(ACCOUNT_BALANCE) * RiskPercent/100;

 

 double ticksize = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE); 

 double tickvalue = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE); 

 double lotstep = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);

 

 double moneyPerLotstep = slPoints / ticksize * tickvalue * lotstep;

 double lots = MathFloor(risk / moneyPerLotstep) * lotstep;

 

 double minvolume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN); 

 double maxvolume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX); 

 

 if(maxvolume!=0) lots = MathMin(lots,maxvolume);

 if(minvolume!=0) lots = MathMax(lots,minvolume);

 

 lots = NormalizeDouble(lots,2);

 

 return lots;

 }

 

  void SetAllConditionstofalse()

     {

      FutureCloudGreen = false;

      FutureCloudRed = false;

      PriceaboveCloud = false;

      PricebelowCloud = false;

      TenkanaboveKijun = false;

      TenkanbelowKijun = false;

      ChikouaboveCloud = false;

      ChikoubelowCloud = false;

     }
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2024.09.06
  • 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
 
any success with the strategy?