Blackjack Candle Count
- Experts
- Scott Adam Meldrum
- Version: 1.6
- Updated: 10 April 2025
BlackJack Counting EA
Ive included the main parameters you need to tweak the EA, the logic that was trained on AI (the bias) is hard coded.
To speed up the EA, printing of the running count is omitted. the logic is in place and working in the background.
Download the demo and test on GOLD H2 !
Any Questions please contact me.
Background
I've always been captivated by the intricate dance between strategy, probability, and psychology inherent in games like chess, poker, and blackjack. At their core, these games aren't just about luck—they're strategic contests where understanding patterns, predicting outcomes, and outsmarting opponents provide immense satisfaction.
Chess, for example, exemplifies pure strategy. Each move opens or closes pathways, demands foresight, and requires players to anticipate their opponent’s intentions many steps ahead. Poker introduces psychological complexity, where success depends not just on cards dealt but also on reading opponents, bluffing convincingly, and managing risk.
However, my greatest fascination lies in blackjack, specifically the brilliant simplicity of the blackjack counting system. Unlike poker and chess, blackjack combines chance with strategic depth in a uniquely quantifiable manner.
The blackjack counting system, at its simplest, assigns numeric values to cards: low cards (2-6) are valued at +1, neutral cards (7-9) at 0, and high cards (10-Ace) at -1. Players track these values to maintain a running count throughout the game.
Why does this work? Fundamentally, blackjack becomes more favorable to the player when the deck is rich in high-value cards. A high count indicates that the deck has proportionally more tens and aces, increasing the odds of hitting a blackjack, improving the effectiveness of doubling down, and boosting the chances that the dealer will bust. By carefully keeping track of the running count, players gain a mathematical advantage, enabling informed decisions about when to bet big or play cautiously.
Casinos, however, are well aware of this advantage. They often counter card counters by taking defensive measures, such as banning suspected card counters from playing altogether or frequently reshuffling the decks, neutralizing any advantage gained from counting. Despite these precautions, the elegance of the counting system remains compelling, transforming blackjack from a game of chance into a calculated, intellectual challenge.
Why does this work? Fundamentally, blackjack becomes more favorable to the player when the deck is rich in high-value cards. A high count indicates that the deck has proportionally more tens and aces, increasing the odds of hitting a blackjack, improving the effectiveness of doubling down, and boosting the chances that the dealer will bust. By carefully keeping track of the running count, players gain a mathematical advantage, enabling informed decisions about when to bet big or play cautiously.
Casinos, however, are well aware of this advantage. They often counter card counters by taking defensive measures, such as banning suspected card counters from playing altogether or frequently reshuffling the decks, neutralizing any advantage gained from counting. Despite these precautions, the elegance of the counting system remains compelling, transforming blackjack from a game of chance into a calculated, intellectual challenge.
This concept led me to a fascinating realization: could a similar counting logic be applied to financial trading? Imagine assigning positive and negative counts to various candle formations, moving average crosses, ATR values, and other indicators commonly used by traders. Just as a high positive count signals an advantageous moment in blackjack, a positive running count in trading could signal a buying opportunity, while a negative count could indicate a selling opportunity.
In fact, applying this blackjack-inspired counting method to trading provides two distinct edges: first, unlike casinos that reshuffle decks to eliminate counting advantages, financial markets never reshuffle historical candles or price action. Second, while a negative blackjack count typically forces you to stop betting or lose money, in trading, you can actively benefit from both positive and negative counts by adjusting your market position accordingly. This transforms trading into a dynamic game of continuous strategic advantage, directly inspired by the intellectual rigor of blackjack counting.
The Importance of a Running Count for Market Entry and Exit: Leveraging Blackjack Logic
Maintaining a running count is a crucial component in trading, particularly when determining optimal entry and exit points. Inspired by the blackjack counting strategy, the running count approach translates market signals into quantifiable numeric values, thereby offering clear, actionable insights.
Each market indicator—whether it be candle formations, moving average crosses, gaps, or volatility readings from Average True Range (ATR)—is assigned a numeric value. Positive signals increase the count, suggesting bullish conditions, while negative signals decrease it, signaling bearish conditions. This continuous count acts as a barometer for market sentiment, guiding traders on when to enter or exit positions effectively.
Why is this method so effective? Just like counting cards in blackjack provides a clear advantage in betting decisions, maintaining a running market count provides real-time clarity on market strength or weakness. A rising positive count indicates increasing bullish momentum, making it advantageous to enter or maintain long positions. Conversely, a declining or negative count suggests bearish momentum, signaling traders to exit long positions or initiate shorts.
Moreover, leveraging machine learning to enhance this counting system refines its effectiveness. Neural networks analyze historical data, continuously optimizing count assignments and biases, thus significantly improving the accuracy of trading signals. By integrating this advanced analytical power, traders ensure that the running count remains responsive and precise.
EA Basic Setup -Inputs
Strategy Control Inputs
These inputs determine how the EA behaves with respect to opening extra trades and the sensitivity of signals.
-
input bool enableAdditionalTrades = true;
Purpose: Enables (or disables) the ability to open extra trades if the trading bias (running total) increases significantly.
When enabled: The EA can add to an existing position if the signal grows stronger. -
input double additionalTradeGap = 300.0;
Purpose: Defines the minimum price gap (in pips, converted to points internally) that must be met between consecutive additional trades.
Usage: Helps avoid rapid re-entry or “whipsaw” when the price hasn’t moved enough from the previous additional entry. -
input double additionalTradeThreshold = 3;
Purpose: Sets the minimum increase in the running total (i.e., the cumulative bias from recent bars) required to trigger an additional trade.
Usage: Ensures that an extra trade is only taken when the signal’s strength increases by at least this amount compared to the previous trade signal.
Running Total Configuration
These parameters control how the EA calculates the bias (or signal strength) by summing the contributions from multiple bars.
-
input int runningTotalBars = 13;
Purpose: Defines the number of previous bars used to compute the running total of bias values.
Usage: A larger number smooths out random fluctuations; a smaller number makes the EA more sensitive to recent moves. -
input double minCountThreshold = 7;
Purpose: Sets the minimum sum of bias (from the recent bars) required to trigger a new trade.
Usage: Helps filter out weak or indecisive market conditions. -
input double maxCountThreshold = 0;
Purpose: Establishes an upper limit for the bias—if the running total exceeds this threshold, the EA would skip the trade.
Usage: When set to 0, it’s effectively turned off; if a nonzero value is provided, it prevents trading in overly strong conditions where the bias might be excessively high.
Trade and Risk Management Inputs
These settings determine your trade size and risk thresholds.
-
input double fixedLotSize = 0.1;
Purpose: Defines the fixed number of lots to trade for each order.
Usage: This is the base volume that will be normalized later to comply with the broker’s volume settings. -
input int stopLossPoints = 850;
Purpose: Specifies the stop loss distance in points (a “point” being the minimal price movement defined by the broker’s symbol settings).
Usage: Determines how far from the entry price the stop loss is placed to limit potential losses. -
input bool useTrailingStop = true;
Purpose: Enables (or disables) a trailing stop mechanism.
Usage: When enabled, the EA will adjust the stop loss during the life of the trade, potentially locking in profits as the market moves favorably. -
input double takeProfitPercent = 6;
Purpose: Sets the take profit threshold as a percentage gain relative to the account balance.
Usage: When equity reaches this percentage above the balance, the EA will close all trades to secure profits. -
input double maxDrawdownPercent = 1;
Purpose: Defines the maximum allowable drawdown (as a percentage below the account balance) before all trades are closed.
Usage: Acts as a safety mechanism to limit losses in adverse market conditions. -
input int MagicNumber = 123452;
Purpose: Provides a unique identifier for all trades executed by this EA.
Usage: Distinguishes these orders from those placed manually or by other EAs running on the same account.
Single Candle Patterns – Bias and Detection Thresholds
These inputs set bias values for signals generated by certain single-candle patterns and determine detection criteria.
-
input double biasPinBar = 0.5;
Purpose: Assigns a bias score for detecting a Pin Bar pattern (a reversal candle with a long tail).
Usage: A Pin Bar contributes positively or negatively to the trading signal depending on its context. -
input double biasInvertedHammerBull = 3;
Purpose: Sets the bias for an Inverted Hammer pattern in a bullish scenario, where a long upper wick may signal a reversal. -
input double biasWideRangeBull = -3.5;
Purpose: Assigns a bias to wide-range bullish candles (a large candle body compared to the overall range), which can indicate strong momentum. -
input double biasMarubozuBull = -1;
Purpose: Determines the bias for a Marubozu candle—a candle with little or no wicks that indicates strong directional conviction. -
input double minPinBodyRatio = 0.11;
Purpose: The minimum ratio of the candle body to the full range required for a candle to qualify as a Pin Bar or hammer pattern. -
input double dojiBodyThresholdRatio = 0.1;
Purpose: Establishes the maximum body-to-range ratio for a candle to be considered a Doji.
Usage: Ensures that only candles with very little body (indicative of market indecision) are flagged.
Two Candle Patterns – Bias Settings
These inputs are used for patterns involving two consecutive candles.
-
input double biasBullEngulfing = -1.5;
Purpose: Sets the bias for a bullish engulfing pattern where a bullish candle completely engulfs a previous bearish candle. -
input double biasInsideBarBull = 1;
Purpose: Provides a positive bias for an inside bar pattern, where the current candle’s range is entirely within the previous candle’s range. -
input double biasHaramiBull = 0;
Purpose: Defines the bias for a bullish Harami pattern—a small bullish candle contained within a larger bearish candle.
Usage: A zero value means it has a neutral impact on the signal. -
input double biasPiercing = 3.5;
Purpose: Assigns a bias for a Piercing pattern. This is a bullish reversal pattern where a bullish candle closes above the midpoint of a prior bearish candle.
Three Candle Patterns – Bias and Detection Thresholds
These inputs apply to signals derived from three-candle formations.
-
input double biasMorningStar = 2;
Purpose: Bias for a Morning Star pattern (a three-candle bullish reversal that often includes a doji), indicating a shift in momentum. -
input double biasThreeWhiteSoldiers = 4.5;
Purpose: A strong bullish bias when three consecutive bullish candles (Three White Soldiers) are detected. -
input double biasThreeInsideUp = 5;
Purpose: Bias for a “Three Inside Up” pattern, where an inside pattern confirms bullish reversal. -
input double biasThreeBarBullRev = 3;
Purpose: Sets a bias for a custom-defined three-bar bullish reversal pattern. -
input double biasUpsideGapTwoCrows = 3;
Purpose: Although named with a “crows” reference, it is associated with bearish gap patterns involving two candles.
Usage: The setting suggests that such a formation contributes a specific bias to the overall signal.
Gap Patterns – Open-Close Based Bias Settings
These inputs address gap patterns by comparing open/close prices, offering additional signals.
-
input double biasGap_OC_Up_BullBull = -1;
Purpose: Bias value for a gap up scenario where bullish conditions continue (both previous and current candles are bullish). -
input double biasGap_OC_Up_BullBear = -2;
Purpose: Bias for a gap up pattern that reverses into bearish behavior. -
input double biasGap_OC_Down_BullBull = 2;
Purpose: Bias for a gap down that continues bullish momentum, an unusual situation where market structure might imply a retracement. -
input double biasGap_OC_Down_BullBear = -3;
Purpose: Bias for a gap down leading to bearish continuation.
Gap Patterns – High-Low Based Bias Settings
These settings consider gaps in the high-low range rather than open-close levels.
-
input double biasGap_HL_Up_BullBull = -2.5;
Purpose: Bias for a bullish confirmation in a gap up scenario based on the high-low range. -
input double biasGap_HL_Up_BullBear = -5;
Purpose: A stronger bearish bias in a gap up scenario when conditions reverse. -
input double biasGap_HL_Down_BullBull = -1.5;
Purpose: Bias for gap down with bullish continuation. -
input double biasGap_HL_Down_BullBear = 0.5;
Purpose: A mild bias for gap down scenarios that turn bearish.
Pattern Group Enable/Disable Flags
These boolean switches let you choose which sets of pattern analyses to run. Disabling a group can simplify the decision-making process if you wish to focus on particular patterns.
-
input bool analyzeSingleCandlePatterns = true;
Enables or disables the detection of single-candle patterns. -
input bool analyzeTwoCandlePatterns = true;
Controls whether two-candle pattern detection is active. -
input bool analyzeThreeCandlePatterns = true;
Toggles the analysis for three-candle patterns. -
input bool analyzeGapPatterns = true;
Determines if gap-based patterns are to be included in the trading signal.
MA Cross Visualization Settings (Moving Average Filter)
These inputs configure two moving averages used as a filter to further confirm trade signals.
Fast Moving Average (MA1)
-
input bool InpUseMAFilter = true;
Purpose: Enables or disables the moving average filter entirely.
Usage: When enabled, the EA will only take a trade if the fast MA is in the desired relation to the slow MA. -
input string FAST and related text strings ( MA1_TEXT , MA1_TEXT_2 ):
Purpose: Provide labels or visual separators for the fast MA settings when displayed on the chart. -
input ENUM_TIMEFRAMES MA1_TIMEFRAME = PERIOD_CURRENT;
Purpose: Sets the timeframe on which the fast MA is calculated (by default, the current chart’s timeframe). -
input ENUM_MA_METHOD MA1_MODE = MODE_SMA;
Purpose: Defines the method used for the fast MA calculation (Simple Moving Average in this case). -
input int MA1_PERIOD = 60;
Purpose: Specifies the period (number of bars) to calculate the fast MA. -
input int MA1_SHIFT = 0;
Purpose: Allows shifting the fast MA forward or backward relative to the price bars. -
input ENUM_APPLIED_PRICE MA1_APPLIED_PRICE = PRICE_CLOSE;
Purpose: Chooses the price data (e.g., close, open, high, low) that is fed into the fast MA calculation.
Slow Moving Average (MA2)
-
input string SLOW, MA2_TEXT, MA2_TEXT_2 :
Purpose: Similar to the fast MA strings, these are used for labeling and visual organization for the slow MA settings. -
input ENUM_TIMEFRAMES MA2_TIMEFRAME = PERIOD_CURRENT;
Purpose: Sets the timeframe for the slow MA calculation. -
input ENUM_MA_METHOD MA2_MODE = MODE_SMA;
Purpose: Determines the method for the slow MA (again using a simple moving average). -
input int MA2_PERIOD = 155;
Purpose: Sets the number of bars used in calculating the slow MA. Typically, a longer period is chosen than for the fast MA. -
input int MA2_SHIFT = 0;
Purpose: Allows for adjusting the alignment of the slow MA. -
input ENUM_APPLIED_PRICE MA2_APPLIED_PRICE = PRICE_CLOSE;
Purpose: Selects which price to use (here, the closing price) for calculating the slow MA.
Summary
Each setting has been carefully designed to control either the:
-
Trade Execution and Management: (lot size, stop loss, trailing stops, risk limits, extra trade conditions)
-
Signal Generation: (candlestick pattern biases and thresholds, running total calculation)
-
Market Filtering: (moving average filter for trade confirmation)
By adjusting these inputs, you can fine-tune the strategy’s sensitivity, risk profile, and market condition adaptability.
This thorough explanation should help you—and any end user—understand the purpose and function of every configuration parameter in the EA.
Great EA, it trades like a professional trader, with SL and higher time frame trading it is a winner in many aspects, the logic behind it is amazing and the author is professional and responsive, thank you for making such a great EA, really like it :)