Need help afl for presto magic box from metastock

rvlv

Active Member
#1
Hi friends

can anyone help me get the afl coding for this metastock code please!
I tried but found a thing called PREVIOUS and got stuck there.


HTML:
//Presto's Magic Box afl  (i tried- still incomplete)

//(a tweaked Version of the Darvis Box)

Periods=Param("periods",1,260,100);

Topbox=IIf(Ref(H,-3)>=Ref(HHV(H,Periods),-4) AND Ref(H,-2)<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND H< Ref(H,-3),Ref(H,-3),PREVIOUS);

Botbox=IIf(Ref(H,-3)>=Ref(HHV(H,Periods),-4) AND Ref(H,-2)<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND H< Ref(H,-3),LLV(L,4),PREVIOUS);

Plot(Botbox,"botbox",colorRed,styleDashed);
Plot(Topbox,"Topbox",colorBlue,styleDashed);
Plot(C,"c",colorBlack,styleBar);
original version of ms code here

HTML:
Presto's Magic Box

(a tweaked version of the Darvis Box)

Periods:=Input("periods",1,260,100);

Topbox:=If(Ref(H,-3)>=Ref(HHV(H,Periods),-4) AND Ref(H,-2)<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND H< Ref(H,-3),Ref(H,-3),PREVIOUS);

Botbox:=If(Ref(H,-3)>=Ref(HHV(H,Periods),-4) AND Ref(H,-2)<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND H< Ref(H,-3),LLV(L,4),PREVIOUS);

Botbox;

Topbox;
thanks in advance
 

KelvinHand

Well-Known Member
#2
Hi friends

can anyone help me get the afl coding for this metastock code please!
I tried but found a thing called PREVIOUS and got stuck there.


HTML:
//Presto's Magic Box afl  (i tried- still incomplete)

//(a tweaked Version of the Darvis Box)

Periods=Param("periods",1,260,100);

Topbox=IIf(Ref(H,-3)>=Ref(HHV(H,Periods),-4) AND Ref(H,-2)<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND H< Ref(H,-3),Ref(H,-3),PREVIOUS);

Botbox=IIf(Ref(H,-3)>=Ref(HHV(H,Periods),-4) AND Ref(H,-2)<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND H< Ref(H,-3),LLV(L,4),PREVIOUS);

Plot(Botbox,"botbox",colorRed,styleDashed);
Plot(Topbox,"Topbox",colorBlue,styleDashed);
Plot(C,"c",colorBlack,styleBar);
original version of ms code here

HTML:
Presto's Magic Box

(a tweaked version of the Darvis Box)

Periods:=Input("periods",1,260,100);

Topbox:=If(Ref(H,-3)>=Ref(HHV(H,Periods),-4) AND Ref(H,-2)<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND H< Ref(H,-3),Ref(H,-3),PREVIOUS);

Botbox:=If(Ref(H,-3)>=Ref(HHV(H,Periods),-4) AND Ref(H,-2)<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND H< Ref(H,-3),LLV(L,4),PREVIOUS);

Botbox;

Topbox;
thanks in advance
Waited for few days, thought one of the intelligent guy will solve this PREV problem.

Please reference to Guppy Ghost Box DarvasHigh(), copy the exact same to code
- your PREV issue for topbox an botbox separately OR
- because the condition is the same for both topbox and botbox, you can use the single looping to get the topbox and botbox
Change you Param(), put the 100 in front.

http://www.traders.com/Documentation/FEEDbk_docs/2005/06/TradersTips/TradersTips.html#amibroker
 
Last edited:

rh6996

Well-Known Member
#3
Waited for few days, thought one of the intelligent guy will solve this PREV problem.

Please reference to Guppy Ghost Box DarvasHigh(), copy the exact same to code
- your PREV issue for topbox an botbox separately OR
- because the condition is the same for both topbox and botbox, you can use the single looping to get the topbox and botbox
Change you Param(), put the 100 in front.

http://www.traders.com/Documentation/FEEDbk_docs/2005/06/TradersTips/TradersTips.html#amibroker
Any idea about Toby Crabels Patterns in Metastock !
 

rvlv

Active Member
#5
HI kelvinhand

Thank you for the hint and reference.

What I could do is this.
hope it is ok.If any error please help correct.
The rule is buy if candles cross above topboxline and sell if candle cross below bottombox line.


