Please Help, how to solve undeclare token

 
I am new to MT5 and I copy a code from https://www.youtube.com/watch?v=d9-_bb58PgE and https://www.youtube.com/watch?v=PgxhNRoe4AM and It says there are errors.
//+------------------------------------------------------------------+
//|                                                     scalper2.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property description "1 M Scalper"
#property description "based on Trade pro https:youtu.be/0Q6iEmeUys"
#property strict

input int InpFastBars = 20;
input ENUM_MA_METHOD InpFastMethod = MODE_EMA;
input ENUM_APPLIED_PRICE InpFastAppliedPrice = PRICE_CLOSE;

input int InpMidBars = 50;
input ENUM_MA_METHOD InpMidMethod = MODE_EMA;
input ENUM_APPLIED_PRICE InpMidAppliedPrice = PRICE_CLOSE;

input int InpSlowBars = 100;
input ENUM_MA_METHOD InpSlowMethod = MODE_EMA;
input ENUM_APPLIED_PRICE InpSlowAppliedPrice = PRICE_CLOSE;

input double InpProfitRatio = 1.5;

input double InpVolume = 0.01;
input string InpTradeComment = "M1 Scalper"

int SkipTrade = -1;

int HandleFast;
int HandleMid;
int HandleSlow;
int HandleFractal;

double IndicatorBuffer[];

#include <Trade/Trade.mqh>
CTrade Trade;
input int InpMagic = 222222;

int OnInit(){
   
   if(!CheckInputs() ) return(INIT_PARAMETERS_INCORRECT);
   
   HandleFast = iMA(Symbol(), Period(), InpFastBars, 0, InpFastMethod, InpFastAppliedPrice);
   HandleFast = iMA(Symbol(), Period(), InpMidBars, 0, InpMidMethod, InpMidAppliedPrice);
   HandleFast = iMA(Symbol(), Period(), InpSlowBars, 0, InpSlowMethod, InpSlowAppliedPrice);
   HandleFractal = iFractals(Symbol(), Period());
   
   if(HandleFast == INVALID_HANDLE || HandleMid == INVALID_HANDLE || 
      HandleSlow == INVALID_HANDLE || HandleFractal == INVALID_HANDLE) {
      Print("Failed to creat indicator handle");
      return(INIT_FAILED);
      }
   
   ArraySetAsSeries(IndicatorBuffer, true);
   Trade.SetExpertMagicNumber(InpMagic);
   
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason){
   IndicatorRelease(HandleFast);
   IndicatorRelease(HandleMid);
   IndicatorRelease(HandleSlow);
   IndicatorRelease(HandleFractal);
}

void OnTick() {

   if(!NewBar() ) return;
   
   for(int i = PositionsTotal() - 1; i>= 0; i--) {
      ulong ticket = PositionGetTicket( i );
      if(!PositionSelectByTicket(ticket) ) continue;
      if(PositionGetString(POSITION_SYMBOL) != Symbol() )continue;
      if(PositionGetInteger(POSITION_MAGIC) != InpMagic) continue;
      return;
   }
   

   int fractalBar = 3;
   int bar =1;

   int copyBars = fractalBar +1;
   
   if(CopyBuffer(HandleFast, 0, 0, copyBars, IndicatorBuffer ) < copyBars ) return;
   double fast = IndicatorBuffer[bar];
   double fastF = IndicatorBuffer[fractalBar];

   if(CopyBuffer(HandleMid, 0, 0, copyBars, IndicatorBuffer ) < copyBars ) return;
   double mid = IndicatorBuffer[bar];
   double midF = IndicatorBuffer[fractalBar];

   if(CopyBuffer(HandleSlow, 0, 0, copyBars, IndicatorBuffer ) < copyBars ) return;
   double slow = IndicatorBuffer[bar];
   double slowF = IndicatorBuffer[fractalBar];

   if(CopyBuffer(HandleFractal, UPPER_LINE, 0, copyBars, IndicatorBuffer) < copyBars) return;
   double fractalHi = IndicatorBuffer[fractalBar];
   if(CopyBuffer(HandleFractal, LOWER_LINE, 0, copyBars, IndicatorBuffer) < copyBars) return;
   double fractalLo = IndicatorBuffer[fractalBar];

   double close = iClose(Symbol(), Period(), bar );

   double sl = 0;

   if(fast > mid && mid > slow) {
      if(close < slow) {
         SkipTrade = ORDER_TYPE_BUY;
      }
      else if(fastF > midF && midF > slowF) {
         if(fractalLo != EMPTY_VALUE && fractalLo > slowF && fractalLo < fastF) {
            if(SkipTrade != ORDER_TYPE_BUY) {
            sl = (fractalLo < midF) ? slow : mid;
            OpenTrade(ORDER_TYPE_BUY, sl);
            }
            SkipTrade = -1;
            return;
         }
      }
   }

   if (fast < mid && mid < slow) {
      if(close > slow) {
         SkipTrade = ORDER_TYPE_SELL;
      }
      else if(fastF < midF && midF < slowF) {
         if(fractalLo != EMPTY_VALUE && fractalLo < slowF && fractalLo > fastF) {
            if(SkipTrade != ORDER_TYPE_BUY) {
            sl = (fractalHi > midF) ? slow : mid;
            OpenTrade(ORDER_TYPE_SELL, sl);
        }
         SkipTrade = -1;
         return;
      }
   }
}

}
bool NewBar(){

   datetime currentTime = iTime(Symbol(), Period(),0);
   static datetime previousTime =
      0;
   if (currentTime == previousTime) return (false);
   previousTime = currentTime;
   return (true);
}



