Skip to product information
1 of 1

forexeasourcecodes

EX4 Chantika V6 Expert Advisor

EX4 Chantika V6 Expert Advisor

Regular price $0.00 USD
Regular price Sale price $0.00 USD
Sale Sold out
Quantity

The Chantika V6 Expert Advisor (EA) for MetaTrader 4 (MQL4) is a forex trading algorithm designed to trade currency pairs such as EURUSD, GBPUSD, and USDJPY. It employs a combination of technical indicators, time-based trading rules, and trailing stop mechanisms to place and manage trades. Below is a detailed explanation of how the EA trades, based on its code structure and logic.

1. Overview of Trading Strategy
The Chantika V6 EA uses a trend-following and breakout strategy with the following key components:

Indicators: It uses either Moving Averages (iMA) or Envelopes (iEnvelope) to generate buy/sell signals based on price breakouts.
Order Types: Places pending orders (Buy Stop and Sell Stop) to capture breakouts above or below key price levels.
Trade Management: Implements trailing stops and break-even mechanisms to manage open trades, along with timed closing to exit trades after a specified duration.
Risk Management: Supports money management (MM) with dynamic lot sizing based on account balance and risk percentage, as well as spread filtering to avoid trading in high-spread conditions.
Time Filter: Restricts trading to specific hours to avoid low-liquidity periods.

The EA is designed to trade within predefined parameters, adjusting its behavior based on the currency pair, spread, and market conditions.

2. Key Parameters and Settings
The EA has numerous configurable parameters that define its trading behavior. Below are the most critical ones:

Indicators:

IndicatorToUse: Determines whether to use Moving Average (0) or Envelopes (1) for signal generation.
MAPeriod and MAMethod: Define the Moving Average period and type (e.g., MAPeriod = 3, MAMethod = 3 for Exponential Moving Average).
Env_period, Env_deviation, Env_shift: Configure the Envelopes indicator (e.g., Env_period = 10, Env_deviation = 0.05).


Trade Parameters:

MaxTrades: Limits the number of open trades (default: 3).
StopLoss: Sets the stop-loss for pending orders (default: 200 points, equivalent to 20 pips on 5-digit brokers).
Limit: Distance for placing pending orders (default: 22 points).
Distance, NoTrade_Profit_Yet_Distance, InTrade_Profit_Distance: Control trailing stop distances.
NoTrade_Profit_Yet_Limit, NoTrade_Profit_Yet_StopLoss: Adjust settings for trades with low profit.


Risk Management:

Risk: Percentage of account balance to risk per trade (default: 10%).
UseMM: Enables/disables money management (default: TRUE).
FixedLots: Fixed lot size if UseMM is disabled (default: 0.01).
MaxSpread, MaxSpread_EU, MaxSpread_GU, MaxSpread_UJ: Maximum allowable spread for trading (e.g., 0.3 for general, 0.4 for EURUSD).


Trailing Stop and Break-Even:

Use_TrailingStep: Enables trailing stops (default: TRUE).
Start_Trailing_At: Profit level to start trailing (default: 2.9 pips).
TrailingStep: Step size for trailing stop (default: 0.3 pips).
Use_Set_BreakEven: Enables break-even (default: TRUE).
Set_BreakEvenAt: Profit level to set break-even (default: 2.3 pips).
LockPips: Pips to lock in at break-even (default: 0.3 pips).


Time-Based Rules:

StartHour, StartMinute, EndHour, EndMinute: Define trading hours (default: 00:00 to 23:59).
Timed_Closing: Enables time-based trade closure (default: TRUE).
Minutes_Buy, Minutes_Sell: Duration before closing buy/sell trades (default: 40 minutes).
Timed_Buy_TakeProfit, Timed_Sell_TakeProfit: Minimum profit for timed closure (default: -5 points).


Currency-Specific Filters:

Filter_EU, Filter_GU, Filter_UJ: Volatility filters for EURUSD, GBPUSD, and USDJPY (e.g., 130, 170, 190 points).
MaxSpreadPlusCommission_EU, MaxSpreadPlusCommission_GU, MaxSpreadPlusCommission_UJ: Spread plus commission limits for each pair.




3. Trading Logic
The EA's trading logic is implemented primarily in the start() function, with supporting functions for trade management and indicator calculations. Here's a step-by-step breakdown of how it trades:
a. Initialization (init() function)

