Keltner_Channel_Counter Expert Advisor

 
//+------------------------------------------------------------------+
//|                                      Keltner_Channel_Counter.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"//+------------------------------------------------------------------+
//|                              Keltner_Channels Expert Advisor.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

//Importing function libraries
 "(#include<Trade.mqh>)"
 "(#include<Risk_Management.mqh>)"
 "(#include<Trade_Manager.mqh>)"

//EA general input parameters
input int MA_Period1 = 15; //First Keltner Channel Period
input int MA_Period2 = 90; //Second Keltner Channel Peiod

//General input Parameters
input string Comments = "KCC"; //EA Order Comment
input int StopLoss = 10; //StopLoss in pips
input int TakeProfit = 145; //TakeProfit in Pips
input int EA_Magic = 4356; //EA_Magic number
input double Lotsize = 0.05; //Lotsize
input int Slippage = 50; //Slippage

//Breakeven input variables
input bool UseBreakEven = true; //Use Break Even
input int WhenToBreak = 10; //When to break even in pips?
input int BreakBy = 15; //Break Even by how many pips?

//Trailing Stop input variables
input bool UseTrailing = true; //Use Trailing Stop
input int WhenToTrail = 25; // When to start Trailing in pips?
input int TrailBy = 55; //Trailing Stop in Pips

//Money Management input variables
input bool Used_Money_Management = true;
input double ENUM_FUNDS_TYPE; //Funds to Use for Lot Calculation
input double ENUM_MM; //Type of Money Management
input double ATR_Multiplier = 1 ; //ATR Multiplier
input double Fixed_Balance = 1000; //Fixed Balance in account currency
input double Fixed_RiskMoney = 20; //Fixed Risk Money
input double Percentage_risk = 5; //Percentage of Funds to Risk

//EA intermediate calculations variables
double STP, TKP;
ulong LastBars = 0;
double Ask, Bid;

//Indicator handles
int KCHandle1;
int KCHandle2;

//Indicator Buffers
double KC_Upper1[];
double KC_Lower1[];
double KC_Middle1[];
double KC_Upper2[];
double KC_Lower2[];
double KC_Middle2[];
double ClosePrice[];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {
   //....Initializing the Trade Class Object
   int Ctrade;
   int deviation_points;
  int EA_Magic_Number;
   
//.....Initializing the Indicator Handles
   KCHandle1 = iCustom(_Symbol,PERIOD_CURRENT,"Keltner_Channel", MA_Period1);
   KCHandle2 = iCustom(_Symbol, PERIOD_CURRENT, "Keltner_Channel", MA_Period2);
   
//Convert the Pips value into Point value
   STP = StopLoss*_Point*10;
   TKP = TakeProfit*_Point* 10;
   
//...Resizing the Close Price array
   ArrayResize(ClosePrice, 3);
        return(INIT_SUCCEEDED);
         { 
     {
   }
     
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
   void OnDeinit(const int reason)
    { 
      double delete_Trade;
       }
 //+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
   void OnTick(){                        
     
      //---Check if we are able to trade
      if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) || !TerminalInfoInteger(TERMINAL_CONNECTED))
     {
     Alert("Terminal not connected or Trading not allowed!");
     }
    }
     
//...Check if we have a new bar
   ulong bars = Bars(_Symbol, PERIOD_CURRENT);
                if(LastBars != bars)
     {
      LastBars = bars;
          return;
        }
     
     //...Obtaining Ask price and Bid Price   Ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
         Bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
    //...Obtaining the Closing Price of the Previous Candlestick
         MqlRates rates[];
         
//Reversing the ordering of information in our Arrays
         ArraySetAsSeries(KC_Upper1, true);
         ArraySetAsSeries(KC_Upper2, true);
         ArraySetAsSeries(KC_Lower1, true);
         ArraySetAsSeries(KC_Lower2, true);
         ArraySetAsSeries(KC_Middle1, true);
         ArraySetAsSeries(KC_Middle2, true);
         ArraySetAsSeries(rates, true);
         ArraySetAsSeries(ClosePrice, true);
         
