Your EA sounds intriguing with its dynamic risk management and neural network features. I’ll definitely test it out in the MetaTrader 5 strategy tester. I’ll share my results and any suggestions for improvements once I’ve had a chance to evaluate its performance.
I'm looking forward to your opinion on my EA :)
Code Explanation:
-
OpenTrades() Function:
- We analyze predictions from the neural network for three different timeframes: M5, M15, and H1.
- The results for each timeframe are collected and printed on the chart using the Comment() function, showing the predictions in percentages.
- If all predictions are greater than 60%, a buy order is placed.
-
GetPredictionForTimeframe() Function:
- This function retrieves price data (open, high, low, close, and volume) for a specified timeframe.
- It then normalizes the data and calculates the prediction using the neural network's forward pass.
- If data retrieval fails, it returns -1.0 , indicating an error.
-
Output on the Chart:
- The predictions for each timeframe will be displayed on the chart in the following format:
Neural Network Predictions:
Timeframe M5: 65.32%
Timeframe M15: 70.12%
Timeframe H1: 60.98%
This enhanced version of the EA ensures that trades are only executed if the neural network provides consistent buy signals across multiple timeframes, improving the accuracy of entry points.//+------------------------------------------------------------------+
//| Function to open trades based on neural network predictions from multiple timeframes |
//+------------------------------------------------------------------+
void OpenTrades()
{
// Timeframes for analysis
ENUM_TIMEFRAMES timeframes[] = {PERIOD_M5, PERIOD_M15, PERIOD_H1};
// Predictions for each timeframe
double predictions[];
// Check signals on each timeframe
for(int i = 0; i < ArraySize(timeframes); i++)
{
// Get prediction for the current timeframe
double prediction = GetPredictionForTimeframe(Symbol(), timeframes[i]);
// If prediction failed, exit the function
if(prediction == -1.0)
{
Print("Failed to get data for timeframe: ", EnumToString(timeframes[i]));
return;
}
// Store the prediction
ArrayResize(predictions, ArraySize(predictions) + 1);
predictions[ArraySize(predictions) - 1] = prediction;
}
// Print predictions on the chart
string comment = "Neural Network Predictions:\n";
for(int i = 0; i < ArraySize(timeframes); i++)
{
comment += StringFormat("Timeframe %s: %.2f%%\n", EnumToString(timeframes[i]), predictions[i] * 100);
}
Comment(comment); // Displays the comment on the chart
// If all predictions are greater than 60%, open a buy order
bool allBuySignals = true;
for(int i = 0; i < ArraySize(predictions); i++)
{
if(predictions[i] <= 0.6) // If any prediction is below 60%, don't buy
{
allBuySignals = false;
break;
}
}
if(allBuySignals)
{
// All timeframes indicate a buy signal, open a buy order
double lotSize = CalculateLotSize(Symbol());
SendOrder(Symbol(), lotSize, ORDER_TYPE_BUY);
}
else
{
Print("Buy signal is insufficient on one or more timeframes.");
}
}
//+------------------------------------------------------------------+
//| Function to get prediction for a specific timeframe |
//+------------------------------------------------------------------+
double GetPredictionForTimeframe(string symbol, ENUM_TIMEFRAMES timeframe)
{
MqlRates rates[];
// Get the last two candles for the specified timeframe
if(CopyRates(symbol, timeframe, 0, 2, rates) < 2)
{
Print("Error getting data for timeframe: ", EnumToString(timeframe));
return -1.0; // Return error
}
double inputs[INPUT_SIZE];
inputs[0] = rates[1].open;
inputs[1] = rates[1].high;
inputs[2] = rates[1].low;
inputs[3] = rates[1].close;
inputs[4] = (double)rates[1].tick_volume; // Cast volume to double
// Normalize input data
NormalizeInputs(inputs);
// Get the neural network prediction
double prediction = ForwardPass(inputs);
return prediction;
}
Conclusion:
This multi-timeframe approach makes the EA more robust, reliable, and adaptable to market conditions. It reduces the chance of false signals, improves trade accuracy, and provides a deeper analysis of market trends, which are all essential to a long-term profitable trading strategy.
// Apply penalty if daily profit is less than target if(dailyProfitPercent < g_dailyProfitTarget && !IsNewDay()) { // Implement penalty logic AdjustParametersForPenalty(); }
this condition is constantly run again and again if you try to do anything with your EA, and it won't place any trades at all. You need to fix bugs in your EA before you make a topic about it
Hello everyone,
I’ve developed an Expert Advisor (EA) that uses a simple neural network architecture to make buy and sell decisions based on historical price data. The EA includes some interesting features, such as dynamic stop-loss adjustments using the ATR indicator and a momentum-based optimization for training the neural network.
Here are some of the key features of the EA:
- Dynamic risk management per trade
- Daily and overall risk limitation
- Neural network implementation with adjustable learning rates
- Dynamic calculation of stop loss and take profit using ATR
I am currently working on improving this EA and would greatly appreciate it if some of you could take the time to test it in the MetaTrader 5 strategy tester and share your thoughts.
Questions for you:
- How does the EA perform in the strategy tester? What results did you achieve?
- Were there any specific situations where the EA performed particularly well or poorly?
- Based on your test results, what improvements would you suggest?
You can find the code attached. I’m looking forward to hearing your feedback and opinions!
Thanks in advance and best regards,
Seyyid Sahin
Hi
Why are you decreasing the learning rate as a penalty ?
Shouldn't you be increasing the learning rate if things are "wrong" ?
Also you can have an input on top where the user can select to "train" the EA .
This way the file can be saved in the folders outside tester , available for use without the user moving files around .
Btw. you might experience a little performance improvement when you replace function call with inline function for your Sigmoid(), ReLU() and ReLUDerivative()
And avoid repeat call to ArrayResize, when the size is not changing.
I understand for code clarity, it's nice to use dedicated functions.
Good luck.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone,
I’ve developed an Expert Advisor (EA) that uses a simple neural network architecture to make buy and sell decisions based on historical price data. The EA includes some interesting features, such as dynamic stop-loss adjustments using the ATR indicator and a momentum-based optimization for training the neural network.
Here are some of the key features of the EA:
I am currently working on improving this EA and would greatly appreciate it if some of you could take the time to test it in the MetaTrader 5 strategy tester and share your thoughts.
Questions for you:
You can find the code attached. I’m looking forward to hearing your feedback and opinions!
Thanks in advance and best regards,
Seyyid Sahin