Instructions for Setting Up and Using theStochasticProEAExpert Advisor
TheStochasticProEAExpert Advisor is designed for automated trading based on the Stochastic oscillator. It uses agrid strategy: it opens a series of positions in one direction when certain conditions are met, adding new orders with a specified step. The advisor includes professional filters (EMA, RSI, ATR, time filter, spread), adaptive overbought/oversold levels, and an advanced risk management system: trailing stop, protection against a series of losses, maximum drawdown control, partial position closing, and much more.
The advisor is fully ready for use on a live account, but requires careful tuning for a specific instrument and trading style.
1. Main Stochastic Parameters
These parameters determine how the Stochastic indicator is calculated.
Parameter
Description
Inp_KPeriod
%K period (main line). Usually 5–14.
Inp_DPeriod
%D period (signal line). Usually 3–5.
Inp_Slowing
%K smoothing. The larger the value, the smoother the line.
Setup:For short-term trading, smaller values are used (K=5, D=3); for medium-term, larger values (K=14, D=7). It is recommended to start with the classic settings 10,7,3.
2. Trading Parameters
Parameter
Description
Inp_Lot
Fixed lot for the first position (if not using drawdown-based calculation).
Inp_MaxLot
Maximum allowed lot (upper limit).
Inp_MagicNumber
Unique identifier of the advisor. Different advisors on the same account must have different magic numbers.
Inp_Slippage
Allowed slippage in points.
Inp_UseNewBar
Iftrue, the advisor only works on the opening of a new bar (recommended for stability).
3. Professional Filters
Filters are appliedonlywhen opening the first position in the grid, if theInp_GridUseFiltersparameter is enabled (see the grid section). They help filter out false signals.
3.1. EMA Filter (Trend)
Parameter
Description
Inp_UseEMAFilter
Enable/disable the EMA filter.
Inp_EMAPeriod
EMA period (e.g., 50).
Inp_UseHigherTF
Use EMA from a higher timeframe.
Inp_HigherTF
Higher timeframe (H1, H4, etc.).
How it works:
For a buy: the price (Ask) must beabovethe EMA (uptrend).
For a sell: the price (Bid) must bebelowthe EMA (downtrend). IfUseHigherTFis enabled, the comparison is made with the EMA on the higher timeframe.
3.2. ATR Filter (Volatility)
Parameter
Description
Inp_UseATRFilter
Enable/disable the ATR filter.
Inp_ATRPeriod
ATR period for the filter (usually 14).
Inp_ATRMin
Minimum ATR value. If ATR is lower, the signal is not accepted.
Inp_ATRMax
Maximum ATR value. If ATR is higher, the signal is not accepted.
Purpose:Filters out moments of too low or too high volatility.
3.3. RSI Filter (Confirmation)
Parameter
Description
Inp_UseRSIFilter
Enable/disable the RSI filter.
Inp_RSIPeriod
RSI period (usually 14).
Inp_RSILevel
Level for confirmation.
How it works:
For a buy: RSI must beabovethe specified level (default 50).
For a sell: RSI must bebelowthe specified level.
3.4. Time Filter and Spread
Parameter
Description
Inp_UseTimeFilter
Enable/disable the time filter.
Inp_StartHour
Trading start hour (server time).
Inp_EndHour
Trading end hour.
Inp_MaxSpread
Maximum allowed spread in points. If the spread is larger, the trade is not opened.
4. Adaptive Overbought/Oversold Levels
Instead of fixed levels (e.g., 30 and 70), dynamic levels can be used, calculated as percentiles over a specified period.
Parameter
Description
Inp_UseAdaptiveLevels
Enable adaptive levels.
Inp_AdaptivePeriod
Period for percentile calculation (number of bars).
Note:If adaptive levels are disabled, the fixed levels from the grid parameters (Inp_GridOversold,Inp_GridOverbought) are used.
5. Risk Management (Common for All Positions)
5.1. Trailing Stop
Parameter
Description
Inp_UseTrailingStop
Enable trailing stop.
Inp_TrailingStop
Distance from the current price to the stop (in points).
Inp_TrailingStep
Step by which the stop must move to trigger a modification (to avoid frequent modifications).
5.2. Protection Against a Series of Losses
Parameter
Description
Inp_MaxConsecutiveLosses
Maximum number of consecutive losing trades. When this value is reached, the advisor pauses trading for 10 bars.
5.3. Maximum Drawdown Protection
Parameter
Description
Inp_MaxDrawdownPercent
Maximum allowed drawdown in % of the maximum balance. When this level is reached, all positions are closed and trading is blocked for 10 bars.
6. Grid Parameters
This is the main part of the strategy. The grid opens in one direction after a Stochastic signal.
6.1. Basic Grid Settings
Parameter
Description
Inp_CloseProfitPips
Take profit for each individual position (in points). If 0 – not used.
Inp_NoTradeNearBy
Base distance between grid levels (in points) if ATR is not used.
Inp_MaxGridPositions
Maximum number of positions in the grid (in one direction).
Inp_HowManyCandle
Number of candles during which Stochastic must remain in the overbought/oversold zone before a signal is considered valid.
Inp_GridOversold
Oversold level (if adaptive levels are disabled).
Inp_GridOverbought
Overbought level (if adaptive levels are disabled).
6.2. Advanced Grid Parameters
Parameter
Description
Inp_GridUseATRStep
Use ATR to calculate the grid step.
Inp_ATRPeriodGrid
ATR period for the grid step.
Inp_GridStepATR
ATR multiplier (step = ATR * multiplier).
Inp_GridUseTotalTP
Use a total take profit for the entire grid.
Inp_GridTotalProfitPips
Total target profit in points (multiplied by the total volume).
Inp_GridLotType
Lot calculation type for added positions:Fixed– fixed lot;Multiply– multiplication with a coefficient;ByDrawdown– calculated from current drawdown.
Inp_GridLotMultiplier
Lot multiplication factor (if Multiply is selected).
Inp_GridUseFilters
Whether to apply filters (EMA, RSI, ATR, time, spread) when opening the first grid position.
Inp_GridExitByStoch
Exit the grid based on a Stochastic signal.
Inp_GridExitStochLevel
Stochastic level whose crossover (together with line crossover) gives an exit signal.
Inp_GridDynamicStep
Dynamic grid step: increases as drawdown grows (step = base step * (1 + drawdown/100)).
Inp_GridPartialClose
Enable partial closing of positions when the price moves into profit.
Inp_GridPartialClosePips
Minimum profit in points at which a position can be partially closed.
Inp_GridPartialClosePercent
Percentage of the total grid volume to close when partial closing triggers (the most profitable positions are closed).
Inp_GridMaxHoldHours
Maximum grid holding time in hours. After exceeding this, all positions are closed.
Inp_DrawdownLevel1
Drawdown level 1 (in %), at which a portion of positions is closed (Inp_DrawdownCloseLevel1).
Inp_DrawdownLevel2
Drawdown level 2 (in %), at which a portion of positions is closed (Inp_DrawdownCloseLevel2).
Inp_DrawdownCloseLevel1
% of positions (by volume) closed when level 1 is reached.
Inp_DrawdownCloseLevel2
% of positions (by volume) closed when level 2 is reached.
7. How the Strategy Works
7.1. Entry for the First Position
On each new bar (if enabled), the advisor checks the Stochastic signal:
Buy signal: the %K and %D lines cross upwards, and before that, Stochastic wasbelowthe oversold level forInp_HowManyCandlecandles.
Sell signal: the lines cross downwards, and before that, Stochastic wasabovethe overbought level for the specified number of candles.
If filters are enabled (Inp_GridUseFilters), all filters (EMA, RSI, ATR, time, spread) are additionally checked. If everything matches, the first position (Buy or Sell) is opened with lotInp_Lot(or a calculated lot if the lot type is not Fixed). The grid start time is recorded.
7.2. Adding Positions to the Grid
After opening the first position, the advisor monitors the price movement. If the price moves a distance equal to the grid step (calculated by ATR or fixed) and the number of positions is less thanInp_MaxGridPositions, a new position in the same direction is opened with an increased lot (depending on the lot type). The step may dynamically increase as drawdown grows.
7.3. Exiting the Grid
There are several ways to exit:
Individual Take Profit– each position closes when it reaches its own target (Inp_CloseProfitPips). The grid may continue with the remaining positions.
Total Take Profit(Inp_GridUseTotalTP) – when the total profit of all positions reachesInp_GridTotalProfitPips(multiplied by the total volume), all positions are closed.
Exit by Stochastic(Inp_GridExitByStoch) – if the grid consists only of long positions and Stochastic gives a sell signal (downward crossover and below the level), the grid is closed. Similarly for short positions.
Trailing Stop– if enabled, stops are moved manually.
Drawdown Protection– when levelsInp_DrawdownLevel1/2are reached, a specified percentage of positions (the oldest) is closed. WhenInp_MaxDrawdownPercentis reached, all positions are closed.
Maximum Holding Time– if the grid remains open longer thanInp_GridMaxHoldHours, all positions are closed.
7.4. Partial Closing (Inp_GridPartialClose)
When the price moves into profit and any position has a profit greater thanInp_GridPartialClosePips, the advisor may close a portion of the positions (the most profitable ones) with a total volume equal toInp_GridPartialClosePercentof the entire grid volume. This allows locking in profits while keeping the grid.
8. Additional Features
State Recovery After Restart: upon initialization, the advisor scans open positions with its magic number and restores grid parameters (average prices, volumes, start time). This prevents disruption after a terminal restart.
Margin Check: before opening each position, it checks whether there is enough free margin.
Lot Normalization: the lot is automatically adjusted to the symbol's requirements (min, max, step).
Safe Closing: if the standard position close fails, the advisor attempts to close with a direct market order.
9. Setup Recommendations
Instrument Selection: the advisor works best on currency pairs with good volatility and liquidity (EURUSD, GBPUSD, etc.).
Timeframe: optimally M15 – H1.
Stochastic Parameters: classic 10,7,3 or 14,7,3. For more frequent signals, you can reduce K to 5.
Grid Step: if using ATR, start with a multiplier of 1.0–1.5. For a fixed step, choose a value commensurate with the average price movement (e.g., 20–50 points for EURUSD).
Maximum Number of Positions: no more than 3–5, to avoid overloading the deposit.
Filters: enable them gradually. You can start with all filters off, then add EMA to determine the trend.
Risk Management: be sure to setInp_MaxDrawdownPercent(e.g., 15–20%) andInp_MaxConsecutiveLosses(3–5).
Testing: conduct thorough testing on historical data and on a demo account before live trading. Pay attention to behavior during strong trends and flat markets.
10. Conclusion
StochasticProEAis a powerful tool for automated trading using a grid strategy. Thanks to its many settings, it can be adapted to different market conditions. However, grid strategies carry increased risks during sharp movements, so be sure to use protective mechanisms and control drawdown.
Instructions for Setting Up and Using the StochasticProEA Expert Advisor
The StochasticProEA Expert Advisor is designed for automated trading based on the Stochastic oscillator. It uses a grid strategy: it opens a series of positions in one direction when certain conditions are met, adding new orders with a specified step. The advisor includes professional filters (EMA, RSI, ATR, time filter, spread), adaptive overbought/oversold levels, and an advanced risk management system: trailing stop, protection against a series of losses, maximum drawdown control, partial position closing, and much more.
The advisor is fully ready for use on a live account, but requires careful tuning for a specific instrument and trading style.
1. Main Stochastic Parameters
These parameters determine how the Stochastic indicator is calculated.
Setup: For short-term trading, smaller values are used (K=5, D=3); for medium-term, larger values (K=14, D=7). It is recommended to start with the classic settings 10,7,3.
2. Trading Parameters
3. Professional Filters
Filters are applied only when opening the first position in the grid, if the Inp_GridUseFilters parameter is enabled (see the grid section). They help filter out false signals.
3.1. EMA Filter (Trend)
How it works:
For a buy: the price (Ask) must be above the EMA (uptrend).
For a sell: the price (Bid) must be below the EMA (downtrend).
If UseHigherTF is enabled, the comparison is made with the EMA on the higher timeframe.
3.2. ATR Filter (Volatility)
Purpose: Filters out moments of too low or too high volatility.
3.3. RSI Filter (Confirmation)
How it works:
For a buy: RSI must be above the specified level (default 50).
For a sell: RSI must be below the specified level.
3.4. Time Filter and Spread
4. Adaptive Overbought/Oversold Levels
Instead of fixed levels (e.g., 30 and 70), dynamic levels can be used, calculated as percentiles over a specified period.
Note: If adaptive levels are disabled, the fixed levels from the grid parameters (Inp_GridOversold, Inp_GridOverbought) are used.
5. Risk Management (Common for All Positions)
5.1. Trailing Stop
5.2. Protection Against a Series of Losses
5.3. Maximum Drawdown Protection
6. Grid Parameters
This is the main part of the strategy. The grid opens in one direction after a Stochastic signal.
6.1. Basic Grid Settings
6.2. Advanced Grid Parameters
7. How the Strategy Works
7.1. Entry for the First Position
On each new bar (if enabled), the advisor checks the Stochastic signal:
Buy signal: the %K and %D lines cross upwards, and before that, Stochastic was below the oversold level for Inp_HowManyCandle candles.
Sell signal: the lines cross downwards, and before that, Stochastic was above the overbought level for the specified number of candles.
If filters are enabled (Inp_GridUseFilters), all filters (EMA, RSI, ATR, time, spread) are additionally checked. If everything matches, the first position (Buy or Sell) is opened with lot Inp_Lot (or a calculated lot if the lot type is not Fixed). The grid start time is recorded.
7.2. Adding Positions to the Grid
After opening the first position, the advisor monitors the price movement. If the price moves a distance equal to the grid step (calculated by ATR or fixed) and the number of positions is less than Inp_MaxGridPositions, a new position in the same direction is opened with an increased lot (depending on the lot type). The step may dynamically increase as drawdown grows.
7.3. Exiting the Grid
There are several ways to exit:
Individual Take Profit – each position closes when it reaches its own target (Inp_CloseProfitPips). The grid may continue with the remaining positions.
Total Take Profit (Inp_GridUseTotalTP) – when the total profit of all positions reaches Inp_GridTotalProfitPips (multiplied by the total volume), all positions are closed.
Exit by Stochastic (Inp_GridExitByStoch) – if the grid consists only of long positions and Stochastic gives a sell signal (downward crossover and below the level), the grid is closed. Similarly for short positions.
Trailing Stop – if enabled, stops are moved manually.
Drawdown Protection – when levels Inp_DrawdownLevel1/2 are reached, a specified percentage of positions (the oldest) is closed. When Inp_MaxDrawdownPercent is reached, all positions are closed.
Maximum Holding Time – if the grid remains open longer than Inp_GridMaxHoldHours, all positions are closed.
7.4. Partial Closing (Inp_GridPartialClose)
When the price moves into profit and any position has a profit greater than Inp_GridPartialClosePips, the advisor may close a portion of the positions (the most profitable ones) with a total volume equal to Inp_GridPartialClosePercent of the entire grid volume. This allows locking in profits while keeping the grid.
8. Additional Features
State Recovery After Restart: upon initialization, the advisor scans open positions with its magic number and restores grid parameters (average prices, volumes, start time). This prevents disruption after a terminal restart.
Margin Check: before opening each position, it checks whether there is enough free margin.
Lot Normalization: the lot is automatically adjusted to the symbol's requirements (min, max, step).
Safe Closing: if the standard position close fails, the advisor attempts to close with a direct market order.
9. Setup Recommendations
Instrument Selection: the advisor works best on currency pairs with good volatility and liquidity (EURUSD, GBPUSD, etc.).
Timeframe: optimally M15 – H1.
Stochastic Parameters: classic 10,7,3 or 14,7,3. For more frequent signals, you can reduce K to 5.
Grid Step: if using ATR, start with a multiplier of 1.0–1.5. For a fixed step, choose a value commensurate with the average price movement (e.g., 20–50 points for EURUSD).
Maximum Number of Positions: no more than 3–5, to avoid overloading the deposit.
Filters: enable them gradually. You can start with all filters off, then add EMA to determine the trend.
Risk Management: be sure to set Inp_MaxDrawdownPercent (e.g., 15–20%) and Inp_MaxConsecutiveLosses (3–5).
Testing: conduct thorough testing on historical data and on a demo account before live trading. Pay attention to behavior during strong trends and flat markets.
10. Conclusion
StochasticProEA is a powerful tool for automated trading using a grid strategy. Thanks to its many settings, it can be adapted to different market conditions. However, grid strategies carry increased risks during sharp movements, so be sure to use protective mechanisms and control drawdown.
Happy trading!