Why does it give an error in an if, in Metatader5 when executing stoploss?

The code gives me an error on lines 143 and 153, within the stoploss. I have tried to correct it but when I change the code I get more errors. Please who can help me

// Include the definition of OrderType and order types
#include <TradeTrade.mqh>

//+------------------------------------------------------------------+
//|                                                      martin2.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property strict

// Include the definition of SELECT_BY_POS
#define SELECT_BY_POS 0

// Inputs
input int RSIPeriod = 14;                      // RSI period
input double OverboughtLevel = 70;             // Overbought level
input double OversoldLevel = 30;               // Oversold level
input double InitialLotSize = 0.01;            // Initial lot size
input double MartingaleMultiplier = 2.0;       // Martingale multiplier
input double StopLossPercentage = 30.0;        // Stop loss percentage

// Global variables
int orderCount = 0;                             // Order counter

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    double rsi = iRSI(Symbol(), 0, RSIPeriod, 0); // Get current RSI value from bar 0
    
    double currentBid = SymbolInfoDouble(_Symbol, SYMBOL_BID); // Get current Bid price
    double currentAsk = SymbolInfoDouble(_Symbol, SYMBOL_ASK); // Get current Ask price

    // Check if RSI is above the overbought level
    if (rsi > OverboughtLevel)
    {
        // Calculate lot size for this order
        double lotSize = CalculateLotSize();

        // Structures for request and result of the operation
        MqlTradeRequest request;
        MqlTradeResult result;
        
        // Fill the sell request
        request.action = TRADE_ACTION_DEAL;
        request.symbol = Symbol();
        request.volume = lotSize;
        request.type = ORDER_TYPE_SELL;
        request.price = currentBid; // Use current Bid price
        request.sl = CalculateStopLoss(currentBid); // Calculate stop loss using Bid price
        request.comment = "Martingale RSI";
        request.type_time = ORDER_TIME_GTC;
        request.magic = 123456;
        request.deviation = 20;

        // Send the sell order
        if (OrderSend(request, result))
        {
            orderCount++; // Increment order counter
        }
        else
        {
            Print("Error opening sell order: ", GetLastError());
        }
    }

    // Check if RSI is below the oversold level
    if (rsi < OversoldLevel)
    {
        // Calculate lot size for this order
        double lotSize = CalculateLotSize();

        // Structures for request and result of the operation
        MqlTradeRequest request;
        MqlTradeResult result;

        // Fill the buy request
        request.action = TRADE_ACTION_DEAL;
        request.symbol = Symbol();
        request.volume = lotSize;
        request.type = ORDER_TYPE_BUY;
        request.price = currentAsk; // Use current Ask price
        request.sl = CalculateStopLoss(currentAsk); // Calculate stop loss using Ask price
        request.comment = "Martingale RSI";
        request.type_time = ORDER_TIME_GTC;
        request.magic = 123456;
        request.deviation = 20;

        // Send the buy order
        if (OrderSend(request, result))
        {
            orderCount++; // Increment order counter
        }
        else
        {
            Print("Error opening buy order: ", GetLastError());
        }
    }
}

//+------------------------------------------------------------------+
//| Function to calculate lot size                                   |
//+------------------------------------------------------------------+
double CalculateLotSize()
{
    double lotSize = InitialLotSize * MathPow(MartingaleMultiplier, orderCount);
    return lotSize;
}

//+------------------------------------------------------------------+
//| Function to calculate stop loss                                  |
//+------------------------------------------------------------------+
double CalculateStopLoss(double entryPrice)
{
    double stopLossPrice;

    int totalOrders = OrdersTotal(); // Get total number of orders

    // Check if there are open orders
    if (totalOrders == 0)
    {
        Print("Error: No open orders.");
        return 0;
    }

    // Select the last order using the order number and selection mode
    if (!OrderSelect(totalOrders - 1, SELECT_BY_POS))
    {
        Print("Error selecting order.");
        return 0;
    }

    // Calculate stop loss distance in points
    double stopLossDistance = entryPrice * StopLossPercentage / 100.0 / _Point;

    // Calculate order type of the last order
    int orderType

The code is an experiment of a martigale code with rsi but with a stoploss of 30%. The error seems to appear due to a logic error, but I don’t understand well. maybe it’s syntax

New contributor

ulices is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật