1. Understanding Perceptrons
Welcome to the world of Perceptrons! If you're curious about how simple neural networks operate, check out this insightful resource by Dr. Mark Humphrys.
In the context of trading, I liken it to the logic behind an Expert Advisor (EA) that leverages these concepts.
2. The Algorithm
Let's break it down.
2.1. Inputs
The variables w1, w2, w3, and w4 represent weights that you’ll set based on your optimization preferences.
input int x1 = 0;//weight1 input int x2 = 0;//weight2 input int x3 = 0;//weight3 input int x4 = 0;//weight4
2.2. The Perceptron
For our simple EA, we set the threshold to zero. The output will be either "fires" (1) or "does not fire" (0).

double w1 = x1 - 100; double w2 = x2 - 100; double w3 = x3 - 100; double w4 = x4 - 100; // Perceptron before one bar 2017/03/18 double a11 = ((iRSI(Symbol(), 0, 12, PRICE_MEDIAN, 1))/100-0.5)*2; double a21 = ((iRSI(Symbol(), 0, 36, PRICE_MEDIAN, 1))/100-0.5)*2; double a31 = ((iRSI(Symbol(), 0, 108, PRICE_MEDIAN, 1))/100-0.5)*2; double a41 = ((iRSI(Symbol(), 0, 324, PRICE_MEDIAN, 1))/100-0.5)*2; double Current_Percptron = (w1 * a11 + w2 * a21 + w3 * a31 + w4 * a41); // Perceptron before two bars 2017/03/18 double a12 = ((iRSI(Symbol(), 0, 12, PRICE_MEDIAN, 2))/100-0.5)*2; double a22 = ((iRSI(Symbol(), 0, 36, PRICE_MEDIAN, 2))/100-0.5)*2; double a32 = ((iRSI(Symbol(), 0, 108, PRICE_MEDIAN, 2))/100-0.5)*2; double a42 = ((iRSI(Symbol(), 0, 324, PRICE_MEDIAN, 2))/100-0.5)*2; double Pre_Percptron = (w1 * a12 + w2 * a22 + w3 * a32 + w4 * a42);
While I've used the RSI indicator for this EA, feel free to experiment with other oscillators like RCI or W%R!
2.3. Order Opening and Closing
If the previous Perceptron is below 0 and the current one is above, close any short positions. This signals the EA to send a long order.
if(Pre_Percptron < 0 && Current_Percptron > 0) // long signal { // Close short position if it exists if(pos < 0) { ret = OrderClose(Ticket, OrderLots(), OrderClosePrice(), 0); if(ret) pos = 0; // Position status reset } // Send long order if no position exists if(pos == 0) Ticket = OrderSend(_Symbol, OP_BUY, Lots, Ask, 0, 0, 0, Trade_Comment, MagicNumber, 0, Green); }
On the flip side, if the current Perceptron is below 0 and the previous one is above, close any long positions and send a short order.
3. Optimization
To optimize, load the "Slime_Mold_RSI_template.set" and select "open price only" for the model.


4. Comments and Magic Number
The Magic Number is set to the duration used for optimization, and this EA utilizes it in the comments.
string Trade_Comment = IntegerToString(MagicNumber,5,' ') + "Days-Optimization";

5. Related Article
For further reading, you might find this article helpful: Check it out here!
연관 포스트
- How to Fetch High Impact Events from Forex Factory for Your EA
- RRS Impulse: Your Go-To Scalping EA for MetaTrader 4
- Mastering Visual Order Processing with MetaTrader 4
- Mastering Take Profit Strategies in MetaTrader 4: A Local Trader’s Guide
- Unlocking the AK-47 Scalper EA: Your Ultimate MetaTrader 4 Companion