With this the chart shows with 100 periods,most of the time the candles are above botom box and well below or always below topboxline.
In fact candles rarely cross above topbox line.
what is the way out?
Reduce periods--may be

HTML:
 Periods = Param("Periods", 100, 2, 300, 1, 10 );

//Topbox=IIf(Ref(H,-3)>=Ref(HHV(H,Periods),-4) AND Ref(H,-2)<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND H< Ref(H,-3),Ref(H,-3),PREVIOUS);

//Botbox=IIf(Ref(H,-3)>=Ref(HHV(H,Periods),-4) AND Ref(H,-2)<Ref(H,-3) AND Ref(H,-1)<Ref(H,-3) AND H< Ref(H,-3),LLV(L,4),PREVIOUS);



        function DarvasHigh( Periods )
    {
     HHVtemp = HHV( High, Periods );
     result = HHVTemp;
     for( i = Periods + 4; i < BarCount; i++ )
     {
       result[ i ] = IIf( H[ i - 3 ] >= HHVTemp[ i - 4 ] AND
                         H[ i - 3 ] > H[ i - 2 ] AND
                         H[ i - 3 ] > H[ i - 1 ] AND
                         H[ i - 3 ] > H[ i ],
                         H[ i - 3 ],
                         result[ i - 1 ] );
     }
     return result;
    }
    function NewDarvasHigh( Periods )
    {
      dh = DarvasHigh( Periods );
      return dh AND Nz( dh ) != Ref( Nz( dh ), -1 );
    }
    function NewDarvasLow( Periods )
    {
      dh = DarvasHigh( Periods );
      ndl = Ref( L, -3 ) < Ref( L, -2 ) AND
            Ref( L, -3 ) < Ref( L, -1 ) AND
            Ref( L, -3 ) < L AND
            Ref( H, -2 ) < dh AND
            Ref( H, -1 ) < dh AND
            H < dh;
      return Nz( ndl ) AND Ref( Nz( ndl ), -1 ) < 1;
    }
    function DarvasLow( Periods )
    {
      return ValueWhen( NewDarvasLow( Periods ), Ref( L, -3 ) );
    }
    function DarvasBoxEnd( Periods )
    {
     end = BarsSince( NewDarvasHigh( Periods ) ) <
           BarsSince( Ref( NewDarvasLow( Periods ), -1 ) );
     return Nz( end ) AND NewDarvasLow( Periods );
    }
    function DarvasBoxHigh( Periods )
    {
     dbe = DarvasBoxEnd( Periods );
     dbhi = ValueWhen( Nz( dbe ) AND NOT IsNull( Ref( dbe, -1 )),
           DarvasHigh(       Periods ) );
     return IIf( Nz( dbhi ) == 0, H + 1e-6, dbhi );
    }
    function DarvasBoxLow( Periods )
    {
     dbe = DarvasBoxEnd( Periods );
     dblo = ValueWhen( Nz( dbe ) AND NOT IsNull( Ref( dbe,-1)),DarvasLow( Periods ) );
     return IIf( Nz( dblo ) == 0, L - 1e-6, dblo );
    }
    function DarvasPossSell( Periods )
    {
     dsl = Low < DarvasBoxLow( Periods );
     return Nz( dsl ) AND Ref( Nz( dsl ), -1 ) < Nz( dsl );
    }
    Plot( C, "Price", colorBlack, styleCandle );
    Plot( DarvasLow( PERIODS ), "DL", colorRed ,styleThick);
    Plot( DarvasHigh( PERIODS ), "DH", colorGreen ,styleThick);
 
Last edited:

KelvinHand

Well-Known Member
#6
HI kelvinhand

Thank you for the hint and reference.

What I could do is this.
hope it is ok.If any error please help correct.
The rule is buy if candles cross above topboxline and sell if candle cross below bottombox line.


With this the chart shows with 100 periods,most of the time the candles are above botom box and well below or always below topboxline.
In fact candles rarely cross above topbox line.
what is the way out?
Reduce periods--may be
[/Ouote]

Code:
_SECTION_BEGIN("Presto's Magic Box");

Periods=Param("periods",20,1,260);

