# Multi-Timeframe Intelligence

## The Problem with Traditional EAs

Most Expert Advisors **require** you to run them on a specific chart timeframe (e.g., M5 chart for M5 strategy). This creates several issues:

❌ **Chart clutter** if you prefer different timeframe displays\
❌ **Multiple charts needed** for different strategies\
❌ **Confusion** when managing multiple EAs\
❌ **Inflexibility** in your workspace layout

## BananaEA's Solution: Timeframe Independence

**Run the EA on ANY chart timeframe** while it executes trades based on the **optimal strategy timeframe**.

✅ **100% flexibility** in chart display preference\
✅ **One chart** can run multiple strategy timeframes\
✅ **Optimal performance** regardless of display\
✅ **Better user experience** and workspace organization

***

## How It Works

### **Traditional EA Limitation:**

```
EA on M5 chart → Reads M5 data → Executes on M5
EA on H1 chart → ERROR: Strategy designed for M5!
```

### **BananaEA Smart System:**

```
EA on ANY chart → Reads optimal timeframe data → Executes correctly
EA on M5 chart → Works perfectly ✅
EA on H1 chart → Works perfectly ✅
EA on D1 chart → Works perfectly ✅
```

### **Technical Implementation:**

BananaEA uses **cross-timeframe data access functions** to read candle information from the optimal strategy timeframe, regardless of what chart it's running on.

**Key Functions:**

```mql4
double GetStrategyHigh(int shift)
// Returns High price from strategy timeframe

double GetStrategyLow(int shift)
// Returns Low price from strategy timeframe

double GetStrategyOpen(int shift)
// Returns Open price from strategy timeframe

double GetStrategyClose(int shift)
// Returns Close price from strategy timeframe

datetime GetStrategyTime(int shift)
// Returns bar time from strategy timeframe
```

***

## Supported Strategy Timeframes

BananaEA supports these **predefined strategy timeframes** for optimal performance:

### **M5 (5-Minute) Strategy**

**Best For:**

* Day trading and scalping
* Quick decision-making
* High-frequency opportunities
* Active market sessions

**Recommended Charts:**

* M5 (traditional)
* M15 (less clutter)
* H1 (clean view)

### **M15 (15-Minute) Strategy**

**Best For:**

* Swing trading
* Medium-term positions
* Balanced approach
* Multiple daily signals

**Recommended Charts:**

* M15 (traditional)
* H1 (cleaner view)
* H4 (big picture)

### **H1 (1-Hour) Strategy**

**Best For:**

* Position trading
* Lower frequency
* Stable conditions
* Long-term holds

**Recommended Charts:**

* H1 (traditional)
* H4 (less clutter)
* D1 (macro view)

***

## Configuration

### **StrategyTimeframe Parameter**

```
StrategyTimeframe = PERIOD_M5   // Execute on M5 signals
StrategyTimeframe = PERIOD_M15  // Execute on M15 signals
StrategyTimeframe = PERIOD_H1   // Execute on H1 signals
```

### **Chart Timeframe Independence**

You can run the EA on **any chart timeframe** regardless of StrategyTimeframe setting:

**Example Configurations:**

```
Configuration 1: M5 Strategy on M5 Chart (Traditional)
StrategyTimeframe = PERIOD_M5
Chart Display = M5
Result: Standard setup, works perfectly ✅

Configuration 2: M5 Strategy on H1 Chart (Smart!)
StrategyTimeframe = PERIOD_M5
Chart Display = H1
Result: Trades on M5 signals, cleaner chart view ✅

Configuration 3: H1 Strategy on M15 Chart
StrategyTimeframe = PERIOD_H1
Chart Display = M15
Result: Trades on H1 signals, more detailed view ✅
```

***

## Real-World Benefits

### **Workspace Organization**

**Traditional Approach:**

* M5 strategy = must use M5 chart
* M15 strategy = must use M15 chart
* H1 strategy = must use H1 chart
* **= 3 charts minimum for one symbol**

**BananaEA Approach:**

* M5 strategy = ANY chart timeframe
* M15 strategy = ANY chart timeframe
* H1 strategy = ANY chart timeframe
* **= 1 chart can run all strategies**

### **Visual Clarity**

**Scenario:** You run M5 strategy but prefer cleaner H1 charts for analysis

**Traditional EA:**

```
❌ Forced to view cluttered M5 chart
❌ Difficult to see larger trends
❌ More screen real estate needed
```

**BananaEA:**

```
✅ View clean H1 chart
✅ EA still trades on M5 signals
✅ Best of both worlds
```

### **Multi-Strategy Portfolios**

**Advanced Users:** Run multiple strategy timeframes on different charts for portfolio diversification

```
Chart 1 (M5): BananaEA with StrategyTimeframe = M5
Chart 2 (H1): BananaEA with StrategyTimeframe = H1
Chart 3 (D1): BananaEA with StrategyTimeframe = D1

All visible in organized workspace ✅
Different signal frequencies ✅
Independent risk management ✅
```

***

## Technical Details

### **Data Synchronization**

The EA uses **iTime(), iOpen(), iHigh(), iLow(), iClose()** functions with explicit timeframe parameters:

```mql4
// Example: Reading M5 data regardless of chart timeframe
double high = iHigh(Symbol(), PERIOD_M5, shift);
double low = iLow(Symbol(), PERIOD_M5, shift);
datetime barTime = iTime(Symbol(), PERIOD_M5, shift);
```

### **Bar Completion Detection**

The EA correctly detects new bar formation on the **strategy timeframe**, not the chart timeframe:

```mql4
static datetime lastBarTime = 0;
datetime currentBarTime = iTime(Symbol(), StrategyTimeframe, 0);

if(currentBarTime != lastBarTime) {
    // New bar on strategy timeframe
    lastBarTime = currentBarTime;
    // Process signals
}
```

### **Performance Considerations**

**Cross-timeframe data access is highly efficient:**

* Minimal CPU overhead
* Data cached by MetaTrader
* No additional broker requests
* Negligible performance impact

***

## Best Practices

### **1. Choose Chart Timeframe for Analysis**

Use chart timeframe that helps YOUR decision-making:

**Prefer Detailed View:**

```
StrategyTimeframe = PERIOD_H1
Chart Display = M15 or H1
```

**Prefer Clean View:**

```
StrategyTimeframe = PERIOD_M5
Chart Display = H1 or H4
```

### **2. Match Presets to Strategy Timeframe**

Ensure your chosen preset is optimized for your StrategyTimeframe:

```
StrategyTimeframe = PERIOD_M5
→ Use M5-optimized preset from:
   https://my.itradeaims.net/latest-optimization-sets/
```

### **3. Consistency Across Symbols**

For portfolio consistency, use same chart timeframe across symbols:

```
DAX Chart (H1): StrategyTimeframe = M5
NAS100 Chart (H1): StrategyTimeframe = M5
US30 Chart (H1): StrategyTimeframe = M5

Easy visual comparison ✅
Consistent workspace layout ✅
```

***

## Common Questions

### **"Does this affect performance?"**

**No.** Cross-timeframe data access uses MetaTrader's built-in caching. Performance is identical to running on native timeframe.

### **"Can I switch chart timeframes while EA is running?"**

**Yes.** The EA will continue to trade based on StrategyTimeframe regardless of chart display changes.

### **"What if I change StrategyTimeframe parameter?"**

The EA will restart signal detection based on new timeframe. Existing trades are not affected.

### **"Can I run multiple instances with different StrategyTimeframes?"**

**Yes.** Use different Magic Numbers for each instance:

```
Instance 1: Magic = 12345, StrategyTimeframe = M5
Instance 2: Magic = 12346, StrategyTimeframe = H1
```

***

## Troubleshooting

### **Warning: Cross-Timeframe Access**

**Message:**

```
[WARNING] Running EA on H1 chart but strategy uses M5 timeframe
```

**Meaning:** Informational only. System is working correctly.

**Action:** None required. This confirms smart timeframe system is active.

### **No Signals Appearing**

**Check:**

1. StrategyTimeframe is set correctly
2. Sufficient historical data loaded for strategy timeframe
3. Market is within trading hours
4. Chart symbol matches EA configuration

***

## Future Enhancements 🚀

### **Coming Soon:**

* **Automatic timeframe optimization** based on market conditions
* **Multi-timeframe signal confirmation** (e.g., M5 + H1 agreement)
* **Adaptive timeframe switching** based on volatility
* **Visual indicators** showing active strategy timeframe

***

**Multi-Timeframe Intelligence gives you the freedom to organize your workspace YOUR way** while BananaEA handles the technical complexity behind the scenes.

**Next:**

* [Strategy Presets Guide →](https://github.com/itradeaims/bananaEA-dev/blob/dev/gitbook/smart-features/strategy-presets.md)
* [Advanced Risk Management →](https://itradeaims.gitbook.io/banana-ea/smart-features/overview/risk-management)
* [Smart Trailing Stop →](https://itradeaims.gitbook.io/banana-ea/smart-features/overview/smart-trailing-stop)
