Fear and Greed Function - MetaTrader 5 Script | Forex Indicator Download - MT4/MT5 Resources
As we all know, markets are primarily driven by two emotions: fear and greed.
The script implements a class with variables and functions to embody these sentiments in a mathematical model suitable for trading markets.
Furthermore, mathematical models of motivation, pressure, confidence and activity are shown here - what makes you or your program perform or stop trading operations.
Confidence – shows overall level of trading skill.
Activity can be compared to an organism's periods of activity and rest.
This can be applied to expert advisors or indicators.
The fear scores in this model range from -1 to inf, the greed scores range from 0 to inf, and the motivation, stress, and activity scores range from 1 to -1.
Fear increases as it approaches -1 or disappears near 0, transforming into euphoria at positive values. Fear is strategic. Stress has the same meaning as fear, but has a different tactical meaning during trading. Greed, in turn, ranges from 0 to inf, where: 1 is the normal state, as fear increases, greed decreases to 0, as fear turns into euphoria, greed becomes higher than 1 and multiplies more than 100% of profits. Greed is strategic and motivation approaches tactical significance. The motivation value in the normal state is close to zero, increases as the profit is negative, on the contrary, decreases as the daily target is approached, and becomes negative when the profit is higher than the daily target.
Therefore, it can be used, for example, in programs using fuzzy logic, where it is necessary to use fear, pressure, confidence , an activity and motivation function to open a new trade transaction or close an existing one, and using a greedy function you can regulate the trading volume.
Most of the variables are easy to understand, so I'll only explain a few of them.
Some variables explained:
0) Sensitivity is adjusted from 0 to 1: 0 - coward, 0.5 - normal, 1 - brave. In other words, it turns out that those who are timid are safer and those who are brave are more dangerous.
This can be useful, for example, when your trading expert has accumulated a certain amount of experience in trading, which can be expressed in terms of a positive mathematical expectation - in this case, you can gradually change the sensitivity value in the positive direction, and if the result is negative, you can gradually reduce this parameter.
1) The number of trading operations expected during the recovery period means:
It depends on your trading style: - How many trades do you make over a period of time, and accordingly, how many trades do you plan to restore sagging deposits to their previous levels?
In theory, the higher this value, the less fear you have when your balance decreases - that is, if you plan to restore your balance to its previous value in infinite steps, then you don't have to worry at all.
I don't know yet how to calculate this value, or it simply doesn't exist.
This should be viewed as some kind of ideal that you or your trading professional should strive for. In my opinion, the ideal value here is 3 to 5, or in rare cases up to 10.
2) In this model, there are 3 weight coefficients and 3 amplification switches with appropriate values, which are used to calculate the final degree of fear, and are composed of three parts:
You can change them to your liking - weights range from 0 to 12, and amps are true or false:
- Worry about reduced savings,
- Worry about increasing negative profits,
- Worry about margin calls.
Most of the features are easy to understand, so I'll only explain a few of them.
0) During the first initialization, if the account balance is greater than the current account balance, you can enter the previous state, and then with each change in that balance, you must call the "TrailInitialBalance()" function so that the program takes these changes into account.
1) How to use the function "SetWeightFactors()"? :
For example, the margin call fear factor should be adjusted based on leverage - the higher the leverage, the higher the ratio should be and vice versa, or when the leverage is 1:1, this value should be set to 0. The same must be done for the other two parameters - you need to decide which is more important to you in the current situation: a strategic reduction of the balance or a tactical reduction of the current profit on the account. The remaining two parameters can be changed dynamically.
In general, this is very useful for novice traders as a guide to executing or stopping trades and calculating trade volume and trading results. To do this, run the script in the chart window and make multiple manual trades and see how the values change in real time. Multiply the initial trading volume by the greed value and then open or close existing trading positions based on factors such as fear, stress, fear, activity and motivation values. The closer the stress level is to -1 or the closer the motivation level is to negative values, the more you should consider taking a break and postpone trading for the next period.
If you have any questions, please feel free to write to me and I will try to answer them.
Attachment download
📎 fearlgreed.mq5 (13.16 KB)
📎 fearygreed_r.mq5 (85.48 KB)
Source: MQL5 #41665
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •