Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (alibaba, vicknick), 1,492 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Compare indicator value to the highest value n bars ago #487298
03/06/23 18:26
03/06/23 18:26
Joined: Feb 2023
Posts: 14
D
DonDiego Offline OP
Newbie
DonDiego  Offline OP
Newbie
D

Joined: Feb 2023
Posts: 14
Hi

I do want to compare the current value of a MovingAverage to a the highest value within the last 9 bars, excluding the current one, as a condition in an IF-statement.

something like if MA > Highest(MA,9)[1] then do this and that

I've found HH() but seems only to be useable for priceData and not an indicator.
MaxVal() expect to use series. So I did try:
Code
 if(MA>MaxVal(MA[1],9)

but that throws an error (pointer expected).

I probably could find out what I need with a loop, but that seems to be an overkill and somehow inefficient for my little task.

Re: Compare indicator value to the highest value n bars ago [Re: DonDiego] #487299
03/06/23 18:57
03/06/23 18:57
Joined: Feb 2016
Posts: 15
Russia
nsg Offline
Newbie
nsg  Offline
Newbie

Joined: Feb 2016
Posts: 15
Russia
Assuming MA is a series, you can't use MA[1] within a function that takes a series as an imput. By using MA[1] you're sending a float to it.
The correct syntax is if(MA[0]>MaxVal(MA,9)). This way, you compare float (MA[0]) with another float resulting from evaluation of MaxVal(MA,9).

Re: Compare indicator value to the highest value n bars ago [Re: DonDiego] #487301
03/06/23 19:42
03/06/23 19:42
Joined: Feb 2023
Posts: 14
D
DonDiego Offline OP
Newbie
DonDiego  Offline OP
Newbie
D

Joined: Feb 2023
Posts: 14
Alright, so your version of the code runs without error, but when I play with the lookback period it doesn't make a difference whether I put in 3, 9, 50 or 100. The result is always the same.

On the Financial Hacker website Petra uses some code in the detecting volume breakout article, which I tried to translate to my needs. The result is:
Code
MA[0] > MaxVal(series(MA[1],10),9)


This kind of works, but I don't know how to verify if the code calculates what I had in mind.

Re: Compare indicator value to the highest value n bars ago [Re: DonDiego] #487302
03/06/23 21:46
03/06/23 21:46
Joined: Aug 2017
Posts: 295
Netherlands
G
Grant Online
Member
Grant  Online
Member
G

Joined: Aug 2017
Posts: 295
Netherlands
Maybe there are no trades made during the first 100 days? Use 'set(LOGFILE);' to find out.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1