in Search

7 Conditions Decisional Tree

Last post 04-21-2008, 12:53 by johnl. 8 replies.
Sort Posts: Previous Next
  •  01-18-2008, 17:32 26350

    7 Conditions Decisional Tree

    I want to write an easy language indicator that has 7 conditions build into it, some are easy a few are a little more complex. But for some reason I can write some of them separately but I can not combine them all into one function. Can any one help me out with this? I will add two conditions at a time to make things easy.

     

    Condition 1 - logic Indicator A must be greater than Indicator B and C

     

    Indicator A

    Indicator B

    Indicator C

     

    If Fml(“A”) is > fml(“B”)  and fml(“C”)

     

    Condition 2 – Add Indicator D’s Y value output must be positive and increasing in value

    Note – there are 2 output values X and Y I’m looking at the Y output value in this case

     

                Indicator D

     

    If Fml(“A”) is > fml(“B”)  and fml(“C”) {Condition 1}

    Plus

    If FmlVar(“D”,”Y”), > 0 and FmlVar(“D”,”Y”) > FmlVar(“D”,Y”) {Condition 2}

     

  •  01-18-2008, 18:49 26352 in reply to 26350

    Re: 7 Conditions Decisional Tree

    Hi Underground,

    Could you build the conditions as shown below?

    IndicatorA:=30;
    IndicatorB:=21;
    IndicatorC:=14;
    Condition1:=IndicatorA>IndicatorB AND IndicatorA>IndicatorC;
    {If Condition1 is satisfied then value will = 1}
     
    IndicatorD:=Variables(x,y);
    Condition2:=FmlVar(IndicatorD,"Y")>0 AND FmlVar(IndicatorD,"Y")>Ref(FmlVar(IndicatorD,"Y"),-1);
    {If Condition2 is satisfied then value will = 1}

    7ConditionsIndicator:=(Condition1=1 and Condition2=1 AND
    Condition3=1 AND .... Condition7=1);

    7ConditionsIndicator; {plots indicator}

    I think the only problem could be that there is a limit on the number of variables!

    Cheers,

    ozt

  •  01-19-2008, 23:50 26360 in reply to 26352

    Re: 7 Conditions Decisional Tree

    Hi Underground,

    The last line of my previous post, as shown in red below, is incorrect!

    "I think the only problem could be that there is a limit on the number of variables!"

    According to the manual there is a maximum of 20 different numeric constants which may be used in each formula.

    Cheers,

    ozt

  •  01-20-2008, 12:55 26372 in reply to 26360

    Re: 7 Conditions Decisional Tree

    oz, yes there can only be 20 variables, but after you have finished using a variable, you can reuse the name of a variable to create a new value
  •  01-22-2008, 17:31 26400 in reply to 26372

    Re: 7 Conditions Decisional Tree

    henry1224 - thanks for the help, I was able to get the first two conditions to work correctly.

     

    The next two go something like this:

     

    Condition #3

     

                Indicator E

                Indicator F

    Logic:

    Indicator E and F both need to be increasing in value, or equal to previous bar

     

    I was thinking something like this?

     

    If(ROC(Fml("Indicator E"),1,$)>=0,1,

    +

    If(ROC(Fml("Indicator F"),1,$)>=0,1,

     

     

    Condition #4

     

                Indicator F

                Indicator G

     

    Logic:

    Indicator F is equal to or greater than 1.0 and increasing in value, plus Indicator G is increasing in value

    Not sure about condition 4

  •  01-28-2008, 0:15 26427 in reply to 26400

    Re: 7 Conditions Decisional Tree

    Hi Underground,

    Does "Indicator F" need to be a part of both Condition #3 and Condition #4 or can it be combined in the code for Condition #3?

    Cheers,

    ozt 

  •  04-13-2008, 20:12 26945 in reply to 26427

    Re: 7 Conditions Decisional Tree

    If the indicator I want to be increasing in value doesn't change directions too fast
    and is pretty smooth I use If((AA-Ref(AA,-2)>0),1,0)  where AA is my indicator.
    The Ref(AA,-2) looks the AA value 2 bars back. This gives me a true/false value I can
    use later. 

  •  04-13-2008, 20:53 26946 in reply to 26945

    Re: 7 Conditions Decisional Tree

    MS returns a boolean value of 1 or 0 depending on whether a condition can be expressed as true or false, so you dont need the If((AA-Ref(AA,-2)>0),1,0) it can just be written as (AA-Ref(AA,-2))>0 and it will return a value of 1 if this condition is true, 0 otherwise.

    Binary values can be added together, e.g.

    Code:
    ma1:=Mov(C,12,S);
    ma2:=Mov(C,33,S);

    x:=Cross(ma1,ma2) + (C>10);

    {plot}
    x;


    "x" will take on three possible values:
    0 if the Cross() event did not happen AND the price is not greater than 10
    1 if either of the Cross() event happened OR the price is greater than 10, but NOT both
    2 if both of the Cross() event happened AND the price is greater than 10.

    These concepts allow you to write more simple code to deal with more complex situations.


    wabbit Big Smile [:D]

    [edit]I didn't deal with the N/A situations, but these can be easily figured out by looking at a chart with the above function plotted.


    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

  •  04-21-2008, 12:53 27003 in reply to 26946

    Re: 7 Conditions Decisional Tree

       
    Dropping all the nonessential  stuff always looks better.
    I  keep each as a separate variable so I can easily and subtract information without
    messing everthing else up. I do a lot of throwing stuff against the wall to see what sticks.
    Readability is what I find difficult when I start dropping stuff like that.
    For instance: take those weeky to daily indicators of Roy's. They great work but soft
    coding just one that has the function (MA,RS, etc) as a  variable makes it
    more usable.
    The new program structure would look like:
    a1:= FML(I want to convert);
    b1:= do date stuff
    c1:= convert  a1 into  a standard  variable
    d1:= get b1 stuff and c1 stuff and do daily stuff
    e1:= plot converted d1 variable.
    All that embedded stuff drives me nuts. I am pretty sure it's all a conspiracy. Smile [:)]

View as RSS news feed in XML