bool CheckInputs() {

   bool result = true;
   if(InpFastBars >= InpMidBars || InpMidBars >= InpSlowBars) {
      Print("Fast bars must be < midbars < slow bars");
      result = false;
   }

   return(result);

}

void OpenTrade(ENUM_ORDER_TYPE type, double sl) {

   double price = (type == ORDER_TYPE_BUY ) ? SymbolInfoDouble(Symbol(),SYMBOL_ASK)
                                            : SymbolInfoDouble(Symbol(), SYMBOL_BID);
   double tp = price + ( (price - sl) * InpProfitRatio );
   Trade.PositionOpen(Symbol(), type, InpVolume, price, sl, tp, InpTradeComment);
   
   return;
}





- YouTube
  • www.youtube.com
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
 
Here are the errors, please help.
[Deleted]  
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
[Deleted]  

You are missing a semicolon at the end of line 28.


Please take some time to learn to code and to better understand the compiler errors and their possible causes. Don't just copy/paste code from YouTube videos.

input double InpVolume = 0.01;
input string InpTradeComment = "M1 Scalper"; // <-- Missing semicolon

int SkipTrade = -1;
 
Fernando Carreiro #: You are missing a semicolon at the end of line 28. Please take some time to learn to code and to better understand the compiler errors and their possible causes. Don't just copy/paste code from YouTube videos.

Thank you very much!!!

There is no error now.

I will definitely spend time on learning mql5.

By the way, why it doesn't open any order in the backtest?



//+------------------------------------------------------------------+
//|                                                     scalper2.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property description "1 M Scalper"
#property description "based on Trade pro https:youtu.be/0Q6iEmeUys"
#property strict

input int InpFastBars = 20;
input ENUM_MA_METHOD InpFastMethod = MODE_EMA;
input ENUM_APPLIED_PRICE InpFastAppliedPrice = PRICE_CLOSE;

input int InpMidBars = 50;
input ENUM_MA_METHOD InpMidMethod = MODE_EMA;
input ENUM_APPLIED_PRICE InpMidAppliedPrice = PRICE_CLOSE;

input int InpSlowBars = 100;
input ENUM_MA_METHOD InpSlowMethod = MODE_EMA;
input ENUM_APPLIED_PRICE InpSlowAppliedPrice = PRICE_CLOSE;

input double InpProfitRatio = 1.5;

input double InpVolume = 0.01;
input string InpTradeComment = "M1 Scalper";

int SkipTrade = -1;

int HandleFast;
int HandleMid;
int HandleSlow;
int HandleFractal;

double IndicatorBuffer[];

#include <Trade/Trade.mqh>
CTrade Trade;
input int InpMagic = 12457;

int OnInit(){
   
   if(!CheckInputs() ) return(INIT_PARAMETERS_INCORRECT);
   
   HandleFast = iMA(Symbol(), Period(), InpFastBars, 0, InpFastMethod, InpFastAppliedPrice);
   HandleMid = iMA(Symbol(), Period(), InpMidBars, 0, InpMidMethod, InpMidAppliedPrice);
   HandleSlow = iMA(Symbol(), Period(), InpSlowBars, 0, InpSlowMethod, InpSlowAppliedPrice);
   HandleFractal = iFractals(Symbol(), Period());
   
   if(HandleFast == INVALID_HANDLE || HandleMid == INVALID_HANDLE || 
      HandleSlow == INVALID_HANDLE || HandleFractal == INVALID_HANDLE) {
      Print("Failed to creat indicator handle");
      return(INIT_FAILED);
      }
   
   ArraySetAsSeries(IndicatorBuffer, true);
   Trade.SetExpertMagicNumber(InpMagic);
   
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason){
   IndicatorRelease(HandleFast);
   IndicatorRelease(HandleMid);
   IndicatorRelease(HandleSlow);
   IndicatorRelease(HandleFractal);
}

