HELP!!!

 

Alright, I've put together a strategy that is supposed to buy at the open of the next bar when the previous bar's Close > Open. The trade ends either at my stop/limit or when the Close < Open (if I haven't hit my stop/target, my trade should end at the open of the down close). I cannot get this code to compile correctly, any advice?

//+------------------------------------------------------------------+
//|                                             Close Open Strat.mq4 |
//|                                                   Sheldomination |
//|                                                                  |
//+------------------------------------------------------------------+


extern double LotSize = 0; 
extern double StopLoss = 0; 
extern double TakeProfit = 0; 

extern int Slippage = 0; 
extern int MagicNumber = 1; 
extern bool CheckOncePerBar = true; 

double firstStartSignal = iClose("EURUSD", PERIOD_M30, BarShift);
double secondStartSignal = iOpen("EURUSD", PERIOD_M30, BarShift);

double firstEndSignal = iClose("EURUSD", PERIOD_M30, BarShift);
double secondEndSignal = iOpen("EURUSD", PERIOD_M30, BarShift);

if(Close[BarShift] > Open[BarShift])
   double UseLow = iLow(NULL, 0, BarShift);

int BuyTicket;
int SellTicket;
datetime CurrentTimeStamp;
int BarShift;


double UsePoint;
int UseSlippage;



int init()
   {
      UsePoint = PipPoint(Symbol());
      UseSlippage = GetSlippage(Symbol(), Slippage);
      CurrentTimeStamp = Time [0];
   }
          

int start()
  {
  
      if(CheckOncePerBar == true)
         {
            int BarShift = 1;
            if(CurrentTimeStamp != Time [0])
               {
                  CurrentTimeStamp = Time[0];
                  bool NewBar = true;
               }
            else NewBar = false;
         }
       else
         {
            NewBar = true;
            BarShift = 0;
         }
  

     
      if(TradeAllowed == true && NewBar == true)
         {
         
            if(firstStartSignal > secondStartSignal && BuyTicket == 0)
      
      
      
      
            {
               OrderSelect(SellTicket, SELECT_BY_TICKET);
         
         
     
               if(OrderCloseTime() == 0 && SellTicket > 0)
            {
               double CloseLots = OrderLots(); 
               double ClosePrice = Ask; 
               
               bool Closed = OrderClose(SellTicket, CloseLots, ClosePrice, UseSlippage, Red); 
            }
            
         double OpenPrice = Ask; 
         
         if(StopLoss > 0) double BuyStopLoss = OpenPrice - (StopLoss * UsePoint);
         if(TakeProfit > 0) double BuyTakeProfit = OpenPrice + (TakeProfit * UsePoint);
         

         
         BuyTicket = OrderSend(Symbol(), OP_BUY, LotSize, OpenPrice, UseSlippage, BuyStopLoss, BuyTakeProfit, "Buy Order", MagicNumber, 0, Green);
         
         SellTicket = 0; 
      }
      

     
       if(firstEndSignal < secondEndSignal && SellTicket == 0) 
      
      
      
      
      
         {
            OrderSelect(BuyTicket, SELECT_BY_TICKET);
            
            if(OrderCloseTime() == 0 && BuyTicket > 0)
               {
                  CloseLots = OrderLots();
                  ClosePrice = Bid;
                  
                  Closed = OrderClose(BuyTicket, CloseLots, ClosePrice, UseSlippage, Red);
               }
               
         OpenPrice = Bid; 
         
         if(StopLoss > 0) double SellStopLoss = OpenPrice + (StopLoss * UsePoint);
         if(TakeProfit > 0) double SellTakeProfit = OpenPrice - (TakeProfit * UsePoint);
         
         SellTicket = OrderSend(Symbol(), OP_SELL, LotSize, OpenPrice, UseSlippage, SellStopLoss, SellTakeProfit, "Sell Order", MagicNumber, 0, Red);
         
         BuyTicket = 0; 
         
     }
     
   return(0); 
   
  }
  
  
  double PipPoint(string Currency)
   {
      
      int CalcDigits = MarketInfo(Currency, MODE_DIGITS);
      if(CalcDigits == 2 || CalcDigits == 3) double CalcPoint = 0.01;
      else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;
      return(CalcPoint);
   }
   

  
  int GetSlippage(string Currency, int SlippagePips)
   {
      int CalcDigits = MarketInfo(Currency, MODE_DIGITS);
      if(CalcDigits == 2 || CalcDigits == 3) double CalcSlippage = SlippagePips;
      else if(CalcDigits == 3 || CalcDigits == 4) CalcSlippage = SlippagePips*10;
      return(CalcSlippage);
   }
 

this code can't even pass compilation https://www.mql4.com/files/MQl4BookEnglish.chm

 
double firstStartSignal = iClose("EURUSD", PERIOD_M30, BarShift);
double secondStartSignal = iOpen("EURUSD", PERIOD_M30, BarShift);

double firstEndSignal = iClose("EURUSD", PERIOD_M30, BarShift);
double secondEndSignal = iOpen("EURUSD", PERIOD_M30, BarShift);

if(Close[BarShift] > Open[BarShift])
   double UseLow = iLow(NULL, 0, BarShift);

Initialize variables with constants outside of start. non-constants must be inside.

what is the value of UseLow when the if() is false.

 
WHRoeder:

Initialize variables with constants outside of start. non-constants must be inside.

what is the value of UseLow when the if() is false.

If Close[BarShift] < Open [BarShift]) then the UseLow variable then my wish is to not implement the BarShift variable. Should I add this as an "else" statement?

BarShift is supposed to be designed to shift to a bar other than the current bar to analysis. Thoughts?

 
Does anyone have an answer? Thanks!
 

It looks like you are missing a few closing brackets.

For this one:

{
               OrderSelect(SellTicket, SELECT_BY_TICKET);

and this one:

{
            OrderSelect(BuyTicket, SELECT_BY_TICKET);
 
outofdebt:

It looks like you are missing a few closing brackets.

For this one:

and this one:

Thanks! I'll try that and get back to you guys. I appreciate it!
Reason: