Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 11/23/2005(UTC) Posts: 22 Location: Chicago, Illinois
|
Need some help please. How can I intialize a constant value in MS? The manual is no help on this. I'm writing a trivial exploration where the price at t-n is within the channel formed by the high and low at t, + and - a specified percentage.
It seems the constant values for my channel are constantly changing rendering my algorithm useless. The code:
{ change the next 3 lines to change search criteria } upPct:=.20; { 20 % } dwnPct:=.20; { 20 % } lookBack:=10;
baseHigh:=ref(H,0); baseLow:=ref(L,0);
upLimit:=baseHigh+(baseHigh*upPct); dwnLimit:=baseLow-(baseLow*dwnPct);
hiHigh:=HHV(H,lookBack); lowLow:=LLV(C,lookBack);
{ if condition is true, return 1, els, return 0 } If( upLimit <= hiHigh AND dwnLimit >= lowLow, 1, 0 )
Thanks in advance
G
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/7/2005(UTC) Posts: 602
|
It's doing what you told it to do. I don't like Ref(H,0), since Ref(H,0)=H, just use H. What do you think the indicator should be doing, or what do you want it to do?
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 11/23/2005(UTC) Posts: 22 Location: Chicago, Illinois
|
I want to initialize those 2 values, baseHigh and baseLow as const variables, i.e., non-mutable. I want these to be set to the H and L values as they are today, right now, the day this exploration is run. Then, if the prior H and L for 10 days, or periods, falls within the calculated channel of the H and L at t sub 0, I want to return a boolean true, else, return a false.
The current program changes the vase values to the OHLC value of every period examined, which makes the channel value useless. The manual's explanatio of ref() gives the impression that the value at a given time is returned, i..e., 0, but that is now what happens. So the script does what I asked, but not what I wanted. Hence, I'm asking the gurus that frequent this forum.
Garp
{ change the next 3 lines to change search criteria } upPct:=.20; { 20 % } dwnPct:=.20; { 20 % } lookBack:=10;
/* const */ baseHigh:=ref(H,0); // how do I do this??? /* const */ baseLow:=ref(L,0); // how do I do this ???
upLimit:=baseHigh+(baseHigh*upPct); dwnLimit:=baseLow-(baseLow*dwnPct);
hiHigh:=HHV(H,lookBack); lowLow:=LLV(C,lookBack);
{ if condition is true, return 1, els, return 0 } If( upLimit <= hiHigh AND dwnLimit >= lowLow, 1, 0 )
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/7/2005(UTC) Posts: 602
|
Use the functions year(), month() and dayofmonth() to nail down the exact point of time you want to start. Use Valuewhen() to extract the H or L.
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 11/23/2005(UTC) Posts: 22 Location: Chicago, Illinois
|
Thanks johnl,
Following the MetsStock manual, I changed the initialization code to:
myDay:=3; myMon:=11; myYear:=2009; myHr:=0; myMin:=0;
start::= myDay=DayOfMonth() AND myMon=Month() AND myYear=Year() AND myHr=Hour() AND myMin=Minute();
baseHigh:=ValueWhen(1,start,H);
However, it does not work. Is the above correct?
G
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Unverified Users Joined: 7/12/2007(UTC) Posts: 134 Location: Perth Western Australia
|
Hi G,
You were so close with this first attempt that if I said, as a reminder, that the code calculates from left to right then you would understand that your "baseHigh" and "baseLow" must be before the current High & Low (e.g. Ref(H,-lookBack) & Ref(L,-lookBack)
I would also suggest that you take a closer look at the order of your "If staement".
Cheers,
oz
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 11/23/2005(UTC) Posts: 22 Location: Chicago, Illinois
|
Thanks OZ, But the problem with attempt # 1 was the way the initial values are initialized. Doing baseHigh:=ref(H,0); implicitly gives me a range of values corresponding to whatever the high value of the current tick bar happens to be at the time. This is not what I want. So, as per johnl, I tried the valueWhen() call and just put together a bit of test code. Here: Thanks johnl,
Following the MetsStock manual, I changed the initialization code to:
myDay:=3; myMon:=11; myYear:=2009; myHr:=0; myMin:=0;
start:= myDay=DayOfMonth() AND myMon=Month() AND myYear=Year() AND myHr=Hour() AND myMin=Minute();
baseHigh:=ValueWhen(1,start,H);
So, I grab the high value on 11/3 and initialise baseHigh. I plot this variable on the screen to debug. I expected a straight line touching the high on 11/3 but got a big nothing. I stared at the definition of valueWhen(<int period>, <bool condition>, <array>); and I am conforming to the call standard. I assume it returns a numeric. There is nothing wrong that I can see. G
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Unverified Users Joined: 7/12/2007(UTC) Posts: 134 Location: Perth Western Australia
|
G,
Using most of the code from your 1st attempt and 3 minor changes try running this code and see if this gives you what you're chasing.
upPct:=0.0; {0.0=0% ; 0.2=20%} dwnPct:=0.0; {0.0=05 ; 0.2=20%} lookBack:=10; {# bars to form consolidation period} baseHigh:=Ref(H,-lookBack); baseLow:=Ref(L,-lookBack); upLimit:=baseHigh + (baseHigh*upPct); dwnLimit:=baseLow - (baseLow*dwnPct); hiHigh:=HHV(H,lookBack+1); lowLow:=LLV(L,lookBack+1); If(hiHigh <= upLimit AND lowLow >= dwnLimit,1,0)
I have changed the "upPct" & "dwnPct" to 0 initially as it makes it much easier to do a visual check that the code is working correctly.
A value of 1 indicates that there has been consolidation for a 10 bar period.
Cheers,
oz
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/7/2005(UTC) Posts: 602
|
If oztrader hasn't got it: Below will give you the high of 3/11/2009 as a constant. start:=If(DayOfMonth()=11 AND Month()=3 AND Year()=2009,1,0); baseHigh:=ValueWhen(1,start=1,H); baseHigh
|
|
|
|
Users browsing this topic |
Guest (Hidden)
|
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.