The Xenith Stochastic EA V1.3 (Non-Repaint) is an automated trading tool designed to execute trades based on the stochastic oscillator’s signals. It uses a multi-timeframe approach, where analysis is performed on a secondary timeframe, and trades are executed on the current timeframe. The EA focuses on identifying stochastic crossovers to trigger buy or sell trades, while offering customizable settings like lot size, stop loss, and take profit. Though it recalculates past values, it does not repaint previously generated signals.
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- Set up stochastic handle for Timeframe 2 (TF2)
ExtStochasticHandle_TF2 = iStochastic(NULL, InpTimeFrame_2, InpKPeriod, InpDPeriod, InpSlowing, InpAppliedMA, InpAppliedPrice);
//--- Return initialization result
if (ExtStochasticHandle_TF2 == INVALID_HANDLE)
{
Print("Error initializing Stochastic Handle! Error Code: ", GetLastError());
return(INIT_FAILED);
}
// Initialization successful
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- release stochastic handle on deinit
if (ExtStochasticHandle_TF2 != INVALID_HANDLE)
IndicatorRelease(ExtStochasticHandle_TF2);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- Retrieve current stochastic values
double mainTF2, signalTF2;
if(CopyBuffer(ExtStochasticHandle_TF2, 0, 0, 1, mainTF2) <= 0 || CopyBuffer(ExtStochasticHandle_TF2, 1, 0, 1, signalTF2) <= 0)
{
Print("Error retrieving Stochastic values! Error Code: ", GetLastError());
return;
}
//--- Define trade logic
// Example: Buy when the main line crosses above the signal line
if(mainTF2[0] > signalTF2[0] && PositionsTotal() == 0)
{
//--- Open buy order
OpenTrade(ORDER_TYPE_BUY);
}
// Example: Sell when the main line crosses below the signal line
else if(mainTF2[0] < signalTF2[0] && PositionsTotal() == 0)
{
//--- Open sell order
OpenTrade(ORDER_TYPE_SELL);
}
}
//+------------------------------------------------------------------+
//| OpenTrade function: Opens trades with risk management |
//+------------------------------------------------------------------+
void OpenTrade(int tradeType)
{
double lotSize = 0.1; // Replace with a dynamic lot sizing method if needed
//--- Trade parameters
double stopLoss = 100; // Replace with actual stop loss logic
double takeProfit = 200; // Replace with actual take profit logic
//--- Define trade request
MqlTradeRequest request;
MqlTradeResult result;
ZeroMemory(request);
request.action = TRADE_ACTION_DEAL;
request.symbol = Symbol();
request.volume = lotSize;
request.type = tradeType;
request.price = (tradeType == ORDER_TYPE_BUY) ? Ask : Bid;
request.sl = (tradeType == ORDER_TYPE_BUY) ? Ask - stopLoss * _Point : Bid + stopLoss * _Point;
request.tp = (tradeType == ORDER_TYPE_BUY) ? Ask + takeProfit * _Point : Bid - takeProfit * _Point;
request.deviation = 10;
request.magic = 123456;
request.comment = "Stochastic EA Trade";
//--- Send trade request
if(!OrderSend(request, result))
Print("Error opening trade: ", GetLastError());
}
//+------------------------------------------------------------------+
What is the Xenith Stochastic EA?
The Xenith Stochastic EA is a trading algorithm designed to execute trades based on a technical indicator known as the Stochastic Oscillator. The stochastic is a popular indicator used in trading to identify overbought and oversold conditions. However, this EA goes a step further by analyzing price data from a different timeframe (known as Timeframe 2, or TF2) and executing trades on the current timeframe based on that analysis.
How It Works
Xenith Stochastic EA is built around a simple crossing strategy. The EA waits for a crossover between two key lines: the main stochastic line and the signal line. When these lines cross each other, it can indicate a potential reversal in the market, which prompts the EA to open a buy or sell trade.
The key distinction of the Xenith Stochastic EA is that it doesn’t simply rely on data from the current timeframe you’re trading on. Instead, it pulls in data from Timeframe 2 (TF2), which is set by the user. By doing so, the EA analyzes trends and market behavior from a higher timeframe while executing trades on a lower one.
Key Components of the Xenith Stochastic EA
To better understand the EA, let’s break down its main components and processes:
Timeframe Analysis
The EA uses two timeframes. The current timeframe (TF1) is where the trades are executed. However, the stochastic calculations are done on Timeframe 2 (TF2). This multi-timeframe approach allows the EA to take advantage of longer-term trends and market behavior, rather than just reacting to immediate price action.
By default, TF2 is set to H1, but this is adjustable, allowing traders to analyze data from different timeframes depending on their strategy.
Stochastic Oscillator
The stochastic oscillator is a technical indicator that compares a security’s closing price to its price range over a certain period. The Xenith Stochastic EA uses two lines from this oscillator:
- Main Line: The primary moving average of the stochastic calculation.
- Signal Line: A smoothed version of the main line used to identify potential buy or sell signals.
The crossover between these lines is critical. For instance, when the main line crosses above the signal line, it’s typically seen as a buy signal. When it crosses below, it’s generally a sell signal.
Trade Execution Logic
The EA executes trades based on the crossing of the main and signal lines. The process is simple:
- Buy Trades are opened when the main line crosses above the signal line.
- Sell Trades are opened when the main line crosses below the signal line.
Additionally, the EA ensures that there is only one open position at a time. It doesn’t continue to open new positions if there’s already an active trade in the market. This conservative approach is designed to limit overtrading.
Risk Management
The Xenith Stochastic EA includes basic risk management settings. It allows you to define parameters such as:
- Lot size: The amount to trade on each order.
- Stop Loss: A predefined level at which a trade is automatically closed to prevent excessive losses.
- Take Profit: A predefined level at which the EA will automatically close a trade to lock in profits.
These settings can be adjusted based on personal preferences and risk tolerance, giving users flexibility in managing their trades.
Limitations and Considerations
Recalculating Values
While the EA doesn’t repaint its signals (meaning the signals won’t change retroactively), it does recalculate past values. This recalculation means that past values are updated when new data becomes available, but the signals already generated won’t be affected.
Non-Repainting vs. Non-Lagging
One of the advantages of this EA is that it’s non-repainting, meaning once a signal is generated, it will not change later. This is crucial for traders relying on historical data to make decisions. However, the EA is not fully non-lagging, as it still depends on the inherent delay that comes with using indicators like the stochastic oscillator, which are based on past price data.
Customizability
The Xenith Stochastic EA is designed with flexibility in mind. Traders can adjust key parameters such as:
- The timeframe for analysis (TF2).
- The K period, D period, and slowing values used in the stochastic calculation.
- The moving average method and price basis for the stochastic.
This customization allows traders to fine-tune the EA according to their strategy and preferences. By modifying these settings, users can adapt the EA to different market conditions and trading styles.
Final Thoughts
The Xenith Stochastic EA is a straightforward trading tool that automates the process of identifying and acting on stochastic crossovers. By analyzing data from a secondary timeframe and applying that information to the current timeframe, the EA takes a more holistic view of market conditions.
While it doesn’t promise to eliminate risk or guarantee profits, it offers a systematic way to automate trading based on stochastic signals. Whether you’re a new trader looking for structure or an experienced trader seeking to streamline your process, this EA provides a foundation for trade automation with a simple, understandable strategy. Remember, trading always comes with risk, and it’s essential to use the EA responsibly, with proper risk management in place.