in Search

How to handle time function?

Last post 05-26-2007, 12:36 by patt. 5 replies.
Sort Posts: Previous Next
  •  05-24-2007, 12:46 24134

    How to handle time function?

    I would like to plot an indicator for intraday chart, starting at the specific timing. Here is the code :

    Dy:=Input ("Day ",1,31,1);
    Mo:=Input ("Month ",1,12,1);
    Yr:=Input ("Year ",2005,2010,2007);
    Hr:=Input ("Hours 01 - 24",1,24,9);
    Mn:=Input ("Minutes 00 -59",00,30,30);
    Prd:=Input ("LookBack ",3,25,7);

    X:=BarsSince(DayOfMonth()=Dy AND Month()=Mo AND Year()= Yr AND Hour()=Hr AND Minute()=Mn);

    MyHigh::= HighestSince(1,x=0,H);
    Plt := MyHigh*ATR(Prd);
    Plt ;

    The starting point sometime works but often doen't.

    Another pont is : what should I do if I have more than 6 inputs since this is over the limit .

    Thanks for your advice.
  •  05-24-2007, 21:31 24136 in reply to 24134

    Re: How to handle time function?

    Patt, your code fails when the selected date falls on a bar with no data in it (N/A or null bar).

    I'm unable to post your code solution in this forum due to copyright issues.
    Please re-post your MetaStock query at the Trader's Consortium MetaStock forum, and I will have a solution ready for you there.


    jose '-)
    MetaStockTools.com
  •  05-24-2007, 23:01 24138 in reply to 24134

    Re: How to handle time function?

    Patt,

    A common problem when people use the "=" comparison is they forget that very rarely will this ever be true, so their code often fails.

    With respect to dates, if there is not a bar on the chart with exactly the same date and time information that you have in your filter, the equality condition will never be met.  You need to ensure you trap all of the other possibilities too:

    Code:

    Dy:=Input ("Day ",1,31,1);
    Mo:=Input ("Month ",1,12,1);
    Yr:=Input ("Year ",2005,2010,2007);
    Hr:=Input ("Hours 01 - 24",1,24,9);
    Mn:=Input ("Minutes 00 -59",00,30,30);
    Prd:=Input ("LookBack ",3,25,7);

    x:=
    (Year() > yr) OR
    (Year() = yr AND Month() > mo) OR
    (Year() = yr AND Month() = mo AND DayOfMonth() > dy) OR
    (Year() = yr AND Month() = mo AND DayOfMonth() = dy and Hour() > hr) OR
    (Year() = yr AND Month() = mo AND DayOfMonth() = dy and Hour() = hr AND Minute() >= mn);

    MyHigh:= HighestSince(1,barssince(x)=0,H);
    Plt:=MyHigh*ATR(Prd);
    Plt;


    Untested....

    You might want to reconsider the barssince() condition too?  I don't think the code is doing what you expected it to?   You might want to try cum(isdefined(x))=1 instead?


    Hope this helps.

    wabbit Big Smile [:D]


    MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC & MDK
    For custom MetaStock programming : http://www.wabbit.com.au
    My SkyPE status : wabbit.com.au SkyPE online status
    My SkyPE account : wabbit.com.au

  •  05-25-2007, 10:42 24146 in reply to 24138

    Re: How to handle time function?

    This help a lot. I will look around and might come back for more questions :-)
  •  05-25-2007, 13:31 24147 in reply to 24138

    Re: How to handle time function?

    Patt, your working code solution is waiting for you here.


    wabbit:
    Code:

    Dy:=Input ("Day ",1,31,1);
    Mo:=Input ("Month ",1,12,1);
    Yr:=Input ("Year ",2005,2010,2007);
    Hr:=Input ("Hours 01 - 24",1,24,9);
    Mn:=Input ("Minutes 00 -59",00,30,30);
    Prd:=Input ("LookBack ",3,25,7);

    x:=
    (Year() > yr) OR
    (Year() = yr AND Month() > mo) OR
    (Year() = yr AND Month() = mo AND DayOfMonth() > dy) OR
    (Year() = yr AND Month() = mo AND DayOfMonth() = dy and Hour() > hr) OR
    (Year() = yr AND Month() = mo AND DayOfMonth() = dy and Hour() = hr AND Minute() >= mn);

    MyHigh:= HighestSince(1,barssince(x)=0,H);
    Plt:=MyHigh*ATR(Prd);
    Plt;

    There are a number of reasons why the code above cannot work:

    1) Six Input function errors;

    2) Invalid variable name "mo" - a variable cannot be assigned a name that matches the parameters reserved for use in formulas, mo() = Momentum;

    3) The variable "x" does not signal the start of the Time & Date period, but rather the whole period since, and this won't work effectively with the HighestSince() function;

    4) The BarsSince() function is not only unnecessary, but also introduces unwanted null (N/A) bars into the plot.


    Hope this helps.


    jose '-)
    MetaStockTools.com
  •  05-26-2007, 12:36 24156 in reply to 24134

    Re: How to handle time function?

    Jose,  Thanks for the solution.
View as RSS news feed in XML