in Search

BarsSince, ValueWhen and Custom Formula call in an Expert.

Last post 02-16-2009, 6:17 by marketwatch. 2 replies.
Sort Posts: Previous Next
  •  02-14-2009, 15:04 28909

    BarsSince, ValueWhen and Custom Formula call in an Expert.

    Good day all,

    I have an issue with the above functions working together.  I have a custom formula that determines if a trend exists or not. If not the formula equals 5. I can accurately determine how long the market has been flat (e.g 9 days) using BarsSince() but when I try to ascertain the closing price when no trend existed, using ValueWhen, it fails to give the correct value.  And if I 'page' back in time in the Expert, the length of time the market was flat decreases accordingly but the closing price changes each time. Perhaps I have gone 'code' blind and someone can easily see the errors of my ways. If so let me know. Or perhas there is a better way to achieve my goals.

    In the Expert I have;

    writeif( Fml( "MT-Trend") = 5, "<Name> is not trending over the medium term it is flat. It has been flat for the past writeval( BarsSince( Fml( "MT-Trend") <> 5 ),0.0) day(s). The closing price at that time was writeval(valuewhen(1, BarsSince( Fml( "MT-Trend") <> 5 ),c),3.4)", ")

    Thank you in advance.

    Steve



  •  02-15-2009, 19:02 28916 in reply to 28909

    Re: BarsSince, ValueWhen and Custom Formula call in an Expert.

    Hi Steve,

    Try this:

    writeval(
    valuewhen(1, Fml("MT-Trend") &lt;&gt; 5 ), c)
    ,3.4)


    Note: the BarsSince() was the part that was causing the (logic) error and has been removed.


    Hope this helps.

    wabbit Big Smile [:D]


    "The question of whether a computer can think is no more interesting than the question of whether a submarine can swim."
    Edsgar W. Dijkstra

     

    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 :
    My SkyPE account : wabbit.com.au

  •  02-16-2009, 6:17 28929 in reply to 28916

    Re: BarsSince, ValueWhen and Custom Formula call in an Expert.

    Thanks for spotting my error wabbit. Embarrassed [:$]
View as RSS news feed in XML