Can't find cause of Ending } Expected

 

Hello,

I am in the process of finshing up my first EA. I still have a few importain things to add (like the ordersent) but I felt like it was time to debug. I was able to get everything fixed but a Ending } Expected. I know that this is due to unbalanced brackets and I have gone over every line a few times but I can't find a stray. I have posted my code so if anyone wants to go over it I would appreciate it. If theres any over reason why a Ending } Expected would happen I would like to know.

P.S. I know my code isen't pretty or formated great but its still in creation

Thanks to all who help

#property copyright
#property link      
//Need to know:
//check close all orders, price movement,its direction,buy at market with
//realamount, ra to lots
//To-Do:realamount to lots, rollover time, entry&exit,report condistion
string Old_Price,New_Price,Point2Pip,Stopped,SubjectStopped;
int init()
  {
  /*Start notification:Sents email, makes comment and alerts when 
  program is turned on*/
   string Started,SubjectStarted,Old_Price,New_Price,Point2Pip;
   Started="STTC Started on "TimeMonth(TimeCurrent()) 
   "-"TimeDay(TimeCurrent())"-"TimeDay(TimeCurrent())
   " at "TimeHour(TimeCurrent())":"TimeMinute(TimeCurrent())
   ":"TimeSeconds(TimeCurrent());
   SubjectStarted="STTC Started"
   SendMail(SubjectStarted,Started);
   Comment (Started);
   Alert (Started);
   return(0);
   /*Trend determiner:Part of trend determiner*/
   Old_Price=Ask;
   New_Price=Ask; 
   Point2Pip=Point;
   if(Digits==3){Point2Pip=0.01;}
   if(Digits==5){Point2Pip=0.0001;}
   }
int deinit ()
  {
  /*Stop notification:Sents email, makes comment and alerts when 
  program is shut off*/
   Stopped="STTC Stopped on "TimeMonth(TimeCurrent())
   "-"TimeDay(TimeCurrent())"-"TimeDay(TimeCurrent())" at "
   TimeHour(TimeCurrent())":"TimeMinute(TimeCurrent())":"
   TimeSeconds(TimeCurrent());
   SubjectStopped="STTC Stopped"
   SendMail(SubjectStopped,Stopped);
   Comment (Stopped);
   Alert (Stopped);
   return(0);
  }
