Rank: Newbie
Groups: Registered, Registered Users, Subscribers Joined: 2/4/2021(UTC) Posts: 3 Location: Hamilton
|
Hi everyone. I am a newbie to the Metastock formula language and am just trying to find out what I've done wrong in the following code snippet. The code is designed to find the latest peak and trough in an oscillator and then find the highest and lowest prices within 5 bars of the oscillator peak/trough. Unfortunately, the code doesn't work, however, if I replace the variables TroughOffset and PeakOffset with constants, it works as expected. I have proven that the calculation of TroughOffset and PeakOffset variables is correct. Has anyone any idea on how I can fix this issue please. OSC:= Fml("My Oscillator");
PeakBar:=PeakBars(1,OSC,10);
TroughBar:=TroughBars(1,OSC,10);
TroughBar:=If(TroughBar<PeakBar,TroughBars(2,OSC,10),TroughBar); PeakOffset:=0-(PeakBar-4);
TroughOffset:=0-(TroughBar-4); PL:=ExtFml("ASI.LLV",ExtFml("ASI.Ref",L,TroughOffset),10);
PH:=ExtFml("ASI.HHV",ExtFml("ASI.Ref",H,PeakOffset),10); PL;
PH;
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,960
Thanks: 91 times Was thanked: 155 time(s) in 150 post(s)
|
Originally Posted by: rible172@icloud.com Hi everyone. I am a newbie to the Metastock formula language and am just trying to find out what I've done wrong in the following code snippet. The code is designed to find the latest peak and trough in an oscillator and then find the highest and lowest prices within 5 bars of the oscillator peak/trough. Unfortunately, the code doesn't work, however, if I replace the variables TroughOffset and PeakOffset with constants, it works as expected. I have proven that the calculation of TroughOffset and PeakOffset variables is correct. Has anyone any idea on how I can fix this issue please. OSC:= Fml("My Oscillator");
PeakBar:=PeakBars(1,OSC,10);
TroughBar:=TroughBars(1,OSC,10);
TroughBar:=If(TroughBar<PeakBar,TroughBars(2,OSC,10),TroughBar); PeakOffset:=0-(PeakBar-4);
TroughOffset:=0-(TroughBar-4); PL:=ExtFml("ASI.LLV",ExtFml("ASI.Ref",L,TroughOffset),10);
PH:=ExtFml("ASI.HHV",ExtFml("ASI.Ref",H,PeakOffset),10); PL;
PH;
Hi, Are you getting inaccurate values or no values at all? I replaced your Fml("My Oscillator") variable with RSI(14) and I did get the formula to return high/low price values.
|
|
|
|
Rank: Newbie
Groups: Registered, Registered Users, Subscribers Joined: 2/4/2021(UTC) Posts: 3 Location: Hamilton
|
Hi. Thanks for looking at that for me. Yes, I was getting a response and it was a valid high/low. The problem is that it is no where near the peak/trough of the oscillator.
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,960
Thanks: 91 times Was thanked: 155 time(s) in 150 post(s)
|
Originally Posted by: rible172@icloud.com Hi. Thanks for looking at that for me. Yes, I was getting a response and it was a valid high/low. The problem is that it is no where near the peak/trough of the oscillator.
Hi again and sorry for the delay, One thing that may help here is plotting the actual PeakOffset and TroughOffset outputs to see what they look like. When I do this, sometimes these numbers turn positive (indicating a forward reference for the Ref calls). When you use constants, are you always using negative numbers for the reference? Edited by user Friday, February 12, 2021 3:09:22 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Newbie
Groups: Registered, Registered Users, Subscribers Joined: 2/4/2021(UTC) Posts: 3 Location: Hamilton
|
Hi. Thank you for your feedback and I agree that we sometimes get positive results from the calculated offsets. This was not intended and I have modified my code to protect against this scenario.
Unfortunately, fixing this problem did not resolve my issue but it did make the results more consistent. It now appears to return the price 5 bars before the LLV/HHV search range. Still wrong but consistently wrong.
I have listed my new code below using the Stoch as the oscillator.
It would be very much appreciated if you could have another look at this for me. I would very much like to resolve this issue.
Thanks
STO := Stoch(5,3);
PeakBar:=PeakBars(1,STO,10);
TroughBar:=TroughBars(1,STO,10);
TroughBar:=If(TroughBar<PeakBar,TroughBars(2,STO,10),TroughBar);
PeakOffset:=0-PeakBar+2;
TroughOffset:=0-TroughBar+2;
PeakOffset:=If(PeakOffset>0,0,PeakOffset);
TroughOffset:=If(TroughOffset>0,0,TroughOffset);
PL:=ExtFml("ASI.LLV",ExtFml("ASI.Ref",L,TroughOffset),5);
PH:=ExtFml("ASI.HHV",ExtFml("ASI.Ref",H,PeakOffset),5);
PeakOffset;
TroughOffset;
PL;
PH;
|
|
|
|
Users browsing this topic |
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.