Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 600 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 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