Trough function with negative value

Hi,
I need to find Troughs of CCI Indicator using trough function.
I explore and find the issue: points are always troughs if their value are negative.
I attach my testing afl code and the result below

Blockquote i = BarCount;
x = cum(1);
per = 3;
p = 20;
ccip = cci(p);
s1 = ccip;
ps = troughBars(s1,per,1) == 0;
AddColumn(s1,"s1");
AddColumn(pS,"pS");
Filter=1;

Blockquote

The same code worked with RSI

i = BarCount;
x = cum(1);
per = 3;
p = 20;
rsip = rsi(p);
s1 = rsip;
ps = troughBars(s1,per,1) == 0;
AddColumn(s1,"s1");
AddColumn(pS,"Rsi");
Filter=1;

Blockquote

I searched forum and the help file but can not find the answer.
Please help me to fix it.
Sorry for my bad languague.
Thank for your help!

Trough function is intended to be used with PRICES that are in almost all cases positive. If you want to (ab)use the function for negative numbers, just add constant large enough so all negatives become positive.

Could you please tell me more detail about this?
As you can see in my result, there are 3260 rows of CCI value and i think possitive and negative numbers have same amount.

I work around by define array like this

p = 20;
ccip = cci(p);
s1 = ccip;
ps = s1>Ref(s1,-1) AND Ref(s1,-2)>Ref(s1,-1);
ps2 = Ref(ps,-1);
AddColumn(s1,"Cci");
AddColumn(ps,"ps");
AddColumn(ps2,"Trough");
SetSortColumns(-2);
Filter=1;

As i know, ps2 is ps1 shift one day ago, but the result is one day later


Could you please clarify.

My misunderstanding, i know the result.
Thank for your help Tomasz!

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.