unbalanced parenthesis issue in line of my bot code, 59. please help

 

i have ben trying to fix the issue for some hours and it is not yielding, please help

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

//|                                            Real Money fx 💰      |

//|                        Copyright © 2024, Olalekan Muhammed       |

//|                                    olalekanmuhammed141@gmail.com |

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

#property strict


#include <Trade\Trade.mqh>


input int FastPeriod = 27;

input double FastRange = 1.6;

input int SlowPeriod = 55;

input double SlowRange = 2.0;

input double RiskPercentage = 25.0;  // Risk 25% of account equity

input int VolatilityPeriod = 14; // Period for volatility calculation

input double VolatilityThreshold = 20; // Threshold for high volatility


//--- Indicator buffers

double FastSmoothedRange[];

double SlowSmoothedRange[];

double CombinedSmoothedRange[];

double Filter[];

double Upward[];

double Downward[];

double StdDev[]; // Buffer for standard deviation


//--- Trade object

CTrade Trade;


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

//| Expert initialization function                                   |

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

int OnInit()

{

    ArraySetAsSeries(FastSmoothedRange, true);

    ArraySetAsSeries(SlowSmoothedRange, true);

    ArraySetAsSeries(CombinedSmoothedRange, true);

    ArraySetAsSeries(Filter, true);

    ArraySetAsSeries(Upward, true);

    ArraySetAsSeries(Downward, true);

    ArraySetAsSeries(StdDev, true);


    Print("Initialization completed.");

    return(INIT_SUCCEEDED);

}


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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

{

    Print("Deinitialization completed.");

}


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

//| Expert tick function                                             |

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

void OnTick()

{


  

    // Ensure we are trading only XAUUSD and on the 5-minute chart

    if (Symbol() != "XAUUSD" || Period() != PERIOD_M5)

        return;


    int i = 1; // Calculate for the previous closed bar


    // Calculate the standard deviation

    StdDev[i] = iStdDev(NULL, 0, VolatilityPeriod, PRICE_CLOSE, MODE_SMA, i);


    // Check volatility threshold

    if (StdDev[i] > VolatilityThreshold) // Adjust threshold as needed

    {

        AdjustStopLoss(StdDev[i]);

    }


    // Get close prices

    double closePrice = iClose(NULL, 0, i);

    double prevClosePrice = iClose(NULL, 0, i + 1);


    // Calculate the smoothed ranges

    FastSmoothedRange[i] = CalculateEMA(FastPeriod, FastRange);

    SlowSmoothedRange[i] = CalculateEMA(SlowPeriod, SlowRange);

    CombinedSmoothedRange[i] = (FastSmoothedRange[i] + SlowSmoothedRange[i]) / 2;


    // Calculate the filter

    double previousFilter = Filter[i + 1];

    double currentSource = closePrice;


    if (currentSource > previousFilter)

        Filter[i] = (currentSource - CombinedSmoothedRange[i] < previousFilter) ? previousFilter : currentSource - CombinedSmoothedRange[i];

    else

        Filter[i] = (currentSource + CombinedSmoothedRange[i] > previousFilter) ? previousFilter : currentSource + CombinedSmoothedRange[i];


    // Update upward/downward counters

    if (Filter[i] > Filter[i + 1])

        Upward[i] = Upward[i + 1] + 1;

    else

        Upward[i] = 0;


    if (Filter[i] < Filter[i + 1])

        Downward[i] = Downward[i + 1] + 1;

    else

        Downward[i] = 0;


    // Generate signals

    bool longCond = (closePrice > Filter[i] && closePrice > prevClosePrice && Upward[i] > 0) || (closePrice > Filter[i] && closePrice < prevClosePrice && Upward[i] > 0);

    bool shortCond = (closePrice < Filter[i] && closePrice < Filter[i + 1] && Downward[i] > 0) || (closePrice < Filter[i] && closePrice > prevClosePrice && Downward[i] > 0);


    // Order management

    if (longCond)

    {

        if (PositionsTotal() == 0 || (PositionSelect(Symbol()) && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL))

        {

            CloseAllPositions();

            double sl = iLow(NULL, 0, iLowest(NULL, 0, MODE_LOW, 5, 2));

            double tp = closePrice + (closePrice - sl); // Example TP, you can set your own logic

            double lotSize = CalculateLotSize(closePrice, sl);

            if (lotSize > 0.01)

            {

                OpenOrder(ORDER_TYPE_BUY, lotSize, closePrice, sl, tp);

                SendNotification("Buy position opened for XAUUSD");

            }

        }

    }

    else if (shortCond)

    {

        if (PositionsTotal() == 0 || (PositionSelect(Symbol()) && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY))

        {

            CloseAllPositions();

            double sl = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 5, 2));

            double tp = closePrice - (sl - closePrice); // Example TP, you can set your own logic

            double lotSize = CalculateLotSize(closePrice, sl);

            if (lotSize > 0.01)

            {              OpenOrder(ORDER_TYPE_SELL, lotSize, closePrice, sl, tp);        SendNotification("Sell position opened for XAUUSD")    }



    // Close trade if the buy or sell condition is not valid anymore

    if ((PositionsTotal() > 0 && PositionSelect(Symbol())))

    {

        double entryPrice = PositionGetDouble(POSITION_PRICE_OPEN);

        double currentPrice = closePrice;

        bool isBuy = PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY;

        bool isSell = PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL;


        if ((isBuy && (!longCond && currentPrice >= entryPrice)) || 

            (isSell && (!shortCond && currentPrice <= entryPrice)))

        {

            CloseAllPositions();

            SendNotification("Position closed due to signal disappearance or invalidation.");

        }

    }

}
Standard Deviation - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
Standard Deviation — value of the market volatility measurement. This indicator describes the range of price fluctuations relative to Moving...
 

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.

 

there is no "OpenOrder" function, and you are missing semicolon & closing braces on this part to close the else if:


    else if (shortCond)

    {

        if (PositionsTotal() == 0 || (PositionSelect(Symbol()) && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY))

        {

            CloseAllPositions();

            double sl = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 5, 2));

            double tp = closePrice - (sl - closePrice); // Example TP, you can set your own logic

            double lotSize = CalculateLotSize(closePrice, sl);

            if (lotSize > 0.01)

            {              OpenOrder(ORDER_TYPE_SELL, lotSize, closePrice, sl, tp);        SendNotification("Sell position opened for XAUUSD")    }
 
Sergey Golubev #:

When you post code please use the CODE button (Alt-S)!

Thank you.

Will it remove the unbalanced parentheses error of I press Alt-S. And also thanks for your reply am expecting your response
 
Conor Mcnamara #:

there is no "OpenOrder" function, and you are missing semicolon & closing braces on this part to close the else if:


Can you help me with a screenshot of where you said I will put semicolon and closing brace. I will really appreciate
 
Muhammed Olalekan #:
Can you help me with a screenshot of where you said I will put semicolon and closing brace. I will really appreciate
Or you help me edit that part of the code, it is really frustrating
 

Do never ever ever ever use multiple statements on a single line. Even though the language allows it, it makes more difficult to debug your code.


This is bad:

    else if (shortCond)

    {

        if (PositionsTotal() == 0 || (PositionSelect(Symbol()) && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY))

        {

            CloseAllPositions();

            double sl = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 5, 2));

            double tp = closePrice - (sl - closePrice); // Example TP, you can set your own logic

            double lotSize = CalculateLotSize(closePrice, sl);

            if (lotSize > 0.01)

            {              OpenOrder(ORDER_TYPE_SELL, lotSize, closePrice, sl, tp);        SendNotification("Sell position opened for XAUUSD")    } // → THIS IS A BAD PRACTICE, you're missing a semicolon and a brace here


This is good:


    else if (shortCond)

    {

        if (PositionsTotal() == 0 || (PositionSelect(Symbol()) && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY))

        {

            CloseAllPositions();

            double sl = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 5, 2));

            double tp = closePrice - (sl - closePrice); // Example TP, you can set your own logic

            double lotSize = CalculateLotSize(closePrice, sl);

            if (lotSize > 0.01)

            {              OpenOrder(ORDER_TYPE_SELL, lotSize, closePrice, sl, tp);
        		   SendNotification("Sell position opened for XAUUSD");  // fixed a semicolon missing here  
            } // now you see there's a brace missing here aswell
	}
 
Emanuel Cavalcante Amorim Filho #:

Do never ever ever ever use multiple statements on a single line. Even though the language allows it, it makes more difficult to debug your code.


This is bad:


This is good:


will update it now, thanks I hope it resolved the issue