求救,哪位朋友能帮我用WLD3编一个函数。

Discussion in 'Wealth-Lab Developer' started by 小面瓜, Oct 21, 2009.

  1. 如题
    先谢过了。

    Function

    MRO(EXPR,LENGTH,OCCUR)

    Parameters

    EXPRESSION occurrence to check for, for example when Close>Open
    LENGTH number of trailing bars to check
    OCCUR which occurrence, for example, 1 = most recent, 2 = 2nd most recent, and so on
    Returns

    A numeric value containing the number of bars ago that the specified expression was True; -1 if expression was not found to be True within the last LENGTH bars

    Usage

    The first parameter, EXPR, stands for expression. It is the true/false condition you are looking for. For example, if you wanted to find the most recent occurrence of an outside bar, that would be your expression. LENGTH refers to how many bars the MRO function will evaluate at a time. Find the most recent occurrence of an outside bar for every 15 bars would require a LENGTH of 15. OCCUR stands for occurrence and refers to which occurrence you want to find. Usually the most recent occurrence is desired and is obtained by using an OCCUR of 1. If you wanted to find the second most recent occurrence, you would use the number 2.

    Since the parameter EXPR is a true/false parameter, its replacement must be a true/false expression. The hard coded value or the default value of the input used to replace it must be a true/false expression. The parameters LENGTH and OCCUR are numeric simple type parameters and can be replaced with any positive whole number or numeric expression that yield a whole number. And, the value that replaces OCCUR should not be greater than the value that replaces LENGTH.

    The MRO function always returns a number representing how many bars ago the true/false expression occurred (0 equals the CurrentBar, 1 equals one bar ago, etc.). If it did not occur within the LENGTH of bars specified, the MRO function returns -1.

    Note

    Test the return value before using it as a bar reference. If the MRO function does not find your specified criteria (and therefore returns a -1), normally you would not want to take any action. Therefore, check to see if the function returns a value greater than negative one. If you try to reference a price using a bar number of -1 you will receive a Runtime error, which refers to the Maximum number of bars referenced by a study (or MaxBarsBack) setting.




    {************************************************* ******************
    Description: Most Recent Occurrence
    Provided By: Omega Research, Inc. (c) Copyright 1999
    ************************************************** ******************}

    Inputs: Expression(TrueFalseSeries), Length(NumericSimple), Occur(NumericSimple);
    Variables: TrueCount(0), Counter(0);

    Counter = 0;
    TrueCount = 0;

    While Counter < Length AND TrueCount < Occur Begin
    If Expression[Counter] Then
    TrueCount = TrueCount + 1;
    Counter = Counter + 1;
    End;
    If TrueCount >= Occur AND TrueCount > 0 Then
    MRO = Counter - 1 + CurrentBar - BarNumber
    Else
    MRO = -1;
     
  2. 上面的内容翻译成中文看看是要实现什么功能?
     
  3. 有点明白了。
    http://www.hylt.net/vb/showthread.php?t=14711&page=4
    很容易我们可以找到barnumber函数
    他的说明如下
    BarNumber (Function)
    Disclaimer

    The BarNumber series function assigns a reference number to each bar after MaxBarsBack is satisfied.

    Syntax
    BarNumber

    Returns (Integer)
    A positive numeric reference value for each bar on the chart.

    Parameters
    None

    Remarks
    MaxBarsBack is the minimum number of referenced historical bars required at the beginning of a chart to begin calculating trading strategies, analysis techniques, and functions. For example, a 10-bar moving average would require a MaxBarsBack setting of 9 to calculate, which is 9 historical bars and the current bar.

    Since BarNumber is based on MaxBarsBack, if there are 500 bars in a chart, with a MaxBarsBack setting of 50, the next bar after the 50th bar on the chart moving left to right, will be BarNumber = 1. The last bar on the chart (most recent) will be BarNumber = 451.

    BarNumber is often used to identify a particular bar or number of bars because of some special occurrence or situation that you want to test or factor into your analysis.

    The BarNumber function is similar to the reserved word CurrentBar. However, CurrentBar does not allow previous bar references: BarNumber[5](of five bars ago) is correct, however, Currentbar[5] is incorrect and does not work.

    Examples
    Assigns the BarNumber for each bar to Value1, then plots Value1:

    Value1 = BarNumber;

    Plot1(Value1, "BarNum");

    Assigns the BarNumber to Value1 when Condition1 is true, and assigns the number of bars since Condition1 occurred to Value2:

    if Condition1 then
    Value1 = BarNumber;
    if BarNumber > Value1 then
    Value2 = CurrentBar – Value1;

    我们可以看到在这个帮助系统里面,对每一个函数,都给出了拼写,参数定义,注意事项和使用实例

    ok现在我们知道barnumber代表了当前图表中的k线数-maxbarback(这个运算运算向前引用的k线数)
    所以barnumber+maxbarback就可以得出当前图表中的k线数
    那么下一个问题是如何把这个数字显示出来,在tradestation中,有足够的方式来显示信息,可以是文字,也可以是图形和线条,对于当前的例子,我们希望他返回的是一个数字,因此我们还需要去找在ts中如何显示数字。
     
  4. CurrentBar是一個常常會呼叫的函式,不過它不必引入參數,它回傳的是一個數字,這數字跟你計算指標的起始有效日數有關。在此例中、我們在資料開始的第9天後才能開始計算出KD的值,所以CurrentBar回傳為1時就是第9天。所以我們在第9天之後開始計算KD(CurrentBar > 1),如此你就不會在第9天之前看到亂七八糟的指標數據了。
     
  5. TS里的定义:
    BarNumber (Function)
    Disclaimer

    The BarNumber series function assigns a reference number to each bar after MaxBarsBack is satisfied.

    Syntax
    BarNumber

    Returns (Integer)
    A positive numeric reference value for each bar on the chart.

    Parameters
    None

    Remarks
    MaxBarsBack is the minimum number of referenced historical bars required at the beginning of a chart to begin calculating trading strategies, analysis techniques, and functions. For example, a 10-bar moving average would require a MaxBarsBack setting of 9 to calculate, which is 9 historical bars and the current bar.

    Since BarNumber is based on MaxBarsBack, if there are 500 bars in a chart, with a MaxBarsBack setting of 50, the next bar after the 50th bar on the chart moving left to right, will be BarNumber = 1. The last bar on the chart (most recent) will be BarNumber = 451.

    BarNumber is often used to identify a particular bar or number of bars because of some special occurrence or situation that you want to test or factor into your analysis.

    The BarNumber function is similar to the reserved word CurrentBar. However, CurrentBar does not allow previous bar references: BarNumber[5](of five bars ago) is correct, however, Currentbar[5] is incorrect and does not work.

    Examples
    Assigns the BarNumber for each bar to Value1, then plots Value1:

    Value1 = BarNumber;

    Plot1(Value1, "BarNum");

    Assigns the BarNumber to Value1 when Condition1 is true, and assigns the number of bars since Condition1 occurred to Value2:

    if Condition1 then
    Value1 = BarNumber;
    if BarNumber > Value1 then
    Value2 = CurrentBar – Value1;
     
  6. CurrentBar (Reserved Word)
    Disclaimer

    Returns the number of the bar currently being evaluated.

    Each bar on a chart (after the number of bars specified by the Maximum number of bars referenced by a study, known as MaxBarsBack) is assigned a number, which is incremented by 1 with each successive bar. For example, if your MaxBarsBack is set to 10, the 11th bar is CurrentBar number 1, the 12th bar is CurrentBar number 2, and so on.

    Remarks
    CurrentBar can only be used to return the number of the current bar, for example, you cannot use:

    CurrentBar[n]

    … to obtain the bar number of the bar n bars ago. However, you can obtain the number of the bar n bars ago (for example, 5) by using:

    CurrentBar - 5

    Also, the CurrentBar reserved word is the same as the user function BarNumber. The only difference is that you can use the BarNumber function to reference past bars:

    BarNumber[5]

    Examples
    You can use CurrentBar to determine how long ago a particular condition occurred:

    If Condition1 then
    Value1 = CurrentBar;
    If CurrentBar > Value1 then
    Value2 = CurrentBar – Value1;

    Value2 would hold the number of bars ago Condition1 occurred.
     
  7. MRO (Function)
    Disclaimer

    The MRO (Most Recent Occurrence) function returns the number of bars ago the specified expression was True. Or, if the specified expression did not occur within the last x number of bars, the function informs you of such.

    Syntax
    MRO(Test, Length, Instance)

    Returns (Integer)
    A numeric value containing the number of bars ago that the specified Expression was True; -1 if Expression was not found to be True within the last Length bars.

    Parameters
    Name
    Type
    Description

    Test
    TrueFalse
    Sets the true/false expression to check for (that is, Close > Open).

    Length
    Numeric
    Sets the number of bars to check.

    Instance
    Numeric
    Sets which occurrence, for example, 1 = most recent, 2 = 2nd most recent, and so on.


    Remarks
    The MRO function is specifically designed to identify when a certain condition occurred. It checks from the current bar and works away from it.

    The function returns a number representing how many bars ago the true/false expression was fulfilled (0 = current bar, 1 = one bar ago, 2 = 2 bars ago …). If the function does not find a bar within the specified Length, which meets the criteria, it will return a -1.

    Note When using the MRO function in an analysis technique, always check the result of the MRO function before using the value in another calculation or function. If the condition occurred over Length number of bars, a -1 value will be returned.

    Example
    Value1 = MRO(Close>Open, 5, 1);
     
  8. // function: RecentOcc

    inputs:
    Test( truefalseseries ),
    Len( numericsimple ),
    Instance( numericsimple ),
    MLFlag( numericsimple ) ;

    variables:
    var0( 0 ),
    var1( 0 ) ;

    if MLFlag = 1 then
    var0 = 0
    else if MLFlag = -1 then
    var0 = Len - 1 ;

    var1 = 0 ;

    while var0 >= 0 and var0 < Len and var1 < Instance
    begin
    if Test[var0] then
    var1 = var1 + 1 ;
    var0 = var0 + MLFlag ;
    end ;

    condition1 = var1 = Instance and Instance > 0 ;
    if condition1 then
    RecentOcc = var0 - MLFlag + ExecOffset
    else
    RecentOcc = -1 ;
     
  9. 这个MRO(EXPR,LENGTH,OCCUR)是不是实现的是飞狐的BARSLAST功能?
     
  10. MRO这个函数是用来检查在最近length那么多个bar中,第n次出现expression这个情况时的barnumer,我觉得其中麻烦最大的是这个expression在wld中如何能够简捷地传送到函数中,好像wld不支持那么灵活的功能,当然,用OOP可能能够实现
     
  11. expression在WLD中应该可以使用逻辑实现吧。
    有必要让我把上面的说明都翻译过来吗?
     
  12. 我印象中wld的函数只能传递数据类型及对应的数值,当然,表达式可以转换成字符串传送过去,但是如何转换回逻辑表达式似乎没有简单的办法。当然,我说的只是wld4和4的情况,wld5我没有发言权。

    另外上边的说明我把大概的意思说说吧,就是解释MRO这个函数,以及各个参数的作用。比如,如果我们想检查“过去20天中,从今天倒数,发生第二个外部日,即最高价和最低价都比前一个bar极端,这样的bar的位置”,就可以用这个函数来寻找。
    这个函数是挺方便的,不过这要调用TS本身的一些特性,要转换似乎不是那么好办。