#include <iostream> #include <vector> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; // ===== SIMPLE VERSION FOR QUICK TESTING ============================ struct Candle { double open, high, low, close; }; struct Trade { bool isBuy; double entry, sl, tp; double profit; }; class SimpleTester { private: vector<Candle> generateTestData(int count) { vector<Candle> candles; double price = 100.0; srand(time(0)); for(int i = 0; i < count; i++) { Candle c; c.open = price; // Random movement double change = ((rand() % 100) - 50) / 100.0; price += change; // Create candle with random range double range = abs(change) * 2.0 + 0.1; c.high = price + range * 0.3; c.low = price - range * 0.2; c.close = price; // Occasionally create engulfing patterns if(i > 0 && rand() % 20 == 0) { if(rand() % 2 == 0) { // Bullish engulfing c.open = candles.back().close - 0.2; c.close = candles.back().open + 0.3; } else { // Bearish engulfing c.open = candles.back().close + 0.2; c.close = candles.back().open - 0.3; } } candles.push_back(c); price = c.close; } return candles; } bool isBullEngulfing(const Candle& curr, const Candle& prev) { return (prev.close < prev.open) && // Previous bearish (curr.close > curr.open) && // Current bullish (curr.open <= prev.close) && // Engulfing condition (curr.close >= prev.open); } bool isBearEngulfing(const Candle& curr, const Candle& prev) { return (prev.close > prev.open) && // Previous bullish (curr.close < curr.open) && // Current bearish (curr.open >= prev.close) && // Engulfing condition (curr.close <= prev.open); } double calculateSMA(const vector<Candle>& candles, int period, int index) { if(index < period) return 0.0; double sum = 0.0; for(int i = 0; i < period; i++) { sum += candles[index - i].close; } return sum / period; } public: void runTest() { cout << "=== VOLATILITY 100 ENGULFING EA TEST ===\n"; cout << "Generating test data...\n"; vector<Candle> candles = generateTestData(200); vector<Trade> trades; // Parameters double tpPoints = 30.0; double slPoints = 30.0; double pointValue = 0.01; int maxTrades = 3; int smaPeriod = 9; int totalTrades = 0; int winningTrades = 0; double totalProfit = 0.0; cout << "\nStarting simulation...\n"; for(int i = 2; i < candles.size(); i++) { Candle curr = candles[i]; Candle prev = candles[i-1]; // Calculate SMA double sma = calculateSMA(candles, smaPeriod, i); // Check for BUY signal if(trades.size() < maxTrades) { if(isBullEngulfing(curr, prev) && sma < curr.close) { Trade trade; trade.isBuy = true; trade.entry = curr.close; trade.sl = curr.low - (slPoints * pointValue); trade.tp = curr.close + (tpPoints * pointValue); // Check if trade would hit TP/SL double profit = 0.0; for(int j = i + 1; j < candles.size() && j < i + 50; j++) { if(candles[j].high >= trade.tp) { profit = tpPoints; // TP hit break; } else if(candles[j].low <= trade.sl) { profit = -slPoints; // SL hit break; } } trade.profit = profit; trades.push_back(trade); cout << "BUY Signal at candle " << i << " Entry: " << trade.entry << " Profit: " << profit << " points\n"; totalTrades++; totalProfit += profit; if(profit > 0) winningTrades++; } // Check for SELL signal else if(isBearEngulfing(curr, prev) && sma > curr.close) { Trade trade; trade.isBuy = false; trade.entry = curr.close; trade.sl = curr.high + (slPoints * pointValue); trade.tp = curr.close - (tpPoints * pointValue); // Check if trade would hit TP/SL double profit = 0.0; for(int j = i + 1; j < candles.size() && j < i + 50; j++) { if(candles[j].low <= trade.tp) { profit = tpPoints; // TP hit break; } else if(candles[j].high >= trade.sl) { profit = -slPoints; // SL hit break; } } trade.profit = profit; trades.push_back(trade); cout << "SELL Signal at candle " << i << " Entry: " << trade.entry << " Profit: " << profit << " points\n"; totalTrades++; totalProfit += profit; if(profit > 0) winningTrades++; } } } // Print results cout << "\n=== TEST RESULTS ===\n"; cout << "Total Trades: " << totalTrades << endl; cout << "Winning Trades: " << winningTrades << endl; cout << "Losing Trades: " << (totalTrades - winningTrades) << endl; if(totalTrades > 0) { double winRate = (winningTrades * 100.0) / totalTrades; cout << "Win Rate: " << winRate << "%\n"; cout << "Total Profit: " << totalProfit << " points\n"; cout << "Average Profit per Trade: " << (totalProfit / totalTrades) << " points\n"; // Calculate profit factor double grossProfit = 0.0; double grossLoss = 0.0; for(const auto& trade : trades) { if(trade.profit > 0) grossProfit += trade.profit; else grossLoss += abs(trade.profit); } if(grossLoss > 0) { double profitFactor = grossProfit / grossLoss; cout << "Profit Factor: " << profitFactor << endl; } } cout << "\n=== TRADE EXAMPLES ===\n"; for(int i = 0; i < min(5, (int)trades.size()); i++) { cout << "Trade " << (i+1) << ": " << (trades[i].isBuy ? "BUY" : "SELL") << " Profit: " << trades[i].profit << " points\n"; } } }; int main() { SimpleTester tester; tester.runTest(); return 0; }
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
// ===== SIMPLE VERSION FOR QUICK TESTING ============================
struct Candle {
double open, high, low, close;
};
struct Trade {
bool isBuy;
double entry, sl, tp;
double profit;
};
class SimpleTester {
private:
vector<Candle> generateTestData(int count) {
vector<Candle> candles;
double price = 100.0;
srand(time(0));
for(int i = 0; i < count; i++) {
Candle c;
c.open = price;
// Random movement
double change = ((rand() % 100) - 50) / 100.0;
price += change;
// Create candle with random range
double range = abs(change) * 2.0 + 0.1;
c.high = price + range * 0.3;
c.low = price - range * 0.2;
c.close = price;
// Occasionally create engulfing patterns
if(i > 0 && rand() % 20 == 0) {
if(rand() % 2 == 0) {
// Bullish engulfing
c.open = candles.back().close - 0.2;
c.close = candles.back().open + 0.3;
} else {
// Bearish engulfing
c.open = candles.back().close + 0.2;
c.close = candles.back().open - 0.3;
}
}
candles.push_back(c);
price = c.close;
}
return candles;
}
bool isBullEngulfing(const Candle& curr, const Candle& prev) {
return (prev.close < prev.open) && // Previous bearish
(curr.close > curr.open) && // Current bullish
(curr.open <= prev.close) && // Engulfing condition
(curr.close >= prev.open);
}
bool isBearEngulfing(const Candle& curr, const Candle& prev) {
return (prev.close > prev.open) && // Previous bullish
(curr.close < curr.open) && // Current bearish
(curr.open >= prev.close) && // Engulfing condition
(curr.close <= prev.open);
}
double calculateSMA(const vector<Candle>& candles, int period, int index) {
if(index < period) return 0.0;
double sum = 0.0;
for(int i = 0; i < period; i++) {
sum += candles[index - i].close;
}
return sum / period;
}
public:
void runTest() {
cout << "=== VOLATILITY 100 ENGULFING EA TEST ===\n";
cout << "Generating test data...\n";
vector<Candle> candles = generateTestData(200);
vector<Trade> trades;
// Parameters
double tpPoints = 30.0;
double slPoints = 30.0;
double pointValue = 0.01;
int maxTrades = 3;
int smaPeriod = 9;
int totalTrades = 0;
int winningTrades = 0;
double totalProfit = 0.0;
cout << "\nStarting simulation...\n";
for(int i = 2; i < candles.size(); i++) {
Candle curr = candles[i];
Candle prev = candles[i-1];
// Calculate SMA
double sma = calculateSMA(candles, smaPeriod, i);
// Check for BUY signal
if(trades.size() < maxTrades) {
if(isBullEngulfing(curr, prev) && sma < curr.close) {
Trade trade;
trade.isBuy = true;
trade.entry = curr.close;
trade.sl = curr.low - (slPoints * pointValue);
trade.tp = curr.close + (tpPoints * pointValue);
// Check if trade would hit TP/SL
double profit = 0.0;
for(int j = i + 1; j < candles.size() && j < i + 50; j++) {
if(candles[j].high >= trade.tp) {
profit = tpPoints; // TP hit
break;
} else if(candles[j].low <= trade.sl) {
profit = -slPoints; // SL hit
break;
}
}
trade.profit = profit;
trades.push_back(trade);
cout << "BUY Signal at candle " << i
<< " Entry: " << trade.entry
<< " Profit: " << profit << " points\n";
totalTrades++;
totalProfit += profit;
if(profit > 0) winningTrades++;
}
// Check for SELL signal
else if(isBearEngulfing(curr, prev) && sma > curr.close) {
Trade trade;
trade.isBuy = false;
trade.entry = curr.close;
trade.sl = curr.high + (slPoints * pointValue);
trade.tp = curr.close - (tpPoints * pointValue);
// Check if trade would hit TP/SL
double profit = 0.0;
for(int j = i + 1; j < candles.size() && j < i + 50; j++) {
if(candles[j].low <= trade.tp) {
profit = tpPoints; // TP hit
break;
} else if(candles[j].high >= trade.sl) {
profit = -slPoints; // SL hit
break;
}
}
trade.profit = profit;
trades.push_back(trade);
cout << "SELL Signal at candle " << i
<< " Entry: " << trade.entry
<< " Profit: " << profit << " points\n";
totalTrades++;
totalProfit += profit;
if(profit > 0) winningTrades++;
}
}
}
// Print results
cout << "\n=== TEST RESULTS ===\n";
cout << "Total Trades: " << totalTrades << endl;
cout << "Winning Trades: " << winningTrades << endl;
cout << "Losing Trades: " << (totalTrades - winningTrades) << endl;
if(totalTrades > 0) {
double winRate = (winningTrades * 100.0) / totalTrades;
cout << "Win Rate: " << winRate << "%\n";
cout << "Total Profit: " << totalProfit << " points\n";
cout << "Average Profit per Trade: " << (totalProfit / totalTrades) << " points\n";
// Calculate profit factor
double grossProfit = 0.0;
double grossLoss = 0.0;
for(const auto& trade : trades) {
if(trade.profit > 0) grossProfit += trade.profit;
else grossLoss += abs(trade.profit);
}
if(grossLoss > 0) {
double profitFactor = grossProfit / grossLoss;
cout << "Profit Factor: " << profitFactor << endl;
}
}
cout << "\n=== TRADE EXAMPLES ===\n";
for(int i = 0; i < min(5, (int)trades.size()); i++) {
cout << "Trade " << (i+1) << ": "
<< (trades[i].isBuy ? "BUY" : "SELL")
<< " Profit: " << trades[i].profit << " points\n";
}
}
};
int main() {
SimpleTester tester;
tester.runTest();
return 0;
}=== VOLATILITY 100 ENGULFING EA TEST === Generating test data... Starting simulation... SELL Signal at candle 11 Entry: 99.86 Profit: -30 points BUY Signal at candle 12 Entry: 100.32 Profit: 30 points SELL Signal at candle 23 Entry: 99.63 Profit: 30 points === TEST RESULTS === Total Trades: 3 Winning Trades: 2 Losing Trades: 1 Win Rate: 66.6667% Total Profit: 30 points Average Profit per Trade: 10 points Profit Factor: 2 === TRADE EXAMPLES === Trade 1: SELL Profit: -30 points Trade 2: BUY Profit: 30 points Trade 3: SELL Profit: 30 points