post1295570324.html#p1295570324
1. The Scaling Problem on XAUUSD and BTCUSD (The "Squeezed" Indicator)
You are 100% correct in your diagnosis. This is the primary issue with the indicator, and it's a classic one when mixing normalized values with price-based values.
The Cause:
Your histogram (Buffers 0, 1, 2) is normalized to a 0-100 scale. This is excellent.
However, your moving averages (Buffers 3 and 4) are calculated directly on the price using iMA(..., PRICE_CLOSE, ...).
For USDJPY, the price might be ~157. The indicator window tries to display both 0-100 and 0-157, which is manageable.
For XAUUSD (Gold), the price is ~2350. The window must now scale from 0 to 2350. Your 0-100 histogram becomes a tiny, "squeezed" line at the very bottom.
For BTCUSD, the price is ~65,000. The effect is even more extreme.
The Solution:
We need to make all plotted data exist on the same scale. The logical choice is to calculate the moving averages on your normalized_ohlc_avg value, not the raw PRICE_CLOSE. This will keep all five indicator buffers within the 0-100 range.
Since iMA can't be used on a custom calculated array directly inside the loop, we will calculate the MAs manually. It's a great learning exercise.
2. The 100% Win-Rate / High Loss-Rate Confusion
This is a very common point of confusion when starting out.
The Explanation:
The code you have written is an indicator, not an Expert Advisor (EA). An indicator's job is to draw lines and histograms on the chart to help you make trading decisions. It does not execute trades itself.
The win-rate and loss-rate statistics you are seeing are from the Strategy Tester's report of your manual trades. When you run the tester in visual mode and "pick trades as and when I would," the tester is logging your manual clicks as trades.
100% Accuracy: This likely means that in one test session, you placed one or more trades, and they all closed in profit. If you place one trade and it wins, the win rate is 100%.
High Loss Rate: This would be from a different backtest run where you placed trades that resulted in losses.
There are no bugs in your code causing this. The indicator has no concept of "winning" or "losing." It only calculates and displays values. The statistics are a reflection of your own trading performance during the visual test.
3. Code Review and Improvements
Your idea is very interesting! It's essentially a custom oscillator that measures the position of a smoothed price ((O+H+L+C)/4) within a recent price range. This is a solid foundation. Here are my suggestions for improvement, which I will implement in the final code below.
A. Critical Fix: Fix the Scaling Issue (as discussed above)
We will calculate the EMA and SMMA manually on the normalized 0-100 values.
B. Add Visual Threshold Levels
An oscillator is much easier to read if it has lines showing the thresholds. We can add horizontal lines at your Bullish_Threshold and Bearish_Threshold values.
C. Add More Useful Alerts
The MA crossover alert is good, but the primary signal of your indicator seems to be when the histogram enters the "Bullish" or "Bearish" zones. We should add alerts for this as well.
D. Minor Code Refinements
The code is already good, but we'll make a few small tweaks for robustness and clarity during the rewrite. For example, we'll create a dedicated buffer to hold the normalized value before it's split into the three color buffers, which simplifies the MA calculations.
The Improved and Corrected Code
Here is the full, updated MQ4 file. I have commented on the new and changed sections so you can see exactly what was done.
Key Changes:
Added a new buffer (Normalized_OHLC_Avg_Buffer) to hold the 0-100 value. This makes it easy to calculate MAs on it.
OnCalculate is rewritten to manually calculate the EMA and SMMA on the normalized values. The iMA calls are removed.
Added #property indicator_level... to draw horizontal lines at your thresholds.
Added new extern parameters and logic for histogram-based alerts (crossing into bullish/bearish zones).
Copy and paste this entire code into a new file in MetaEditor. It will solve all the issues you've described.
Re: Something interesting from Chatgpt/AI please post here
241"My Forex Holy Grail? Sure, I'll share it. It's a magical PDF that costs $997 and the first chapter is titled: 'How to Sell a $997 PDF.'"