fix ea error please

 
// Declare global variables
extern double LotSize = 0.01; // initial lot size
double MaxLotSize = 0.05; // maximum lot size
double MinLotSize = 0.01; // minimum lot size
double RiskPercentage = 2.0; // risk percentage per trade
double TakeProfit = 0.0; // take profit level
double StopLoss = 0.0; // stop loss level
double TrailingStop = 0.0; // trailing stop level
bool NewsFilter = true; // enable news filter

// Declare function to calculate lot size based on account balance and risk percentage
double CalculateLotSize() {
    double AccountBalance = AccountBalance();
    double TradeRisk = AccountBalance * (RiskPercentage / 100.0);
    double PipValue = MarketInfo(Symbol(), MODE_TICKVALUE);
    double LotSize = TradeRisk / (PipValue * StopLoss);
    LotSize = NormalizeDouble(LotSize, 2);
    LotSize = MathMax(MinLotSize, LotSize);
    LotSize = MathMin(MaxLotSize, LotSize);
    return LotSize;

// Declare function to check news events
bool CheckNewsFilter() {
    if (NewsFilter) {
        int Impact = NewsImpact("USD", true, true);
        if (Impact > 2) {
            Print("News filter triggered, no trade allowed.");
            return false;
        }
    }
    return true;
}

// Declare function to manage trades
void ManageTrades() {
    for (int i = OrdersTotal() - 1; i >= 0; i--) {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
            if (OrderSymbol() == Symbol()) {
                if (OrderType() == OP_BUY) {
                    if (OrderProfit() >= (OrderLots() * TakeProfit)) {
                        if (OrderClose(OrderTicket(), OrderLots(), Bid, 3)) {
                            Print("Buy trade closed at take profit level.");
                        }
                    } else if (OrderStopLoss() != StopLoss && OrderStopLoss() > 0) {
                        if (OrderModify(OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0)) {
                            Print("Buy trade stop loss modified.");
                        }
                    } else if (TrailingStop > 0 && Bid - OrderOpenPrice() > TrailingStop * Point) {
                        double NewStopLoss = Bid - TrailingStop * Point;
                        NewStopLoss = MathMax(OrderStopLoss(), NewStopLoss);
                        if (OrderModify(OrderTicket(), OrderOpenPrice(), NewStopLoss, OrderTakeProfit(), 0)) {
                            Print("Buy trade trailing stop activated.");
                        }
                    }
                } else if (OrderType() == OP_SELL) {
                    if (OrderProfit() >= (OrderLots() * TakeProfit)) 
                        if (OrderClose(OrderTicket(), OrderLots(), Ask, 3)) {
                            Print("Sell trade closed at take profit level.");
                        }
                    } else if (OrderStopLoss() != StopLoss && OrderStopLoss() > 0) {
                        if (OrderModify(OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0)) {
                            Print("Sell trade stop loss modified.");
                        }
                    } else if (TrailingStop > 0 && OrderOpenPrice() - Ask > TrailingStop * Point) {
                        double NewStopLoss = Ask + TrailingStop * Point;
                        NewStopLoss = MathMin(OrderStopLoss(), NewStopLoss);
                        if (OrderModify(OrderTicket(), Order

 

Forum on trading, automated trading systems and testing trading strategies

BUYSTOP, SELLSTOP orders getting Ordersend error 130

Alain Verleyen, 2023.03.14 22:31

Please start to post in the correct section if you need help.

There is an MT4/mql4 section at the bottom of the forum.


 
  1. Why did you post your MT4 question in the 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? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. double CalculateLotSize() {                  <<<<<<<<<<<<< Opening brace.              
        double AccountBalance = AccountBalance();
        double TradeRisk = AccountBalance * (RiskPercentage / 100.0);
        double PipValue = MarketInfo(Symbol(), MODE_TICKVALUE);
        double LotSize = TradeRisk / (PipValue * StopLoss);
        LotSize = NormalizeDouble(LotSize, 2);
        LotSize = MathMax(MinLotSize, LotSize);
        LotSize = MathMin(MaxLotSize, LotSize);
        return LotSize;
                                                 <<<<<<<<<<<<< Where is the closing brace?
    // Declare function to check news events
    bool CheckNewsFilter() {
    Don't post code that will not even compile.