void OnTick() {

   if(!NewBar() ) return;
   
   for(int i = PositionsTotal() - 1; i>= 0; i--) {
      ulong ticket = PositionGetTicket( i );
      if(!PositionSelectByTicket(ticket) ) continue;
      if(PositionGetString(POSITION_SYMBOL) != Symbol() )continue;
      if(PositionGetInteger(POSITION_MAGIC) != InpMagic) continue;
      return;
   }
   

   int fractalBar = 3;
   int bar =1;

   int copyBars = fractalBar +1;
   
   if(CopyBuffer(HandleFast, 0, 0, copyBars, IndicatorBuffer ) < copyBars ) return;
   double fast = IndicatorBuffer[bar];
   double fastF = IndicatorBuffer[fractalBar];

   if(CopyBuffer(HandleMid, 0, 0, copyBars, IndicatorBuffer ) < copyBars ) return;
   double mid = IndicatorBuffer[bar];
   double midF = IndicatorBuffer[fractalBar];

   if(CopyBuffer(HandleSlow, 0, 0, copyBars, IndicatorBuffer ) < copyBars ) return;
   double slow = IndicatorBuffer[bar];
   double slowF = IndicatorBuffer[fractalBar];

   if(CopyBuffer(HandleFractal, UPPER_LINE, 0, copyBars, IndicatorBuffer) < copyBars) return;
   double fractalHi = IndicatorBuffer[fractalBar];
   if(CopyBuffer(HandleFractal, LOWER_LINE, 0, copyBars, IndicatorBuffer) < copyBars) return;
   double fractalLo = IndicatorBuffer[fractalBar];

   double close = iClose(Symbol(), Period(), bar );

   double sl = 0;

   if(fast > mid && mid > slow) {
      if(close < slow) {
         SkipTrade = ORDER_TYPE_BUY;
      }
      else if(fastF > midF && midF > slowF) {
         if(fractalLo != EMPTY_VALUE && fractalLo > slowF && fractalLo < fastF) {
            if(SkipTrade != ORDER_TYPE_BUY) {
            sl = (fractalLo < midF) ? slow : mid;
            OpenTrade(ORDER_TYPE_BUY, sl);
            }
            SkipTrade = -1;
            return;
         }
      }
   }

   if (fast < mid && mid < slow) {
      if(close > slow) {
         SkipTrade = ORDER_TYPE_SELL;
      }
      else if(fastF < midF && midF < slowF) {
         if(fractalLo != EMPTY_VALUE && fractalLo < slowF && fractalLo > fastF) {
            if(SkipTrade != ORDER_TYPE_BUY) {
            sl = (fractalHi > midF) ? slow : mid;
            OpenTrade(ORDER_TYPE_SELL, sl);
        }
         SkipTrade = -1;
         return;
      }
   }
}

}
bool NewBar(){

   datetime currentTime = iTime(Symbol(), Period(),0);
   static datetime previousTime =
      0;
   if (currentTime == previousTime) return (false);
   previousTime = currentTime;
   return (true);
}



bool CheckInputs() {

   bool result = true;
   if(InpFastBars >= InpMidBars || InpMidBars >= InpSlowBars) {
      Print("Fast bars must be < midbars < slow bars");
      result = false;
   }

   return(result);

}

void OpenTrade(ENUM_ORDER_TYPE type, double sl) {

   double price = (type == ORDER_TYPE_BUY ) ? SymbolInfoDouble(Symbol(),SYMBOL_ASK)
                                            : SymbolInfoDouble(Symbol(), SYMBOL_BID);
   double tp = price + ( (price - sl) * InpProfitRatio );
   Trade.PositionOpen(Symbol(), type, InpVolume, price, sl, tp, InpTradeComment);
   
   return;
}
It is a 1 minute scalping strategy and the MetaEditor shows no error, but it didn't place any order. Is there any mistake at ordering part?
 
Nevermind, I solved it my self, but still thank you for helping me.