На Backtest все в порядке, а при Forwardtest ни одного исполнения

 

Здравствуйте. Не могу понять, почему при Backtest експерт совершает десятки сделок в день, а при проведении Forwardtest на демо - не совершает ни одной? За любую помощь буду благодарен. Заранее спасибо.


// Function to place a sell order
bool PlaceSellOrder() {
    double previousLow = iLow(NULL, 0, 1); // Low of the previous candle
    double currentPrice = iLow(NULL, 0, 0); // Current candle low (dynamic)

    // Check if current price is 1 point or more below the previous candle's low
    if (currentPrice < previousLow - Point) {
        double price = currentPrice; // Current price for the sell order
        double sl = price + StopLossPoints * Point;
        double tp = price - TakeProfitPoints * Point;
        
        int ticket = OrderSend(Symbol(), OP_SELL, LotSize, price, Slippage, sl, tp, "", 0, 0, Red);
        if (ticket < 0) {
            LogError("Sell order failed", GetLastError());
            return false;
        }
        return true;
    }
    return false; // No sell order placed if condition is not met
}

// Function to place a buy order
bool PlaceBuyOrder() {
    double previousHigh = iHigh(NULL, 0, 1); // High of the previous candle
    double currentPrice = iHigh(NULL, 0, 0); // Current candle high (dynamic)

    // Check if current price is 1 point or more above the previous candle's high
    if (currentPrice > previousHigh + Point) {
        double price = currentPrice; // Current price for the buy order
        double sl = price - StopLossPoints * Point;
        double tp = price + TakeProfitPoints * Point;

        int ticket = OrderSend(Symbol(), OP_BUY, LotSize, price, Slippage, sl, tp, "", 0, 0, Blue);
        if (ticket < 0) {
            LogError("Buy order failed", GetLastError());
            return false;
        }
        return true;
    }
    return false; // No buy order placed if condition is not met
}

// The main function where the EA logic is executed
void OnTick() {
    // Check if there are open orders
    if (OrdersTotal() > 0) {
        // Manage trailing stop and breakeven if the trade is in profit
        ManageOpenPositions();
        return;
    }

    // Check Sell conditions
    if (CheckSellConditions()) {
        PlaceSellOrder();
    }

    // Check Buy conditions
    if (CheckBuyConditions()) {
        PlaceBuyOrder();
    }
}
 
Vadym Dubenko:

Здравствуйте. Не могу понять, почему при Backtest експерт совершает десятки сделок в день, а при проведении Forwardtest на демо - не совершает ни одной? За любую помощь буду благодарен. Заранее спасибо.


а что в журнал пишет ?

и кстати, 1) SL TP надо нормализовать 2) покупают по ask, продают по bid, а не по high/low текущей свечи :-)

 
Maxim Kuznetsov #:
а что в журнал пишет ?

А вот в том-то и дело, что журнал просто молчит. Пусто и в журнале, и в Эксперте. Был вчера момент, когда я повставлял принты на все условия входа в сделку и он пару сделок выполнил. Но потом снова замолчал. Это меня еще больше запутало.

P.S. Мне нужно весь код выложить для понимания структуры или это будет лишним?
 
Maxim Kuznetsov #:
2) покупают по ask, продают по bid, а не по high/low текущей свечи :-)
// Function to place a sell order (on bid price)
bool PlaceSellOrder() {
    double currentPrice = Bid; // Use the Bid price for sell orders

    // Check if current price is 1 point or more below the previous candle's low
    double previousLow = iLow(NULL, 0, 1);
    if (currentPrice < previousLow - Point) {
        double sl = currentPrice + StopLossPoints * Point;
        double tp = currentPrice - TakeProfitPoints * Point;
        
        int ticket = OrderSend(Symbol(), OP_SELL, LotSize, currentPrice, Slippage, sl, tp, "", 0, 0, Red);
        if (ticket < 0) {
            LogError("Sell order failed", GetLastError());
            return false;
        }
        return true;
    }
    return false; // No sell order placed if condition is not met
}

// Function to place a buy order (on ask price)
bool PlaceBuyOrder() {
    double currentPrice = Ask; // Use the Ask price for buy orders

    // Check if current price is 1 point or more above the previous candle's high
    double previousHigh = iHigh(NULL, 0, 1);
    if (currentPrice > previousHigh + Point) {
        double sl = currentPrice - StopLossPoints * Point;
        double tp = currentPrice + TakeProfitPoints * Point;

        int ticket = OrderSend(Symbol(), OP_BUY, LotSize, currentPrice, Slippage, sl, tp, "", 0, 0, Blue);
        if (ticket < 0) {
            LogError("Buy order failed", GetLastError());
            return false;
        }
        return true;
    }
    return false; // No buy order placed if condition is not met
}
 
Maxim Kuznetsov #:
1) SL TP надо нормализовать


// External variables that can be set by the trader
extern double TakeProfitPoints = 50;       // Take Profit in points
extern double StopLossPoints = 50;          // Stop Loss in points
extern double BreakevenPoints = 50;         // Points in profit when Stop Loss is moved to Breakeven
extern double TrailStopDistance = 50;       // Trailing Stop distance in points
extern double MinPriceMove = 50;            // Minimum price move in consecutive candles before entering
extern double LotSize = 0.01;                // Fixed lot size
extern int Slippage = 20; // Define slippage (in points)
Или вы что-то другое имели ввиду?
 
Maxim Kuznetsov #:
2) покупают по ask, продают по bid, а не по high/low текущей свечи :-)
Это изменение решило проблему. Спасибо большое!
 
Maxim Kuznetsov #:
1) SL TP надо нормализовать

Я нашел о чем вы говорите. Спасибо за совет. Финальная версия кода выглядит теперь вот так:


// Function to place a sell order using MqlTick for Bid price with normalized stop loss and take profit
bool PlaceSellOrder() {
    MqlTick tick;
    SymbolInfoTick(_Symbol, tick); // Get the latest tick data
    
    double price = tick.bid; // Use Bid price from the terminal, no need to normalize
    double sl = NormalizePrice(price + StopLossPoints * Point); // Normalize Stop Loss
    double tp = NormalizePrice(price - TakeProfitPoints * Point); // Normalize Take Profit
    double lotSize = NormalizeLots(LotSize); // Normalize lot size
    
    if (lotSize == 0) {
        Print("Error: Lot size too small.");
        return false;
    }
    
    int ticket = OrderSend(Symbol(), OP_SELL, lotSize, price, Slippage, sl, tp, "", 0, 0, Red);
    if (ticket < 0) {
        LogError("Sell order failed", GetLastError());
        return false;
    }
    return true;
}

// Function to place a buy order using MqlTick for Ask price with normalized stop loss and take profit
bool PlaceBuyOrder() {
    MqlTick tick;
    SymbolInfoTick(_Symbol, tick); // Get the latest tick data
    
    double price = tick.ask; // Use Ask price from the terminal, no need to normalize
    double sl = NormalizePrice(price - StopLossPoints * Point); // Normalize Stop Loss
    double tp = NormalizePrice(price + TakeProfitPoints * Point); // Normalize Take Profit
    double lotSize = NormalizeLots(LotSize); // Normalize lot size
    
    if (lotSize == 0) {
        Print("Error: Lot size too small.");
        return false;
    }
    
    int ticket = OrderSend(Symbol(), OP_BUY, lotSize, price, Slippage, sl, tp, "", 0, 0, Blue);
    if (ticket < 0) {
        LogError("Buy order failed", GetLastError());
        return false;
    }
    return true;
}