trading-signals icon indicating copy to clipboard operation
trading-signals copied to clipboard

Replace and "What if" Scenarios

Open ozum opened this issue 1 year ago • 3 comments

Hi,

In the README I saw the replace feature:

// You can replace a previous value (useful for live charts):
sma.update('40', true);

However, it is unavailable for indicators such as DX. Any suggestions on replacing the last candle and the result of DX?

const dx = new DX(14);

// I want to see results for what-if scenarios.
const dxA = dx.update( { high: 10, low: 3, close: 2 } );

// I want to see the result without the previous update
const dxB = dx.update( { high: 8, low: 2, close: 6 }, true );

Thanks,

ozum avatar Apr 14 '24 16:04 ozum

Hi @ozum, the "replace" functionality is not yet available for all indicators. It's an early draft by @iam-rohid and myself and we are open to suggestions and Pull Requests.

bennycode avatar Apr 16 '24 09:04 bennycode

I have some thoughts, but first could you please check #668? If my findings in #668 are true, I will shape my suggestion accordingly.

ozum avatar Apr 16 '24 09:04 ozum

Hi @ozum, the DX indicator doesn't have the "replace" functionality yet. To build it, it would be necessary to cache all its internal states (so a previous and current value can be stored) and forward the replace parameter to every call of setResult like here: https://github.com/bennycode/trading-signals/blob/v5.0.3/src/DX/DX.ts#L87

bennycode avatar May 08 '24 13:05 bennycode