Help! MedaEditor tells me didn't defind GetTotalProfits / CloseAllTrades.Why?

 

Hi all,

ha yeah one more new coders..

(code it at bottom)

What was mt4 expecting on 145?

Why is 104 unbalanced.

I thought I did defind GetTotalProfits on line 72.

I thought I did defind CloseAllTrades on line 72.

Thanks for the help!


#property strict

string BotName = "JHB Robot";
int Magic = 123456;
int MaxTrades = 1;
int MaxCloseSpreadPips = 7;

double LotsToTrade = 1.0;
double StopLoss = 3700;
double ProfitTarget = 20.00;

int SMAFast = 145;
int SMASlow = 250;
bool LongSetup = False;

int OnInit()
  {

   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {

   
  }
  

// This runs on every single tick 
void OnTick()
{
   double SlowMovingAverage = iMA(NULL, 0, SMASlow, 0, MODE_SMA, PRICE_CLOSE, 0);
   double SlowMovingAverageOne = iMA(NULL, 0, SMASlow, 0, MODE_SMA, PRICE_CLOSE, 3);
   double SlowMovingAverageTwo = iMA(NULL, 0, SMASlow, 0, MODE_SMA, PRICE_CLOSE, 15);
   double SlowMovingAverageThree = iMA(NULL, 0, SMASlow, 0, MODE_SMA, PRICE_CLOSE, 30);
   
   double FastMovingAverage = iMA(NULL, 0, SMAFast, 0, MODE_SMA, PRICE_CLOSE, 0);
   double FastMovingAverageOne = iMA(NULL, 0, SMAFast, 0, MODE_SMA, PRICE_CLOSE, 3);
   double FastMovingAverageTwo = iMA(NULL, 0, SMAFast, 0, MODE_SMA, PRICE_CLOSE, 15);
   double FastMovingAverageThree = iMA(NULL, 0, SMAFast, 0, MODE_SMA, PRICE_CLOSE, 30);   
  
     
   
   //int Trades = GetTotalOpenTrades();
   //Print("*** Our Total number of Trades: ", Trades);
   
   if ( GetTotalOpenTrades() < MaxTrades )
   {
      
      // check for long trade setup
      if  ((FastMovingAverageOne < SlowMovingAverageOne) && 
          (FastMovingAverageTwo < SlowMovingAverageTwo) && 
          (FastMovingAverageThree < SlowMovingAverageThree))
      {
        if(FastMovingAverage < SlowMovingAverage)
        {
           LongSetup = True;
        }
      }
      
      if(LongSetup == True)
      {
         int OrderResult = OrderSend(Symbol(), OP_BUY, LotsToTrade, Ask, 10, 0, 0, "Buy Order" , Magic, 0, clrGreen);
         LongSetup = False;  
             
      }  
  
  
   
   }
   
  if (GetTotalProfits() > ProfitTarget) CloseAllTrades(); 

}

int GetTotalOpenTrades()
{
    int TotalTrades = 0;
    
    // Loop through open orders and add them to TotalTrades
    for (int t=0; t<OrdersTotal(); t++)
    {
    
       if(OrderSelect(t, SELECT_BY_POS, MODE_TRADES))
       {
          if(OrderSymbol() != Symbol()) continue;
          if(OrderMagicNumber() != Magic) continue;
          if(OrderCloseTime() != 0) continue;
          
          TotalTrades = (TotalTrades +1);
          
       }
   }
   
   return TotalTrades;
}         
    




    
void CloseAllTrades()
{
   int CloseResult = 0:
   
   for (int t=0; t<OrdersTotal();
   {
   if(OrderSelect(t, SELECT_BY_POS, MODE_TRADES))
   
   {    
       if (OrderMagicNumber() != Magic) continue;
       if (OrderSymbol() != Symbol() continue;
       if OrderType() == OP_BUY) CloseResult = OrderClose(OrderTicket(), OrderLots(), Bid, MaxCloseSpreadPips, clrRed);
       if OrderType() == OP_SELL) CloseResult = OrderClose(OrderTicket(), OrderLots(), Ask, MaxCloseSpreadPips, clrRed);
       t--;
 
   }
   
   return;
}



// Check total profit for all trade combined
double GetTotalProfits()
{
   double TotalProfits = 0.0;

   for (int t=0; t<OrdersTotal(); t++)
   {
      if(OrderSelect(t, SELECT_BY_POS, MODE_TRADES))
      {
          if (OrderMagicNumber() != Magic) continue;
          if (OrderSymbol() != Symbol()) continue;
          if (OrderCloseTime() != 0) continue;
          
          TotalProfits = (TotalProfits + OrderProfit());
          
       }
       
    }   

  return TotalProfits;
}

 
HenryJack:

What was mt4 expecting on 145?

Why is 104 unbalanced.

I thought I did defind GetTotalProfits on line 72.

I thought I did defind CloseAllTrades on line 72.

  1. You have an error at 104. Ignore all errors below that until you fix 104, and recompile.

    1.    for (int t=0; t<OrdersTotal();
      This statement does nothing. It is not connected to the code below.
    2. Count the parentheses.


  2. No that is a call. You tried defined it on line 126 but you have an error at 104. Ignore all errors until you fix 104, and recompile.

  3. No that is a call. You tried to define it on line 103 but you have an error at 104. Ignore all errors until you fix 104, and recompile.
  4. Why did you post your MT4 question in the Root / 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. The moderators will likely move this thread there soon.

  5. CloseResult = OrderClose(OrderTicket(), OrderLots(), Bid, MaxCloseSpreadPips, clrRed);
    Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  6.      if OrderType() == OP_BUY) CloseResult = OrderClose(OrderTicket(), OrderLots(), Bid, MaxCloseSpreadPips, clrRed);
         if OrderType() == OP_SELL) CloseResult = OrderClose(OrderTicket(), OrderLots(), Ask, MaxCloseSpreadPips, clrRed);
    You can use OrderClosePrice() instead of Bid/Ask.
              www.mql5.com/en/forum/158890/page3#comment_3812636


 

Thanks whroeder1!


what should I do on line 104?


Reason: