IF IT AIN'T BROKE, DON'T FIX IT

FX Markets

Wrote a Pivots Key to success

 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 completed PERIOD_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:

  1. Speed: By avoiding manual loops through bars, you can calculate pivots faster, especially on instruments with a lot of history.

  2. Accuracy: Using data directly from the server reduces the chance of calculation errors caused by gaps or missing bars.

  3. Consistency: You're always working with fully completed daily bars, which ensures your pivots are based on the most reliable data.

Share:

No comments:

Post a Comment

S&P 500

Crypto

World Clock

Bloomberg

MTV Rocks

    Wikipedia

    Search results

    News

    Powered by Blogger.

    Blog Archive

    Popular Posts

    Pages