Sets Global Variables:

Initializes G_digits_192 (symbol digits) and G_point_196 (point size).
Calculates lot step (Gi_204) and enforces minimum/maximum lot sizes (Gd_208, Gd_216).
Sets symbol-specific parameters (e.g., MaxSpread and Filter for EURUSD, GBPUSD, USDJPY).
Normalizes key parameters like MaxSpreadPlusCommission, Limit, Distance, and Filter to account for broker precision.


Commission Calculation:

Sets Gi_268 = FALSE to indicate no commission data initially. Later, it calculates commission (Gd_272) from historical orders in the start() function.



b. Signal Generation

The EA uses either Moving Average or Envelopes to generate signals:

Moving Average (IndicatorToUse = 0):

Calculates two MAs: one on PRICE_LOW and one on PRICE_HIGH with MAPeriod = 3 and MAMethod = 3 (EMA).
Signals are generated based on price crossing these MAs (logic described below).


Envelopes (IndicatorToUse = 1):

Uses iEnvelopes with Env_period = 10, Env_deviation = 0.05, and Env_shift = 0.
Lower band uses PRICE_HIGH, upper band uses PRICE_LOW (unusual configuration, potentially a bug; typically, both use PRICE_CLOSE).
Signals are generated when the price breaks below the lower band (buy) or above the upper band (sell).




Signal Logic:

Calculates the difference between the current bar’s high and low (Ld_172 = ihigh_68 - ilow_76).
If Ld_172 > Gd_256 (volatility exceeds the filter, e.g., 130 points for EURUSD), checks price position:

Buy Signal: If Ask indicator_high (price above the upper MA or Envelope band), sets Li_180 = 1.





c. Trade Placement

Conditions for Placing Trades:

Trades only if:

The number of open trades (count_184) is less than or equal to MaxTrades - 1 (default: 2).
A valid signal exists (Li_180 != 0).
The current spread (Ask - Bid) is less than MaxSpread (adjusted for broker precision).
The time filter (f0_4()) allows trading (within StartHour to EndHour).




Order Types:

Buy Stop: If Li_180 = -1, places a Buy Stop order at Ask + Gd_240 (Ask + Limit, default: 22 points) with a stop-loss at price_24 - 200 * Point (20 pips below).
Sell Stop: If Li_180 = 1, places a Sell Stop order at Bid - Gd_240 (Bid - Limit) with a stop-loss at price_24 + 200 * Point (20 pips above).
Uses OrderSend with slippage (G_slippage_264 = 3) and the calculated lot size (Ld_204).


Lot Size Calculation:

If UseMM = TRUE, calculates lot size as:
mqlLd_196 = AccountBalance() * AccountLeverage() * Gd_224;
Ld_204 = NormalizeDouble(Ld_196 / MarketInfo(Symbol(), MODE_LOTSIZE), Gi_204);
Ld_204 = MathMax(Gd_208, MathMin(Gd_216, Ld_204));

Gd_224 = Risk / 100.0 (e.g., 0.1 for 10% risk).
Ensures lot size is within MinLots and MaxLots.


If UseMM = FALSE, uses FixedLots (default: 0.01).



d. Trade Management

Trailing Stop (RapidTrailingStop()):

For Buy Orders:

If Use_TrailingStep = TRUE and profit (Bid - OrderOpenPrice()) exceeds Start_Trailing_At (2.9 pips), adjusts stop-loss to trail the price by TrailingStep (0.3 pips).
If Use_Set_BreakEven = TRUE and profit exceeds Set_BreakEvenAt (2.3 pips), sets stop-loss to OrderOpenPrice() + LockPips (0.3 pips above open price).


For Sell Orders:

Similar logic, trailing the stop-loss below the Ask price or setting break-even below the open price.




Timed Closing (TimedClosing()):

Closes trades after a specified duration (Minutes_Buy or Minutes_Sell, default: 40 minutes) if the profit meets the minimum threshold:

For Buy: Bid >= OrderOpenPrice() + Timed_Buy_TakeProfit * Point (default: -5 points, likely a bug as negative take-profit is unusual).
For Sell: Ask Gd_232 (spread plus commission exceeds the maximum allowed, e.g., 10.3 points for EURUSD).
Displays spread information on the chart via the Comment function.

f. Graphical Objects