function DarvasHigh( Periods )
{
     HHVtemp = HHV( High, Periods );
     result = HHVTemp;
     for( i = Periods + 4; i < BarCount; i++ )
     {
       result[ i ] = IIf( H[ i - 3 ] >= HHVTemp[ i - 4 ] AND
                         H[ i - 3 ] > H[ i - 2 ] AND
                         H[ i - 3 ] > H[ i - 1 ] AND
                         H[ i - 3 ] > H[ i ],
                         H[ i - 3 ],
                         result[ i - 1 ] );
     }
     return result;
}

function DarvasLow( Periods )
{
     HHVtemp = HHV( High, Periods );
     result = LLV( Low, Periods );

     for( i = Periods + 4; i < BarCount; i++ )
     {
       result[ i ] = IIf( H[ i - 3 ] >= HHVTemp[ i - 4 ] AND
                         H[ i - 3 ] > H[ i - 2 ] AND
                         H[ i - 3 ] > H[ i - 1 ] AND
                         H[ i - 3 ] > H[ i ],
                         result[i],
                         result[ i - 1 ] );
     }
     return result;
}


Plot( C, "Price", colorBlack, styleCandle );
Plot( DarvasHigh( Periods ), "DH", colorGreen );
Plot( DarvasLow( Periods ), "DL", colorRed );

_SECTION_END();
I can't install metastock
pls compare on metastock and amibroker on the same stock to see whether they are the same.
 
Last edited:

rvlv

Active Member
#7
Kelvinhand

Thanks for the full code.

I am getting some error.

Error is coming in the part of
HTML:
 result[i]-----here werror occurs----
                         result[ i - 1 ] );
     }
     return result;
}


Plot( C, "Price", colorBlack, styleCandle );
Plot( DarvasHigh( Periods ), "DH", colorGreen );
Plot( DarvasLow( Periods ), "DL", colorRed );

Sorry I found it,one comma was missing

corrected part is
result
,result[ i - 1 ] );

regards
rvlv

corrected code as below
---------------------------------------
_SECTION_BEGIN("Presto's Magic Box by kelvinhand-perfected");

_SECTION_BEGIN("Presto's Magic Box");

Periods=Param("periods",20,1,260);

function DarvasHigh( Periods )
{
HHVtemp = HHV( High, Periods );
result = HHVTemp;
for( i = Periods + 4; i < BarCount; i++ )
{
result[ i ] = IIf( H[ i - 3 ] >= HHVTemp[ i - 4 ] AND
H[ i - 3 ] > H[ i - 2 ] AND
H[ i - 3 ] > H[ i - 1 ] AND
H[ i - 3 ] > H[ i ],
H[ i - 3 ],
result[ i - 1 ] );
}
return result;
}

function DarvasLow( Periods )
{
HHVtemp = HHV( High, Periods );
result = LLV( Low, Periods );

for( i = Periods + 4; i < BarCount; i++ )
{
result[ i ] = IIf( H[ i - 3 ] >= HHVTemp[ i - 4 ] AND
H[ i - 3 ] > H[ i - 2 ] AND
H[ i - 3 ] > H[ i - 1 ] AND
H[ i - 3 ] > H[ i ],
result
,result[ i - 1 ] );
}
return result;
}


Plot( C, "Price", colorBlack, styleCandle );
Plot( DarvasHigh( Periods ), "DH", colorGreen );
Plot( DarvasLow( Periods ), "DL", colorRed );

_SECTION_END();
-----------------------------------------------------------------------------------------------------
 
Last edited:

KelvinHand

Well-Known Member
#8
Kelvinhand

Thanks for the full code.

I am getting some error.

Error is coming in the part of

result,
result[ i - 1 ] );
}
return result;
}


Plot( C, "Price", colorBlack, styleCandle );
Plot( DarvasHigh( Periods ), "DH", colorGreen );
Plot( DarvasLow( Periods ), "DL", colorRed );


regards
rvlv


!@#$%^&*()_+
 

rvlv

Active Member
#9
Hi kelvinhand

Thanks again.

It is ok now.
I tried a 15 minute nifty chart with periods set at 5.
it looks good.

--I felt adding a mid point line between boxhi and BOXlo may help
--I added target1up with upperbox+2*atr(10)
- I added target1dn with lowerbox-2*atr(10)
This is needed to solve the issue-once entry occurs how far to keep going-
go as far as n*ATR(10) WHERE N IS 0.5 TO 2 TO 4 OR 6 OR 8


thanks once again!
best regards
rvlv
 

Similar threads