Illegal Else without a matching IF ERROR!

 

Can someone please see why this code is not Compiling. 

Am studying an online course, where we're making a simple 2 Deviation BB Strategy (for educational purposes). 

Thanks in advance. 

Mike


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

//|                                             FirstEA_Tutorial.mq4 |

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

#property version   "1.00"

#property strict

#property show_inputs



#include <BBAssignment.mqh>

int magicNB = 888;

int orderID;

int myBB1Period = 20;

int myBB1Std = 1;



int myBB2Period = 20;

int myBB2Std = 4;



input double riskPerTrade = 0.02;

input int MaxLossPips = 40;

input double TargetProfitPercent = 0.06;



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

//| Expert initialization function                                   |

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

int OnInit()

  {

//---

   Alert("The EA just started.");

   

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   Alert("");

   Alert("The EA just shutdown.");

   

  }

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

//| Expert tick function                                             |

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

void OnTick()

{

//---

//BB Band#1

double BB1Upper = iBands(NULL,0,myBB1Period,myBB1Std,0,PRICE_CLOSE,MODE_UPPER,0);

double BB1Mid = iBands(NULL,0,myBB1Period,myBB1Std,0,PRICE_CLOSE,MODE_MAIN,0);

double BB1Lower = iBands(NULL,0,myBB1Period,myBB1Std,0,PRICE_CLOSE,MODE_LOWER,0);



//BB Band#2

double BB2Upper = iBands(NULL,0,myBB2Period,myBB2Std,0,PRICE_CLOSE,MODE_UPPER,0);

double BB2Mid = iBands(NULL,0,myBB2Period,myBB2Std,0,PRICE_CLOSE,MODE_MAIN,0);

double BB2Lower = iBands(NULL,0,myBB2Period,myBB2Std,0,PRICE_CLOSE,MODE_LOWER,0);



//Optimal Lot Size 

double lotsize = OptimalLotSize(riskPerTrade,MaxLossPips);



//Order Management

int openOrders = OrdersTotal();

Alert("Total Open Orders: " + openOrders);



if(!CheckIfOpenOrdersByMagicNB(magicNB)) Alert("Already Open Order. Do NOT send more.");

{

   if(Ask < BB1Lower);//buying Long.

   {

   double stoplossPriceBuy = NormalizeDouble(BB2Lower,Digits);

   double takeProfitPriceBuy = NormalizeDouble(BB1Upper, Digits);  

   orderID = OrderSend(NULL,OP_BUYLIMIT,lotsize,Ask,10,stoplossPriceBuy,takeProfitPriceBuy,NULL,magicNB);

   Alert("Price is below Signal Entry Price, sending Buy Order");

   Alert ("Just sent Buy Order." + orderID); 

   Alert("Take Profit Set @ :" + NormalizeDouble(takeProfitPriceBuy,2));    

   Alert("StopLoss Set @ :" + NormalizeDouble (stoplossPriceBuy,2));

   Alert("Optimal Lot Size: " + NormalizeDouble(lotsize, 2));     

   }  

   if (orderID <0) Alert("Order Rejected - Error# " + GetLastError());      

   else if(Bid > BB1Upper)

   {

   double stoplossPriceShortSell = NormalizeDouble(BB2Upper,Digits);

   double takeProfitPriceShortSell = NormalizeDouble(BB1Lower,Digits); 

   orderID = OrderSend(NULL,OP_SELLLIMIT,lotsize,Bid,10,stoplossPriceShortSell,takeProfitPriceShortSell,NULL,magicNB);

   if (orderID <0) Alert("Order Rejected - Error# " + GetLastError());      

   Alert ("Just sent ShortSell Order.");                         

   Alert("Price is below Signal Entry Price, sending Short Sell Order");

   Alert("Take Profit Set @ :" + NormalizeDouble (takeProfitPriceShortSell, 2));    

   Alert("StopLoss Set @ :" + NormalizeDouble (stoplossPriceShortSell,2)); 

   Alert("Optimal Lot Size: " + NormalizeDouble(lotsize, 2));

   }    

 }

//else if you already have a position, update orders if required

 else Alert("Order already open");     



    if(OrderSelect(orderID,SELECT_BY_TICKET)== true)

     {

      int orderType = OrderType(); // 0=Long, 1=Short

     } 

      double currentExitPoint;

     

      if(orderType = 0)

        {

         currentExitPoint = NormalizeDouble(BB2Lower, Digits);

        }

      else

        {

         currentExitPoint = NormalizeDouble(BB2Upper, Digits);

        }

        double currentTakeProfitLine = NormalizeDouble(BB1Upper, Digits);

        

        double TP = OrderTakeProfit();

        double SL = OrderStopLoss();

        

        if(TP != currentTakeProfitLine !! SL != currentExitPoint)

          {                  

           bool Ans = OrderModify(orderID,OrderOpenPrice(),currentExitPoint,currentTakeProfitLine,0,clrNONE);

           if(Ans == true)

             {

              Alert("Modifying & Updating Order: " + orderID);

             }

          }    

          

}



//+------------------------------------------------------------------+
Files:
 
Please edit your post and

use the code button (Alt+S) when pasting code


I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
 
Keith Watford:
Please edit your post and

use the code button (Alt+S) when pasting code


I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
Thanks Keith. 
 
  1. Don't post your MT4 question in the MT5 General 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.
  2. Use the styler (control++) and you'll see where things don't line up and what is connected to what.
  3. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

 
On many places you have ";" in the "if" part.
Look closer.
Reason: