Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parabolic SAR #780

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Parabolic SAR #780

wants to merge 7 commits into from

Conversation

real-lazy-coder
Copy link
Contributor

Parabolic SAR (PSAR) Type: Trend

The Parabolic Stop and Reverse (PSAR) is a technical indicator that identifies potential reversals in the price movement of an asset. It appears as a series of dots placed either above or below the price, depending on the direction the price is moving. The indicator is used to determine the direction of a trend, identify potential entry and exit points, and set trailing stop-loss orders.

Checklist for new indicators

  • Indicator is documented and implemented by extending BigIndicatorSeries
  • A "faster" version of this indicator is implemented by extending NumberIndicatorSeries
  • Tests for getResult are present
  • Tests for highest and lowest result caching are present (if not already existent for base class)
  • Tests for error handling are present (if not already existent for base class)
  • Indicators (standard & faster version) are exposed in src/index.ts
  • Indicators (standard & faster version) are added to startBenchmark.ts
  • Indicator is listed in README.md

@bennycode
Copy link
Owner

@real-lazy-coder brilliant PR! 👌 Thanks for doing all the work. It is just missing some test coverage. Have you tried EarlyAI to generate test code? Or the Cursor AI Editor?

real-lazy-coder and others added 2 commits March 16, 2025 21:26
@real-lazy-coder
Copy link
Contributor Author

@bennycode I'm on the struggle bus. For the life of me I cannot figure out how to get 100% test coverage on the PSAR.

 ParabolicSAR.ts         |     100 |    97.67 |     100 |     100 | 108,152   

These are edge cases and I'm at a loss. Any guidance?

@real-lazy-coder
Copy link
Contributor Author

@real-lazy-coder brilliant PR! 👌 Thanks for doing all the work. It is just missing some test coverage. Have you tried EarlyAI to generate test code? Or the Cursor AI Editor?

I'm using Claude Code quite a bit these days. But it's 🔥 my 💰 at a blazing fast rate!

I'll look into EarlyAI. Thanks,

@bennycode
Copy link
Owner

bennycode commented Mar 17, 2025

These are edge cases and I'm at a loss. Any guidance?

I ran the tests and reviewed the HTML output in the /coverage directory. It looks like we need to cover scenarios where it falls back to previousLow (line 108):

sar = previousLow.lt(sar) ? previousLow : sar;

Similarly, we should add a test case where it falls back to previousHigh (line 158):

sar = previousHigh.gt(sar) ? previousHigh : sar;

@bennycode
Copy link
Owner

@real-lazy-coder I was able to write tests for the missing cases -> real-lazy-coder#1

Example:

it('adjusts the SAR when the previous low is lower than the pre-previous low', () => {
  const psar = new PSAR({accelerationMax: 0.2, accelerationStep: 0.02});
  const prePreviousLow = 8;
  const previousLow = 7;

  psar.add({high: 10, low: 9});
  psar.add({high: 11, low: prePreviousLow});
  psar.add({high: 12, low: previousLow});

  expect(psar.getResultOrThrow().toString()).toBe('12');
});

@bennycode
Copy link
Owner

@real-lazy-coder shall we get this in? 😀

@real-lazy-coder
Copy link
Contributor Author

I have 1 last line I need to write a test for. I'm currently on vacation with my family. I will get this finalized when I return next week.

1 similar comment
@real-lazy-coder
Copy link
Contributor Author

I have 1 last line I need to write a test for. I'm currently on vacation with my family. I will get this finalized when I return next week.

@bennycode
Copy link
Owner

I have 1 last line I need to write a test for. I'm currently on vacation with my family. I will get this finalized when I return next week.

Sure! Take it easy and enjoy the vacation with your loves ones. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants