Australian (ASX) Stock Market Forum

Amibroker FAQ

Many thanks Wysiwyg! I have just read the ATR stop plugin thread and GP looks to have done us all a huge favour. Looking forward to setting it up.

Cheers :)
 
Dear friends

I am trying to convert an AFL into a DLL File using VC++, I have been successfully do the same except for the below mentioned two codes which I am not getting. Will be very greatfull to you if you Can kindly help with a code to get these two.



1. PreviousDayClose = TimeFrameGetPrice( "C", inDaily, -1 ); // Function in AFL

2. NewDay = Day()!= Ref(Day(), -1);
FDH = HHV( H, NewDay);

Thankyou & Best Regards

VC++ Codes..

AmiVar args7[3];
args7[0].type=VAR_FLOAT;
args7[0].val=sa.Close;
args7[1].type=VAR_STRING;
args7[1].string="inDaily" ;
args7[2].type=VAR_FLOAT;
args7[2].val= -1;


AmiVar PDC;

PDC=gSite.CallFunction("TimeFrameGetPrice",3,args7);
gSite.SetVariable("PDC", PDC);

Getting ERROR ::

How to solve this problem.

Today = gSite.CallFunction("day",0,NULL);



AmiVar ref_Today=gSite.AllocArrayResult();;
ref_Today=VRef(-1,Today.array);
gSite.SetVariable("ref_Today",ref_Today);

BOOL NewD ;
NewD = Today.array != ref_Today.array;
FDH1 = Vhhv(sa.High, NewD);
gSite.SetVariable("FDH1", FDH1);

Getting ERROR
 
Can someone please tell me how I can alter the AFL code so that I get a sell arrow on the chart. I need it so that I can perform a backtest. I just set the buy cond to Buy =0; to keep the AFL short.

I want it to say

Sell = ( a close below the countback line );

Thanks :D
 

Attachments

  • Price 474.afl
    2.1 KB · Views: 15
Can someone please tell me how I can alter the AFL code so that I get a sell arrow on the chart. I need it so that I can perform a backtest. I just set the buy cond to Buy =0; to keep the AFL short.

I want it to say

Sell = ( a close below the countback line );

Thanks :D

Code:
Buy =0;
Sell =0;


nR=2;
Cbl[nR]=Null;
bCBL=False;

    for( i=nR; i < BarCount; i++)
    {
        if( (Low[i-2]<Low[i-1]) && (Low[i-1]<Low[i]) )
        {
            Cbl[i] = Low[i-2];
            bCBL = True;
        }
        else if (bCBL)
        {
            if (Low[i] < Cbl[i-1])
            {
                Cbl[i] = Cbl[i-1];
                bCBL = False;
            }
            else
            {
                n = nR;
                minval[i] = Low[i];
                breakloop= False;
                for (j = 1; NOT(breakloop) && j <= i; j++)
                {
                    if (Low[i-j] < minval[i])
                    {
                        if (n>1)
                        {
                            minval[i] = Low[i-j];
                            n--;
                        }
                        else
                        {
                            Cbl[i] = Low[i-j];
                            breakloop=True;
                        }
                    }
                }
                if (Cbl[i] < Cbl[i-1])
                Cbl[i] = Cbl[i-1];
            }
        }
        else
        {
            Cbl[i] = Cbl[i-1];
        }
    if (Cbl[i]==0)
    Cbl[i] = Cbl[i-1];
    }

Plot(Cbl,"",colorLightGrey,1);
Plot(C,"",-1,64);


PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
 
I think a similar code to the one I have here has to be placed into the formula but I dont know how to do it. This code is copied from a trailing stop.
Code:
if( trailstop > 0 AND Close[ i ] < trailstop )
   {
      Sell[ i ] = 1;
      SellPrice[ i ] = trailstop;
      trailstop = 0;


:banghead::banghead::banghead:
 
Code:
Buy =0;



nR=2;
Cbl[nR]=Null;
bCBL=False;

    for( i=nR; i < BarCount; i++)
    {
        if( (Low[i-2]<Low[i-1]) && (Low[i-1]<Low[i]) )
        {
            Cbl[i] = Low[i-2];
            bCBL = True;
        }
        else if (bCBL)
        {
            if (Low[i] < Cbl[i-1])
            {
                Cbl[i] = Cbl[i-1];
                bCBL = False;
            }
            else
            {
                n = nR;
                minval[i] = Low[i];
                breakloop= False;
                for (j = 1; NOT(breakloop) && j <= i; j++)
                {
                    if (Low[i-j] < minval[i])
                    {
                        if (n>1)
                        {
                            minval[i] = Low[i-j];
                            n--;
                        }
                        else
                        {
                            Cbl[i] = Low[i-j];
                            breakloop=True;
                        }
                    }
                }
                if (Cbl[i] < Cbl[i-1])
                Cbl[i] = Cbl[i-1];
            }
        }
        else
        {
            Cbl[i] = Cbl[i-1];
        }
    if (Cbl[i]==0)
    Cbl[i] = Cbl[i-1];
    }

Sell = Close < Cbl;

Plot(Cbl,"",colorLightGrey,1);
Plot(C,"",-1,64);


PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
I've moved your Sell statement below the CBL loop and set it to trigger when the close price is lower than the Cbl.

Sell = Cross(Cbl,Close);

Using the Cross statement is another way to achieve it, this means Sell is true only on the bar that the close is less than the Cbl rather than remaining true until the Close crosses above the Cbl.

I haven't tested it, so post back here if it's not what you're after.
 
You're a genius. Thank you so much. I have one small problem. I get multiple sell arrows. I tried to remove them by pasting this code but it didnt work.

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
 
Code:
Buy =0;



nR=2;
Cbl[nR]=Null;
bCBL=False;

    for( i=nR; i < BarCount; i++)
    {
        if( (Low[i-2]<Low[i-1]) && (Low[i-1]<Low[i]) )
        {
            Cbl[i] = Low[i-2];
            bCBL = True;
        }
        else if (bCBL)
        {
            if (Low[i] < Cbl[i-1])
            {
                Cbl[i] = Cbl[i-1];
                bCBL = False;
            }
            else
            {
                n = nR;
                minval[i] = Low[i];
                breakloop= False;
                for (j = 1; NOT(breakloop) && j <= i; j++)
                {
                    if (Low[i-j] < minval[i])
                    {
                        if (n>1)
                        {
                            minval[i] = Low[i-j];
                            n--;
                        }
                        else
                        {
                            Cbl[i] = Low[i-j];
                            breakloop=True;
                        }
                    }
                }
                if (Cbl[i] < Cbl[i-1])
                Cbl[i] = Cbl[i-1];
            }
        }
        else
        {
            Cbl[i] = Cbl[i-1];
        }
    if (Cbl[i]==0)
    Cbl[i] = Cbl[i-1];
    }

Sell = Close < Cbl;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

Plot(Cbl,"",colorLightGrey,1);
Plot(C,"",-1,64);


PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
Try the code above or use the

Code:
 Sell = Cross( Cbl,Close);
and Sell will only remain true for the single bar when Close crosses below. If using the exrem method then be sure to remove it when using the formula for backtesting as it can intefere with the backtester. Better still use one code for display and one for backtesting.
 
Thanks Captain black. They both work now. The cross function seems to give better signals. Ive included a picture of the other close below function. It gives a sell if it pushes up through and then closes under. (Not so good)

Sell= Close < CBL;


Is there a way that the AFL can be altered so that I can alter the CBL and its colour in Parameters instead of editing the formula?

Chart.png
[/IMG]
 
Is there a way that the AFL can be altered so that I can alter the CBL and its colour in Parameters instead of editing the formula?

http://www.amibroker.com/guide/afl/paramcolor.html

Code:
Plot(Cbl , "Cbl" , ParamColor ( "Cbl Colour" , colorLightGrey ),styleLine);
Replace the other Cbl plot with the code above. Not tested so post back if it doesn't work.

edit: forgot to add styleline
 
In the Cbl loop replace:

Code:
nR = 2;
with:

Code:
nR = Param( "Cbl n lower lows" , 2 , 2 , 6 ,1 );
This will count back the number of lower lows. ie. set to 2 it counts back to the previous 2 lower lows. Set to 4 it counts back to the previous 4 lower lows.
 
Can you please tell me how to optimize the 2 values of EMA ( 13 & 22 only) in this equation. I dont want to optimize the 200EMA

Sell = Close < EMA( Close ,200 )
AND EMA( Close , 13 ) < EMA( Close , 22 );

I tried this but it doesnt work. :banghead:

fast = EMA(C, Optimize("FastEMA", 13, 3, 20, 1));
slow = EMA(C, Optimize("SlowEMA",22, 5, 50, 1));


Buy = Close > EMA( Close , 200 );

Sell = Close < EMA( Close ,200 )
AND EMA( Close , fast ) < EMA( Close , slow );
 
Can you please tell me how to optimize the 2 values of EMA ( 13 & 22 only) in this equation. I dont want to optimize the 200EMA

Sell = Close < EMA( Close ,200 )
AND EMA( Close , 13 ) < EMA( Close , 22 );

I tried this but it doesnt work. :banghead:

fast = EMA(C, Optimize("FastEMA", 13, 3, 20, 1));
slow = EMA(C, Optimize("SlowEMA",22, 5, 50, 1));


Buy = Close > EMA( Close , 200 );

Sell = Close < EMA( Close ,200 )
AND EMA( Close , fast ) < EMA( Close , slow );

Your optimize statements aren't correct, try this:

Code:
fast =  Optimize("FastEMA", 13, 3, 20, 1);
slow = Optimize("SlowEMA",22, 5, 50, 1);


Buy =  Close > EMA(  Close , 200 );

Sell = Close < EMA(  Close ,200 )
AND EMA(  Close , fast ) < EMA(  Close , slow );
 
Amibroker Plug-ins with C# (no more C++)

Here is a demonstration project which shows how you can create plug-ins for AmiBroker with fully managed code like C# and Microsoft .NET Framework.

http://amibroker.codeplex.com/

No COM proxies, no any single line of C++ just pure C#.
 
Hi all,

Looking for some advice on loading and setting up data from different exchanges. I have loaded ASX data and all is good. When I load up the US exchanges into a different group I seem to get some odd behaviour.

For example, there are 2 'ABC' tickers - one in the ASX and another in the US. My ASX data finished late last year, however it is picking up the 'remainder' from the more recent US data. I have 'blown' away all my data and now just have ASX data. Should this be happening? Maybe my setup is incorrect?

Thanks in advance :)
 
I use separate databases for each exchange, only takes 2 clicks to load each database and keeps everything simple. Others may have different experiences with organising data into different markets using the same database but for the sake of simplicity I've found maintaining data in individual databases works for me.
 
Not sure if this is possible. I want the actual candle that this formula refers to to appear Blue.
LLV(Ref(L,-1),Lpds);

(It is from this formula )

HTML:
Hpds=Optimize("hpds",20 , 1 , 25 ,1 );
Lpds=Optimize("lpds",20 , 1 , 25 ,1 );



DonchianUpper =HHV(Ref(H,-1),Hpds);
DonchianLower = LLV(Ref(L,-1),Lpds);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;


Plot(DonchianUpper,"DU",colorBlue,styleLine);
Plot(DonchianMiddle,"DM",colorGreen,styleLine);
Plot(DonchianLower,"DL",colorRed,styleLine);

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);



PlotShapes(Buy*shapeCircle,colorGreen,0,Low);
PlotShapes(Sell*shapeCircle,colorRed,0,High);

Thanks
 
Top