I have been working on this EA code for months and still seem to be getting errors. HELP!

 
int fibo(int x, int y, int z)
{
  if (z > 0)
    return x + z * (y - x);
  else
    return y + z * (x - y);
}

int OnInit()
{
  // Initialize global variables and settings here

  return(INIT_SUCCEEDED);
}
 
 if OnCalculate(const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[])
                 
{ 
    // Define inputs
    input ma100_period = 100;
    input ma200_period = 200;
    input rsi_period = 14;
    input bb_period = 20;
    input bb_stddev = 2;
    input vwma_period = 20;

   
    // Define strategy
    strategy("My Strategy", overlay=true);

    // Define variables
    double ma100 = sma(close, ma100_period);
    double ma200 = sma(close, ma200_period);
    double rsi = rsi(close, rsi_period);
    double atr = atr(14);
    double bb = bollinger(close, bb_period, bb_stddev);
    double vwma = vwma(close, volume, vwma_period);
    double obv = obv();


    // Define Fibonacci retracement levels
    double retracement76 = fibo(high, low, 76.8);
    double retracement88 = fibo(high, low, 88);

    // Define Fibonacci extension level
    double extension = fibo(high, low, -3.618);

    // Define trend direction
    bool trendUp = ma100 > ma200;
    bool trendDown = ma100 < ma200;

    // Define entry levels
    bool entryLong = trendUp && rsi < 30 && close < retracement88 && close < bb.upper && vwma > obv;
    bool entryShort = trendDown && rsi > 70 && close > retracement88 && close > bb.lower && vwma < obv;

    // Define profit levels
    bool profitLong = high > extension && low > entryLong - (atr * 3);
    bool profitShort = low < extension && high < entryShort + (atr * 3);

      // Place trades
    if (entryLong)
      OrderSend(Symbol(), OP_BUY, 1.0, Ask, 3, 0, 0, "Buy order", 16384, 0, clrGreen);
    if (entryShort)
      OrderSend(Symbol(), OP_SELL, 1.0, Bid, 3, 0, 0, "Sell order", 16384, 0, clrRed);
  }

  // Calculate equity stop out level
  double equityStopOut = AccountEquity() * 0.3;

  // Calculate maximum risk per trade
  double maxRiskPerTrade = AccountEquity() * 0.2;
  
  // Check for open trades
  for(int i = 0; i < OrdersTotal(); i++)
  {
    // Get order information
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    double orderProfit = OrderProfit();
    double orderLots = OrderLots();
    double orderStopLoss = OrderStopLoss();
    double orderTakeProfit = OrderTakeProfit();

    // Check for long trades
    if (OrderType() == OP_BUY)
    {
      // Check for profit
      if (profitLong)
      {
        // Set take profit
        OrderModify(OrderTicket(), OrderOpenPrice(), extension, OrderExpiration(), clrGreen);
      }

      // Check for stop out
      if (AccountEquity() < equityStopOut)
      {
        // Close all trades
        OrderClose(OrderTicket(), OrderLots(), MarketInfo(Symbol(), MODE_BID), 3, clrRed);
      }

      // Check for maximum risk per trade
      if (orderProfit < -maxRiskPerTrade)
      {
        // Close trade
        OrderClose(OrderTicket(), OrderLots(), MarketInfo(Symbol(), MODE_BID), 3, clrRed);
      }
    }

    // Check for short trades
    if (OrderType() == OP_SELL)
    {
      // Check for profit
      if (profitShort)
      {
        // Set take profit
        OrderModify(OrderTicket(), OrderOpenPrice(), extension, OrderExpiration(), clrRed);
      }

      // Check for stop out
      if (AccountEquity() < equityStopOut)
      {
        // Close all trades
        OrderClose(OrderTicket(), OrderLots(), MarketInfo(Symbol(), MODE_ASK), 3, clrGreen);
      }

      // Check for maximum risk per trade
      if (orderProfit < -maxRiskPerTrade)
      {
        // Close trade
        OrderClose(OrderTicket(), OrderLots(), MarketInfo(Symbol(), MODE_ASK), 3, clrGreen);
      }
    }
  }

but on keep getting these errors. (check picture below) I do not know how to fix this to make the code functional and able to compile

 
Simon Popov: but on keep getting these errors. (check picture below) I do not know how to fix this to make the code functional and able to compile

There are just too many things wrong with it. You are mixing elements of an Indicator (to display on a chart) together with an Expert Advisor (for trading).

The OnCalculate() event handler is for Indicators, but indicators cannot use trading functions like OrderSend(). You also have an "if" in front of "OnCalculate()". Maybe you meant to write "int" instead of "if".

If it is an Expert Advisor for trading then you can't use OnCalculate(). Instead you need to use OnTick().

There are also unbalanced parenthesis in your code and code that is outside of a function in the global scope where it is not allowed.

I do suggest you return to the documentation and read some more. Have a look at examples in the CodeBase to help you out.

 
Fernando Carreiro #:

There are just too many things wrong with it. You are mixing elements of an Indicator (to display on a chart) together with an Expert Advisor (for trading).

The OnCalculate() event handler is for Indicators, but indicators cannot use trading functions like OrderSend(). You also have an "if" in front of "OnCalculate()". Maybe you meant to write "int" instead of "if".

If it is an Expert Advisor for trading then you can't use OnCalculate(). Instead you need to use OnTick().

There are also unbalanced parenthesis in your code and code that is outside of a function in the global scope where it is not allowed.

I do suggest you return to the documentation and read some more. Have a look at examples in the CodeBase to help you out.

Yeah I am starting to see where this all went wrong! would you be ever so kind as to refine the code in a way that it would maintain the same execution elements but dispose of all the un needed/ bugged code? cheers in advance :)
 
Simon Popov #: Yeah I am starting to see where this all went wrong! would you be ever so kind as to refine the code in a way that it would maintain the same execution elements but dispose of all the un needed/ bugged code? cheers in advance :)

Sorry, but as I wrote, there is just too much wrong with it. There is even code there that is not even from the MQL language and a whole lot of input parameters that have simply not even been defined.

It would need to be rewritten from scratch and we don't even know the intended strategy logic and the functionality requirements.

If your priority is to get the EA done quickly and not so much learning how to do it yourself, then consider placing a job request in the Freelance section and hiring someone to code it for you.

If however, your priority is learning to code it yourself, then you will have to persevere and continue to do your research and studying other code examples in the CodeBase section, or by reading some Articles aimed at beginner coders.

Reason: