Based on our discussion, here are the key changes made to the script, upgrading it from the original version to the more robust version 5.0.
## 1. More Reliable Daily Pivot Calculation
The Old Way: The original script manually calculated the previous day's date and then scanned backwards through the chart's bars to find the high, low, and close. This method could be slow and potentially fail on charts with gaps or during month/year transitions.
The New Way: The script now uses the built-in
CopyRates
function to directly request the completedPERIOD_D1
(Daily) bar from the server. This is the official and most reliable method, ensuring the correct daily data is always used.
## 2. Immediate Display on First Load
The Old Way: Originally, the indicator would only draw pivots after the first session change occurred on the chart. This meant when you first loaded it, the current session's pivots would be missing.
The New Way: A new function,
InitialStateScan
, was added. It runs only once when the indicator is first loaded. It scans backwards to find the most recent session change, allowing it to calculate and display the pivots for the current session immediately.
Benefits of This Approach:
-
Speed: By avoiding manual loops through bars, you can calculate pivots faster, especially on instruments with a lot of history.
-
Accuracy: Using data directly from the server reduces the chance of calculation errors caused by gaps or missing bars.
-
Consistency: You're always working with fully completed daily bars, which ensures your pivots are based on the most reliable data.
No comments:
Post a Comment