int Start()
  {
   //Declaration of variables
   int Spips,Apips,Epips,TStop,i;
   string TDirection,UseEpipSetter,ACondition,InvestType,InvestAmount,
   InvestPercent,Margin,realamount,beforefloor,InvestLots,donttrade,
   RolloverHour,RolloverMin,RolloverStop,StartWeekendHour,
   StartWeekendMin,StartWeekendDay,StopWeekendDay,StartWeekendStop,
   SentReportHour,trenddirection,Str_Np,Str_Op;
   //Initialization of variables
   //-----------------------------------------------------------------
   //-----------------------------------------------------------------
   Spips=2//Standard entry pips
   Apips=1 //Alternitive entry pips; used if A condition is met and turned on
   TStop=2//Trailing stop
   UseEpipSetter=0 //"1" for Yes or "0" for No
   InvestType=0 //"1" for use amount or "0" for use percentage of balance
   InvestAmount=0 //Amount invested if InvestType is set to 1
   InvestPercent=100 //Amount invested if InvestType is set to 0; 1-100
   Margin=100//Margin multiplyer;max depends on acct, often 100 (for 1:100)
   ACondition=//none  //Condition needed for Apips to be used
   //Use server time zone for all times
   RolloverHour= //hour of rollover
   RolloverMin=  //min of rollover
   RolloverStop= //mins before and after when trading is stopped
   StartWeekendHour= //hour of weekend start
   StartWeekendMin=  //min of weekend start; Can't be 0
   StartWeekendDay=  //day of weekend start; 0=Sunday, 6=Saturday ect.
   SentReportHour= //hour daily report is sent
   //-----------------------------------------------------------------
   //-----------------------------------------------------------------
   /*Epip setter: Determines whether the Apips condition is met and 
   sets Epip to Apip if it is so*/
   IF (UseEpipSetter=1 && ACondition)
   {Epips=Apips;}
   else
   {Epips=Spips;}
   /*Rollover and Weekend Avoider:Assures that no trades are open during rollover or on 
   weekends by exiting and stopping before rollover and weekends*/
   donttrade=0;
   //Rollover
   IF
   (
   IF(TimeMinute(TimeCurrent())==0){RolloverHour=TimeHour(TimeCurrent())-1}
   else{RolloverHour=TimeHour(TimeCurrent())}
   RolloverMin-RolloverStop>=TimeMinute(TimeCurrent())&&
   IF (TimeMinute(TimeCurrent())+RolloverStop<59){RolloverHour=TimeHour(TimeCurrent())+1},
   (RolloverMin+RolloverStop)<=TimeMinute(TimeCurrent());
   )
   {
   //Next 7 lines are from Ahmed Soliman of http://www.xpworx.com
   OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
   if(OrderType()==OP_BUY)
   OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet);
   if(OrderType()==OP_SELL) 
   OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet);
   if(OrderType()>OP_SELL)
   OrderDelete(OrderTicket());
   donttrade=1;
   }
   //Weekend
   IF (
   TimeDayOfWeek(TimeCurrent())=StartWeekendDay&&
   IF(TimeMinute(TimeCurrent())=0){StartWeekendHour=TimeHour(TimeCurrent())-1}
   else{StartWeekendHour=TimeHour(TimeCurrent())}&&
   TimeMinute(TimeCurrent())>=StartWeekendMin-1
   )
   {
   //Next 7 lines are from Ahmed Soliman of http://www.xpworx.com
   OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
   if(OrderType()==OP_BUY)
   OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet);
   if(OrderType()==OP_SELL) 
   OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet);
   if(OrderType()>OP_SELL)
   OrderDelete(OrderTicket());
   donttrade=1;
   }
   /*Investment Amount:Determines the amount invested if its a 
   percentage and sets the amount regardless then turns into lots*/
   IF (InvestType=0)
   {
   realamount=AccountBalance()*(InvestPercent/100)*Margin;
   }
   else
   {
   realamount=InvestAmount*Margin;
   }
   realamount/1000=beforefloor;
   MathFloor (beforefloor)/100=InvestLots;
   /*Trend determiner:Triggers when price moves a certain 
   number of pips and determines the direction of the trend.
   Modified code from ubzen of www.fourm.mql4.com */------------------------------------------------------
   New_Price=Ask;
   Str_Np=DoubleToStr(New_Price,5);
   Str_Op=DoubleToStr(Old_Price,5);
   if(MathAbs(i)<Epips)
   if(Ask>Old_Price+1*Point2Pip);
   {i++;Alert "I Moved Up One-Pip from "+Str_Op+" to "+Str_Np;}
   else
   {i--;Alert "I Moved Dn One-Pip from "+Str_Op+" to "+Str_Np;}  
    Old_Price=New_Price;
    if(MathAbs(i)==Epips)
    {if(i>0){trenddirection=1;}else{trenddirection=-1;}
    i=0;
   /* Entry&Exit:Uses Epips to enter InvestPerc percent of capital
   in a market order with a trailing stop of TStop */
   IF (OrdersTotal()==0&&donttrade=0&&trenddirection=1||trenddirection=-1)
   {
      IF (trenddirection=1;)
      {//add}
      IF (trenddirection=-1;)
      {//add}
      trenddirection=0
   }
   return(0);
 
Act3297:

Hello,

I am in the process of finshing up my first EA. I still have a few importain things to add (like the ordersent) but I felt like it was time to debug. I was able to get everything fixed but a Ending } Expected. I know that this is due to unbalanced brackets and I have gone over every line a few times but I can't find a stray. I have posted my code so if anyone wants to go over it I would appreciate it. If theres any over reason why a Ending } Expected would happen I would like to know.

P.S. I know my code isen't pretty or formated great but its still in creation

Thanks to all who help

Hi Act,

You can use an editor like NotePad++ to find the matching pairs of brackets to fix your code.

Hope this helps,

Robert

 

Compile one line at a time. And make good use of Print or Alert statements. And adopt a neat style. There are lots of capital IF's instead of if. And you commented out your } in the last nest.

IF (trenddirection=1;)
      {//add}
//---Wrong, use the below formats.




if(trenddirection == 1){
    //----Add Something----Simicolon at end;
}

//--or

if(trenddirection == 1)
    {
        //----Add Something----Simicolon at end;
    }

//---Works as well.
 

cosmicbeing--

Thanks

I will download it and try it now.

ubzen--

I did learn that I should compile every line while makeing this EA.

 

EDIT

Never mind about the 2nd problem, I added an extra }

Reason: