in Search

consolidation detector

Last post 11-04-2009, 19:19 by johnl. 8 replies.
Sort Posts: Previous Next
  •  11-01-2009, 7:37 31064

    consolidation detector

    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

  •  11-01-2009, 18:28 31067 in reply to 31064

    Re: consolidation detector

     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?
  •  11-01-2009, 19:28 31068 in reply to 31064

    Re: consolidation detector

    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 )

  •  11-02-2009, 19:16 31082 in reply to 31068

    Re: consolidation detector

     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.
  •  11-03-2009, 21:37 31092 in reply to 31082

    Re: consolidation detector

    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

  •  11-04-2009, 3:30 31096 in reply to 31064

    Re: consolidation detector

    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

  •  11-04-2009, 12:55 31103 in reply to 31096

    Re: consolidation detector

    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
  •  11-04-2009, 17:31 31104 in reply to 31103

    Re: consolidation detector

    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

  •  11-04-2009, 19:19 31106 in reply to 31104

    Re: consolidation detector

         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

View as RSS news feed in XML