// Trading Parameters
input double LotSize = 0.01; // Lot size for trading
input int Tppoints = 800; // Take Profit (10 points = 1 pip)
input int Slpoints = 800; // Stoploss Points (10 points = 1 pip)
input int TslTriggerPoints = 35; // Points in profit before Trailing SL is activated (10 points = 1 pip)
input int TslPoints = 10; // Trailing Stoploss (10 points = 1 pip)
input ENUM_TIMEFRAMES Timeframe = PERIOD_CURRENT; // Time frame to run
input int InpMagic = 891245; // EA identification no
input string TradeComment = "Wendel Cassiano"; // Trade comment
input int MaxSpread = 100; // Maximum spread allowed (in points)
input int Slippage = 50; // Slippage in points
input int MaxOrders = 2; // Maximum simultaneous orders
input int BarsN = 5; // Bars to analyze
input int ExpirationBars = 100; // Order expiration based on bars
input int OrderDistPoints = 100; // Distance in points from price
use de exemplo a rede neural desse codigo e implemente do meu codigo abaixo para melhorar a assertividade, nao adicione outras estrategias de RSI etc apenas mantenha a estrategia do meu codigo original e apenas adicione a rede neural e me entregue o codigo completo com as atualizações:
#property copyright "Copyright 2023, Alfred Mandala. "
#property description "www.billionairebulls.co.za\n"
#property version "1.5"
#property description "RSI GRID SCALPING EA com Stochastic\n"
// Incluindo bibliotecas necessárias
#include <Trade/Trade.mqh>
// ---- INPUTS ----
input group "--- Trading Inputs ---";
input double Lots = 0.01; // Tamanho do Lote
input int TpPoints = 50; // Take Profit em pontos [m5-50p, h1-200p]
input int StopLossPoints = 500; // Stop Loss em pontos [Ex: 20 pontos]
input ENUM_TIMEFRAMES RsiTimeFrame = PERIOD_CURRENT; // Timeframe
input group "--- RSI Inputs ---";
input int RsiPeriods = 18; // Periodo do RSI
input ENUM_APPLIED_PRICE RsiAppPrice = PRICE_CLOSE; // Preço aplicado pelo RSI
input double RsiSellTrigger = 70; // Zona de Venda do RSI
input double RsiBuyTrigger = 30; // Zona de Compra do RSI
input group "--- Bollinger Bands Inputs ---";
input int BbPeriods = 23; // Períodos das BB
input double BbDeviation = 2.0; // Desvio
input double BbShift = 0; // Deslocamento
input group "--- Stochastic Inputs ---";
input int StochKPeriod = 5; // Período K do Stoch
input int StochDPeriod = 3; // Período D do Stoch
input int StochSlowing = 3; // Atraso do Stoch
input double StochOverbought = 80.0; // Nível de sobrecompra
input double StochOversold = 20.0; // Nível de sobrevenda
// ---- GLOBAL VARIABLES ----
int handleRsi, handleBb, handleStochastic;
double rsi[], bbUpper[], bbLower[], stochMain[];
if (points > TpPoints)
{
trade.PositionClose(posTicket);
}
}
}
}
To integrate the neural network functionality from the first code into your existing RSI-Bollinger Bands scalping strategy, we need to make a few adjustments. The goal is to enhance the entry signals generated by your existing logic with predictions from a simple neural network. I will preserve your original strategy while supplementing it with the neural network functionality.
Here's the complete code with the neural network implementation added:
//+------------------------------------------------------------------+
//| AI RSI BB SCALPER.mq5 |
//| Alfr5d |
//| https://www.49design.co.za |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, Alfred Mandala. "
#property description "www.billionairebulls.co.za\n"
#property version "1.6"
#property description "RSI GRID SCALPING EA com Stochastic e Rede Neural\n"
#include <Trade/Trade.mqh>
// ---- INPUTS ----
input group "--- Trading Inputs ---";
input double Lots = 0.01; // Tamanho do Lote
input int TpPoints = 50; // Take Profit em pontos [m5-50p, h1-200p]
input int StopLossPoints = 500; // Stop Loss em pontos [Ex: 20 pontos]
input ENUM_TIMEFRAMES RsiTimeFrame = PERIOD_CURRENT; // Timeframe
input group "--- RSI Inputs ---";
input int RsiPeriods = 18; // Periodo do RSI
input ENUM_APPLIED_PRICE RsiAppPrice = PRICE_CLOSE; // Preço aplicado pelo RSI
input double RsiSellTrigger = 70; // Zona de Venda do RSI
input double RsiBuyTrigger = 30; // Zona de Compra do RSI
input group "--- Bollinger Bands Inputs ---";
input int BbPeriods = 23; // Períodos das BB
input double BbDeviation = 2.0; // Desvio
input double BbShift = 0; // Deslocamento
input group "--- Stochastic Inputs ---";
input int StochKPeriod = 5; // Período K do Stoch
input int StochDPeriod = 3; // Período D do Stoch
input int StochSlowing = 3; // Atraso do Stoch
input double StochOverbought = 80.0; // Nível de sobrecompra
input double StochOversold = 20.0; // Nível de sobrevenda
// Neural Network Parameters
input double Coefficient = 0.1;
input double BuyTargetOutput = 0.3;
input double SellTargetOutput = -0.3;
input double LearningRate = 0.1;
#define NumNodes 10
double Weight[];
double NormalizedInputs[NumNodes];
double NNOutPut = 0;
int handleRsi, handleBb, handleStochastic;
double rsi[], bbUpper[], bbLower[], stochMain[];
CTrade trade;
// ---- EXPERT INIT ----
int OnInit()
{
handleRsi = iRSI(_Symbol, RsiTimeFrame, RsiPeriods, RsiAppPrice);
handleBb = iBands(_Symbol, PERIOD_CURRENT, BbPeriods, BbShift, BbDeviation, PRICE_CLOSE);
handleStochastic = iStochastic(_Symbol, PERIOD_CURRENT, StochKPeriod, StochDPeriod, StochSlowing, MODE_SMA, STO_LOWHIGH);
// Initialize Neural Network Weights
ArrayResize(Weight, NumNodes);
for (int i = 0; i < NumNodes; i++)
Weight[i] = 0.5;
return (INIT_SUCCEEDED);
}
// ---- EXPERT DEINIT ----
void OnDeinit(const int reason)
{
IndicatorRelease(handleBb);
IndicatorRelease(handleRsi);
IndicatorRelease(handleStochastic);
}
// ---- ON TICK FUNCTION ----
void OnTick()
{
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
CopyBuffer(handleBb, 1, 0, 1, bbUpper);
CopyBuffer(handleBb, 2, 0, 1, bbLower);
CopyBuffer(handleRsi, 0, 0, 2, rsi);
CopyBuffer(handleStochastic, 0, 0, 2, stochMain);
// Prepare inputs for the neural network
NormalizedInputs[0] = rsi[0]; // You may want to normalize it: (rsivalue - lower) / (upper - lower)
// ... Populate other nodes (e.g., stochMain) if needed
NormalizingInputs();
OutPutLayerCalculation();
// Ensure only one order at a time
if (PositionsTotal() == 0) // Check for open positions
{
// Condition for Sell using RSI, Stochastic and Neural Network prediction
if (rsi[1] > RsiSellTrigger && rsi[0] < RsiSellTrigger && stochMain[0] > StochOverbought && NNOutPut < SellTargetOutput)
{
if (bid >= bbUpper[0])
{
Print(__FUNCTION__, " > SELL Signal...");
trade.Sell(Lots, _Symbol, bid, bid + StopLossPoints * _Point, bid - TpPoints * _Point);
}
}
// Condition for Buy using RSI, Stochastic and Neural Network prediction
else if (rsi[1] < RsiBuyTrigger && rsi[0] > RsiBuyTrigger && stochMain[0] < StochOversold && NNOutPut > BuyTargetOutput)
{
if (bid <= bbLower[0])
{
Print(__FUNCTION__, " > BUY Signal...");
trade.Buy(Lots, _Symbol, bid, bid - StopLossPoints * _Point, bid + TpPoints * _Point);
}
}
}
// Position management
ManagePositions();
Comment("\nRSI[0]: ", DoubleToString(rsi[0], 5),
"\nRSI[1]: ", DoubleToString(rsi[1], 5),
"\nStochastic: ", DoubleToString(stochMain[0], 2),
"\nNN Output: ", DoubleToString(NNOutPut, 5));
}
// --- Function to manage open positions ---
void ManagePositions()
{
for (int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong posTicket = PositionGetTicket(i);
if (PositionSelectByTicket(posTicket))
{
ENUM_POSITION_TYPE posType = (ENUM_POSITION_TYPE) PositionGetInteger(POSITION_TYPE);
double posOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
int points = (posType == POSITION_TYPE_BUY) ? (int)((bid - posOpenPrice) / _Point) : (int)((posOpenPrice - SymbolInfoDouble(_Symbol, SYMBOL_ASK)) / _Point);
if (points > TpPoints)
{
trade.PositionClose(posTicket);
}
}
}
}
//+------------------------------------------------------------------+
//| Neural Network Functions |
//+------------------------------------------------------------------+
void NormalizingInputs()
{
double LowerNormRange = -1;
double UpperNormRange = 1;
for (int i = 0; i < NumNodes; i++)
{
// Normalize RSI: here we simply assume [0, 100] range and map it [-1, 1]
NormalizedInputs[i] = (((NormalizedInputs[i] - 0) * (UpperNormRange - LowerNormRange)) / (100 - 0)) + LowerNormRange;
}
}
void OutPutLayerCalculation()
{
NNOutPut = HiddenLayerCalculation(NormalizedInputs, Weight);
}
double HiddenLayerCalculation(double &inputs[], double &Weights[])
{
double TotalWeightedInputs = 0.0;
for (int i = 0; i < ArraySize(inputs); i++)
TotalWeightedInputs += inputs[i] * Weights[i];
TotalWeightedInputs *= Coefficient;
return TanHActivationFunction(TotalWeightedInputs);
}
double TanHActivationFunction(double WeightedInputs)
{
return ((exp(WeightedInputs) - exp(-WeightedInputs)) / ((exp(WeightedInputs) + exp(-WeightedInputs))));
}
//+------------------------------------------------------------------+
Changes Made:
Neural Network Logic: I included the neural network logic from your first code directly into your existing EA. This involves the neural network's input normalization and output calculation functions.
Modified Entry Conditions: The decision to trigger a buy or sell now also considers the output of the neural network. For buying, the output must be greater than a defined target, while for selling it should be less.
Integration: The neural network uses the RSI values as input; you can further enhance this by adding more features as needed.
This combined approach allows your existing trading strategy to leverage the prediction capabilities of the neural network, which may enhance its decision-making process. Adjust the neural network parameters to suit the data characteristics you observe during testing or live trading.