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

projection osclliator returns negative values and values greater than 100 PO values range should be [0 -> 100] on node-js environment. #218

Open
devspatron opened this issue Dec 6, 2022 · 4 comments · May be fixed by #329
Assignees

Comments

@devspatron
Copy link

I tried to compute the projection oscillator for 15min frxGBPUSD candles, the total number of candles were 5000, in number. The projection oscillator returns negative values and values greater than 100 PO values range should be [0 -> 100] . The package function package.projectionOscillator returns an object res = { po:[ items ], spo:[ items ] };

  1. The res.po returned 227 <= 0 and 615 >=100, sample arrays as follows respectively.
    res.po less than 0
    po-less-0

res.po greater than 100
po-greater-100

  1. The res.spo returned 227 <= 0 and 610 >=100, sample arrays as follows respectively.
    res.spo less than 0
    spo-less-0

res.spo greater than 100
spo-greater-100

@devspatron devspatron changed the title projection osclliator returns negative values and values greater than 100 PO values range should be [0 -> 100] projection osclliator returns negative values and values greater than 100 PO values range should be [0 -> 100] on node-js environment. Dec 6, 2022
@cinar
Copy link
Owner

cinar commented Dec 6, 2022

Thank you for filing a bug for it. You are right, it should be returning numbers between 0 and 100. There must be something wrong here. I'll take a look definitely. If you see anything in the code that is not right, please do let me know as well.

@cinar cinar self-assigned this Dec 6, 2022
@abhishekmittal15
Copy link
Contributor

Hi, is this issue resolved or is someone working on it currently? Else I would like to look into this, if its fine.

@cinar
Copy link
Owner

cinar commented Jun 27, 2023

Hi Abhishek, Not yet fixed, and no active development on this as of now, so please feel free to take it.

@abhishekmittal15
Copy link
Contributor

abhishekmittal15 commented Jun 28, 2023

Since this same issue was also raised in the indicator go repo. I am referring to the same resources that were pointed out there to implement this indicator.
File: projectionOscillator.ts

Our Code

const x = generateNumbers(0, closings.length, 1);
const lsHighs = movingLeastSquare(period, x, highs);
const lsLows = movingLeastSquare(period, x, lows);

const vHighs = add(highs, multiply(lsHighs.m, x));
const vLows = add(lows, multiply(lsLows.m, x));

According to the resources the pseudo code looks as follows:

Pseudo Code

//method = user defined, default is EMA
//pboPeriod = user defined, default is 14
//sigPeriod = user defined, default is 3
//index = current bar number, LOE = less or equal

mHigh = linRegLine(period, high)[1];   //returns the slope (m) of Linear Regresion line
mLow = linRegLine( period, low)[1];
count = 0;
pbw = 0, pu = 0, pl = Double.MAX_VALUE;
for (i = (index-pboPeriod + 1); i LOE index; i++)   //move back 1 period
    high = high[i];
    low = low[i];
    vHigh = high + (mHigh * (count));
    vLow = low + (mLow * (count));
    if (vHigh moreThan pu) pu = vHigh;
    if (vLow lessThan pl) pl = vLow;
    count++;
endFor
Plot1: PBO = 100 * (price - pl) / (pu - pl);
Plot2: SIG = ma(method, sigPeriod, pbo);
buy = crossedAbove(PBO, SIG);
sell = crossedBelow(PBO, SIG);

I think the error is in calculating vHighs and vLows

Possible Error

In this pseudo code, they are calculating the indicator value on each incoming bar(represented by index). So in every single window( of size =pboPeriod) they are multiplying the mHigh with an array of [0,...,pboPeriod-1]. Whereas we are mutiplying our lsHighs.m[index] with x[index].
I could be wrong here, but this is what I inferred. What do you think about this?

Also any suggestions on how I can verify the correct working of the indicator(example: sample data along with correct values of indicator)?

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 a pull request may close this issue.

3 participants