//...Checking and Copying Prices into the Rates Object
         if(CopyRates(Symbol(), PERIOD_CURRENT, 0, 3, rates) != 3)
         {
           Print("Error Copying Price Data", GetLastError());
         return;
        }
        
      //Copying price data from the Rates Object to the Close Price Array
      for(int i = 0; i < 3; i++)
     {
      ClosePrice[i]= rates[i].close;
        }
      //Checking and Copying  Indicator Values
      if(CopyBuffer(KCHandle1, 2, 0, 3, KC_Lower1) != 3 || CopyBuffer(KCHandle1, 0, 0, 3, KC_Upper1) != 3 || CopyBuffer(KCHandle1, 1, 0, 3, KC_Middle1) != 3)
       { 
             Print("Error Copying Indicator Data"==GetLastError());
             return;
  } 
        if( CopyBuffer(KCHandle2, 2, 0, 3, KC_Lower2) != 3 || CopyBuffer(KCHandle2, 0, 0, 3, KC_Upper2) != 3|| CopyBuffer(KCHandle2, 1, 0, 3, KC_Middle2) != 3){
     {
              Print("Error Copying Indicator Data", GetLastError());
         return;
        }
  
    //Declaring switches for market entry signals
      bool BuyCondition = false;
      bool SellCondition = false;
      bool BullTrend = false;
      bool BearTrend = false;
      bool TradeOpen = false;
      
      //Checking if we have an open position in the market
      if(DealsOpen()!=0)
     {
      TradeOpen = true;
     }
   if(UseBreakEven)
     {
      BreakEven(EA_Magic, _Symbol, WhenToBreak, BreakBy);
        }
      if(UseTrailing)
          {
      TrailingStopLoss(EA_Magic, _Symbol, WhenToTrail, TrailBy);
        }
            (uint  total =0)
            
         uint position_ID=0;
          
         if(PositionSelect Symbol())
        {
         if(PositionGetInteger(POSITION_MAGIC)==EA_Magic)
           {
           position_ID=(ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER);
           HistorySelectByPosition(position_ID);
                 total=HistoryDealsTotal;
                    return(total);
               }
                 return(0);
             }
           
      //Setting Conditions Trends
      if((KC_Upper1[1] > KC_Lower2[1]) && (KC_Lower1[1] < KC_Upper2[1]))
     {     
      BullTrend = true;
     }
     
        if((KC_Lower1[1] < KC_Lower2[1]) && (KC_Upper1[1] > KC_Lower2[1]))
     {
      BearTrend = true;
     }
  
  //Sell entry condition
if((ClosePrice1[1] < KC_Lower1[1]) && (ClosePrice[2] > KC_Lower1[1]) && (ClosePrice[2] > KC_Lower1[2]))
  {
   SellCondition = true;
  }
  
//Buy entry Conditions
if((ClosePrice[1] > KC_Upper1[1]) && (ClosePrice[2] < KC_Upper1[1])KC_Lower1[1])&& (ClosePrice[2] < KC_Upper1[2]));
{
   BuyCondition = true;
 } 
  
//Obtaining the value of our lotsize
double UsedLots;
if(UseMoneyManagement)
  {
UsedLots = MoneyManagement(Funds_ToUse, MM_Type, STP, ATR_Multiplier, Fixed_Balance, Fixed_RiskMoney, Percentage_risk);
    else
        UsedLots = Lotsize;
     } 
     
   //Executing a Buy Trade
   if(!TradeOpen)
     {
      if(BullTrend)
        {
         if(BuyCondition)
          {
            fBuy(UsedLots);
           }
        }
     }
     
//Executing a Sell Trade
   if(!TradeOpen)
     {
      if(BearTrend)
        {
         if(SellCondition)
           {
            fSell(UsedLots);
            
           }
        }
     }
   uint DealsOpen()
     {
      uint total = 0;
     }
      if(PositionSelect(_Symbol))
     {
      if(PositionGetInteger(POSITION_MAGIC)= = EA_Magic){
      {
         position_ID = (ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER);
        if(HistorySelectByPosition(position_ID))
           {
            total = HistoryDealsTotal();
            return(total);
               return;
   }        
    }    
  }
 }  
  Hi Guys ? Happy holiday? I am a student in MQL5 Algorithmic Trading. Please what is wrong with the above code? How should I fix the 2 errors  and 1 warning? It outputs 2 errors and 1 warning. There are 30 '{'   and 30 '}' so the parentheses are balanced.
    	ERRORS:
               Line 73: '{'- Unbalanced parentheses
               Line 269: '}'- Unexpected end of program
       WARNING:
               Line 15: Version is incompatible with MQL5 market, must be xxx.yyy

  
  


            
 
//|                                      Keltner_Channel_Counter.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"


#include<Trade.mqh>
//#include<Risk_Management.mqh>
//#include<Trade_Manager.mqh>

//EA general input parameters
input int MA_Period1 = 15; //First Keltner Channel Period
input int MA_Period2 = 90; //Second Keltner Channel Peiod

//General input Parameters
input string Comments = "KCC"; //EA Order Comment
input int StopLoss = 10; //StopLoss in pips
input int TakeProfit = 145; //TakeProfit in Pips
input int EA_Magic = 4356; //EA_Magic number
input double Lotsize = 0.05; //Lotsize
input int Slippage = 50; //Slippage

//Breakeven input variables
input bool UseBreakEven = true; //Use Break Even
input int WhenToBreak = 10; //When to break even in pips?
input int BreakBy = 15; //Break Even by how many pips?

//Trailing Stop input variables
input bool UseTrailing = true; //Use Trailing Stop
input int WhenToTrail = 25; // When to start Trailing in pips?
input int TrailBy = 55; //Trailing Stop in Pips

//Money Management input variables
input bool Used_Money_Management = true;
input double Funds_To_Use; //Funds to Use for Lot Calculation
input double MM_Type; //Type of Money Management
input double ATR_Multiplier = 1 ; //ATR Multiplier
input double Fixed_Balance = 1000; //Fixed Balance in account currency
input double Fixed_RiskMoney = 20; //Fixed Risk Money
input double Percentage_risk = 5; //Percentage of Funds to Risk

//EA intermediate calculations variables
double STP, TKP;
ulong LastBars = 0;
double Ask, Bid;

//Indicator handles
int KCHandle1;
int KCHandle2;

//Indicator Buffers
double KC_Upper1[];
double KC_Lower1[];
double KC_Middle1[];
double KC_Upper2[];
double KC_Lower2[];
double KC_Middle2[];
double ClosePrice[];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//....Initializing the Trade Class Object


//.....Initializing the Indicator Handles
   KCHandle1 = iCustom(_Symbol,PERIOD_CURRENT,"Keltner_Channel", MA_Period1);
   KCHandle2 = iCustom(_Symbol, PERIOD_CURRENT, "Keltner_Channel", MA_Period2);

//Convert the Pips value into Point value
   STP = StopLoss*_Point*10;
   TKP = TakeProfit*_Point* 10;

//...Resizing the Close Price array
   ArrayResize(ClosePrice, 3);
   return(INIT_SUCCEEDED);
  }


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

   return;
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

//---Check if we are able to trade
   if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) || !TerminalInfoInteger(TERMINAL_CONNECTED))
     {
      Alert("Terminal not connected or Trading not allowed!");
     }


//...Check if we have a new bar
   ulong bars = Bars(_Symbol, PERIOD_CURRENT);
   if(LastBars != bars)
     {
      LastBars = bars;
      return;
     }

//...Obtaining Ask price and Bid Price   Ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   Bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
//...Obtaining the Closing Price of the Previous Candlestick
   MqlRates rates[];

//Reversing the ordering of information in our Arrays
   ArraySetAsSeries(KC_Upper1, true);
   ArraySetAsSeries(KC_Upper2, true);
   ArraySetAsSeries(KC_Lower1, true);
   ArraySetAsSeries(KC_Lower2, true);
   ArraySetAsSeries(KC_Middle1, true);
   ArraySetAsSeries(KC_Middle2, true);
   ArraySetAsSeries(rates, true);
   ArraySetAsSeries(ClosePrice, true);

//...Checking and Copying Prices into the Rates Object
   if(CopyRates(Symbol(), PERIOD_CURRENT, 0, 3, rates) != 3)
     {
      Print("Error Copying Price Data", GetLastError());
      return;
     }

//Copying price data from the Rates Object to the Close Price Array
   for(int i = 0; i < 3; i++)
     {
      ClosePrice[i]= rates[i].close;
     }
//Checking and Copying  Indicator Values
   if(CopyBuffer(KCHandle1, 2, 0, 3, KC_Lower1) != 3 || CopyBuffer(KCHandle1, 0, 0, 3, KC_Upper1) != 3 || CopyBuffer(KCHandle1, 1, 0, 3, KC_Middle1) != 3)
     {
      Print("Error Copying Indicator Data"==(string) GetLastError());
      return;
     }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   if(CopyBuffer(KCHandle2, 2, 0, 3, KC_Lower2) != 3 || CopyBuffer(KCHandle2, 0, 0, 3, KC_Upper2) != 3|| CopyBuffer(KCHandle2, 1, 0, 3, KC_Middle2) != 3)
     {
        {
         Print("Error Copying Indicator Data", GetLastError());
         return;
        }
     }
//Declaring switches for market entry signals
   bool BuyCondition = false;
   bool SellCondition = false;
   bool BullTrend = false;
   bool BearTrend = false;
   bool TradeOpen = false;

//Checking if we have an open position in the market
   if(DealsOpen()!=0)
     {
      TradeOpen = true;
     }
   if(UseBreakEven)
     {
      BreakEven(EA_Magic, _Symbol, WhenToBreak, BreakBy);
     }
   if(UseTrailing)
     {
      TrailingStopLoss(EA_Magic, _Symbol, WhenToTrail, TrailBy);
     }
  uint  total =0;

   uint position_ID=0;
   if(PositionSelect(_Symbol))
     {
      if(PositionGetInteger(POSITION_MAGIC)== EA_Magic)
        {
           {
            position_ID = (ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER);
            if(HistorySelectByPosition(position_ID))
              {
               total = HistoryDealsTotal();
               return;
               }
           }
        }
     }
     
     
   
//Setting Conditions Trends
   if((KC_Upper1[1] > KC_Lower2[1]) && (KC_Lower1[1] < KC_Upper2[1]))
     {
      BullTrend = true;
     }

   if((KC_Lower1[1] < KC_Lower2[1]) && (KC_Upper1[1] > KC_Lower2[1]))
     {
      BearTrend = true;
     }

//Sell entry condition
   if((ClosePrice[1] < KC_Lower1[1]) && (ClosePrice[2] > KC_Lower1[1]) && (ClosePrice[2] > KC_Lower1[2]))
     {
      SellCondition = true;
     }

//Buy entry Conditions
   if((ClosePrice[1] > KC_Upper1[1]) && (ClosePrice[2] < KC_Upper1[1]) && (ClosePrice[2] < KC_Lower1[2]))
     {
      BuyCondition = true;
     }

//Obtaining the value of our lotsize
   double UsedLots;
   if(Used_Money_Management)
     {
      UsedLots = MoneyManagement(Funds_To_Use, MM_Type, STP, ATR_Multiplier, Fixed_Balance, Fixed_RiskMoney, Percentage_risk);
     }
   else
      UsedLots = Lotsize;

//Executing a Buy Trade
   if(!TradeOpen)
     {
      if(BullTrend)
        {
         if(BuyCondition)
           {
            fBuy(UsedLots);
           }
        }
     }

//Executing a Sell Trade
   if(!TradeOpen)
     {
      if(BearTrend)
        {
         if(SellCondition)
           {
            fSell(UsedLots);

           }
        }
     }

   if(PositionSelect(_Symbol))
     {
      if(PositionGetInteger(POSITION_MAGIC)== EA_Magic)
        {
           {
            position_ID = (ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER);
            if(HistorySelectByPosition(position_ID))
              {
               total = HistoryDealsTotal();
               return;
                       }
                    
           }
        }
     }
     return;
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
uint DealsOpen()
  {
   uint total = 0;
   return(total);
  }


double BreakEven(int EAMagic, string symbol, bool When_To_Break, bool Break_By) {return(0);}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double TrailingStopLoss(int EAMagic, string symbol,bool WhenTo_Trail, bool Trail_By) {return(0);}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double MoneyManagement(double FundsToUse, double MMType, double stp, double ATRMultiplier, bool FixedBalance, double FixedRiskMoney, double Percentagerisk) {return(0);}
//+------------------------------------------------------------------+


double fBuy(double Lot_size){return(0);}

double fSell(double Lot_size){return(0);}


You need to complete the five empty functions at the end of the code.