Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 744 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 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: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
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