The EA creates graphical objects (rectangles, Fibonacci levels, text) for visualization, controlled by functions like f0_8, f0_7, f0_3, f0_2, f0_0, and f0_1. These are disabled during testing (IsTesting()) to improve performance.


4. How Trades Are Executed
Here’s a typical trade scenario for EURUSD:

Initialization:

Sets MaxSpread = 0.4, Filter = 130, MaxSpreadPlusCommission = 10.3.
Initializes Digits = 5, Point = 0.00001, D_Factor = 10.


Signal Generation:

Checks if the current bar’s range (High - Low) exceeds 130 points.
If IndicatorToUse = 1, uses Envelopes with a 10-period SMA and 0.05 deviation.
Generates a buy signal if Ask Upper Envelope.


Trade Placement:

If spread is below 0.4 pips and within trading hours, places a Buy Stop at Ask + 22 points or a Sell Stop at Bid - 22 points with a 20-pip stop-loss.
Lot size is calculated based on 10% risk or fixed at 0.01 lots.


Trade Management:

If profit reaches 2.9 pips, trails the stop-loss by 0.3 pips.
If profit reaches 2.3 pips, sets break-even at open price + 0.3 pips.
Closes the trade after 40 minutes if profit is at least -5 points (potential bug).


Exit:

Trades are closed via timed closing, manual stop-loss/take-profit, or trailing stop.




5. Potential Issues and Considerations

Negative Take-Profit: The Timed_Buy_TakeProfit and Timed_Sell_TakeProfit values are set to -5, which implies closing trades at a loss. This is likely a bug and should be positive (e.g., 5).
Unusual Envelope Price Types: Using PRICE_HIGH for the lower band and PRICE_LOW for the upper band is unconventional and may lead to incorrect signals. Both should typically use PRICE_CLOSE.
Spread Sensitivity: The EA is highly sensitive to spread, which may prevent trading in volatile markets. Adjust MaxSpread parameters for your broker.
Symbol Detection: The EA assumes 6-character symbols (e.g., EURUSD). Brokers with suffixes (e.g., EURUSDm) may cause issues unless modified to use StringFind.
Commented-Out Code: Functions like RapidManager and getProfit are commented out, suggesting incomplete features. Ensure these are either restored or removed.


6. Example Trade Scenario
Setup: EURUSD, 5-digit broker, Ask = 1.12000, Bid = 1.11980, spread = 2 points (0.2 pips).

Signal: Price breaks below the lower Envelope band (indicator_low = 1.11950), generating a buy signal (Li_180 = -1).
Order Placement:

Places a Buy Stop at 1.12000 + 22 points = 1.12022 with a stop-loss at 1.12022 - 200 points = 1.11822.
Lot size: If balance = $10,000, risk = 10%, lot size = ~0.5 lots (based on 20-pip stop-loss).


Management:

If price reaches 1.12029 (2.9 pips profit), trails stop-loss to Bid - 0.3 pips.
If profit reaches 1.12023 (2.3 pips), sets stop-loss to 1.12003 (open price + 0.3 pips).
Closes after 40 minutes if profit is at least -5 points (likely unintended behavior).




7. Recommendations for Use

Backtesting: Test the EA on historical data for EURUSD, GBPUSD, and USDJPY to evaluate performance. Adjust MaxSpread and Filter based on your broker’s conditions.
Broker Compatibility: Ensure your broker supports 5-digit pricing and low spreads, as the EA is sensitive to spread conditions.
Fix Negative Take-Profit: Change Timed_Buy_TakeProfit and Timed_Sell_TakeProfit to positive values (e.g., 5) to close trades in profit.
Optimize Parameters: Adjust Risk, StopLoss, Limit, and TrailingStep based on your risk tolerance and market conditions.
Demo Testing: Run the EA on a demo account to verify behavior, especially for spread filtering and order execution.


8. Summary
The Chantika V6 EA trades by placing Buy Stop and Sell Stop orders based on breakouts from Moving Average or Envelope bands, with a focus on EURUSD, GBPUSD, and USDJPY. It manages trades with trailing stops, break-even, and timed closures, while enforcing strict spread and time filters. The strategy is designed for volatile market conditions but requires careful parameter tuning and broker compatibility to avoid issues like excessive spread rejections or incorrect signal generation.

Download here : https://discord.gg/9wYhsZHMWN

View full details