[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Equity(1) modifies sell price ignoring ceil



PureBytes Links

Trading Reference Links

Hello,

You can be sure that if that happens, the trade price that you set is NOT within H-L range.
You can easily see that if you add
SetOption("PriceBoundChecking", False );

then you will see that the price is outside H-L range.

Your plots may not take into account trade delays that you have have set in the settings.
Think about it.
Also with raw mode, the entry point may not be the very first bar when
signal occurred, but later (when cash becomes available because other trade end).

Also read the manual section:
http://www.amibroker.com/guide/a_equity.html

Equity() function performs in-place single-security backtest, and it does not take into account portfolio (i.e. other symbols),
so it will always perform backtestRegular (as there were no other symbols).
(Technically it is allowed to use it anywhere, but it will still perform single-security backtest, therefore
it will not take into account raw mode and all its portfolio-level consequences)
Read more about modes
http://www.amibroker.com/guide/h_backtest.html

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message ----- 
From: "pmxgs" <pmxgs@xxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Tuesday, June 09, 2009 2:38 AM
Subject: [amibroker] Re: Equity(1) modifies sell price ignoring ceil


Hello Tomasz,

 regarding this subject of buyprice array I am getting strange results in the baktester. I define my buyprice variable and plot it 
on the chart so that I can check if it is being calculated correctly, and apparently it is, but when I run the backtester the trades 
are executed at different prices.

>From the code below do you see any reason why the backtester doesn't agree with the buyprice variable ploted on the chart.

Below is just a part of the code which allows you to see what I'm talking about. Below this I pasted the entire code if it is 
usefull.

thanks very much
.......

PH =TimeFrameGetPrice("H", inDaily, -1);
PL =TimeFrameGetPrice("L", inDaily, -1);
PC =TimeFrameGetPrice("C", inDaily, -1);

PP=(PH+PL+PC)/3;
R3=(PH + (2 * (PP - PL)));
S3=(PL - (2 * (PH - PP) ));

// trading system

SetBacktestMode( backtestRegularRawMulti );

intrade=0;
step1=0;
step2=0;
step3=0;
step4=0;
step5=0;
step6=0;
step7=0;
npos=0;
stackplot=0;
entrypriceplot=0;
entryprice=0;
HighestSinceentry=0;
stacks=0;

entry=Cross(H,R3);
exit=Cross(pp,L);
SellPrice=PP; //stop loss selling price
Buy=0;

for(i=1 ; i<(BarCount-1) ; i++)
{

     if( entryprice[i]==0 AND entry[i]==1 AND npos[i]==0) // entry bar check
     {

        entryprice=R3[i];
        HighestSinceentry=H[i];
        stacks[i]=Min(int((H[i]-entryprice[i])*10000/10),4)+1;
  npos[i]=stacks[i];
        BuyPrice[i]=(2*entryprice[i]+((stacks[i]-1)*10/10000))/2;
        Buy[i]=1;
        intrade=1;
        step1[i]=1;
......

Entire code:

//begin
//Pivot Points Indicator

PH =TimeFrameGetPrice("H", inDaily, -1);
PL =TimeFrameGetPrice("L", inDaily, -1);
PC =TimeFrameGetPrice("C", inDaily, -1);

PP=(PH+PL+PC)/3;
//R1 = (2 * PP) - PL;
//S1 = (2 * PP) - PH;
//R2 = PP + R1 - S1;
//S2 = PP + S1 - R1;
R3=(PH + (2 * (PP - PL)));
S3=(PL - (2 * (PH - PP) ));
PPcolor=ParamColor("PP",colorYellow);
SRcolor=ParamColor("S/R color",colorSkyblue);
SRstyle=ParamStyle("S/R style",styleDots|styleNoLine|styleNoRescale);
//Plot(PP,"",PPcolor,styleThick);
//Plot(S3,"",SRcolor,SRstyle);
//Plot(R3,"",SRcolor,SRstyle);

// trading system

SetBacktestMode( backtestRegularRawMulti );


intrade=0;
step1=0;
step2=0;
step3=0;
step4=0;
step5=0;
step6=0;
step7=0;
npos=0;
stackplot=0;
entrypriceplot=0;
entryprice=0;
HighestSinceentry=0;
stacks=0;

entry=Cross(H,R3);
//BuyPrice=R3; //entryprice
exit=Cross(pp,L);
SellPrice=PP; //stop loss selling price
Buy=0;

for(i=1 ; i<(BarCount-1) ; i++)
{

     if( entryprice[i]==0 AND entry[i]==1 AND npos[i]==0) // entry bar check
     {

        Buy[i]=1;
        entryprice=R3[i];
        HighestSinceentry=H[i];
        stacks[i]=Min(int((H[i]-entryprice[i])*10000/10),4)+1; // inclui mais uma posiçao que é a inicial
  npos[i]=stacks[i];
        BuyPrice[i]=(2*entryprice[i]+((stacks[i]-1)*10/10000))/2; // retirar um pois esta incluido nos stacks
        intrade=1;
        step1[i]=1;

         if(H[i]>=(entryprice[i]+50/10000)AND intrade[i]) //profit target hit on entry bar
       {

BuyPrice=(2*entryprice[i]+(4*10/10000))/2;
Sell[i]=1;
SellPrice[i]=entryprice[i]+50/10000;
          entryprice=0;
HighestSinceentry=0;
npos[i+1]=0;

     step2[i]=2;
        intrade=0;
          }

      }



if (H[i]>HighestSinceentry[i] AND intrade[i]) //increase number of positions
{

HighestSinceentry=H[i];

stacks[i]=Min(int((H[i]-entryprice[i])*10000/10),4)-npos[i]+1; //calculate number of stacks
if(stacks[i]<0) stacks[i]=0;
    npos[i]=Min(stacks[i]+npos[i],5); // keep highest number of stacks
    step3[i]=3;
         if(stacks[i]>0 AND npos[i]<=5)  // doesn't buy if stacks is zero and doesn't buy if # of positions is > 5
           {
            Buy[i]=1;
        BuyPrice[i]=(2*entryprice[i]+(stacks[i]*10/10000))/2;
        step4[i]=4;
            }
   }


      npos[i+1]=Min(npos[i],5);
   step5[i]=5;


   if(H[i]>=(entryprice[i]+50/10000) AND intrade[i]) //profit target hit
{

Sell[i]=1;
entryprice=0;
SellPrice[i]=entryprice[i]+50/10000;
    HighestSinceentry=0;
npos[i+1]=0;

step6[i]=6;
    intrade=0;
    }

if(exit[i]==1 AND intrade[i]) //stop loss hit
{

Sell[i]=1;
entryprice=0;
HighestSinceentry=0;
npos[i+1]=0;
   intrade=0;
   step7[i]=7;
}



 stackplot[i]=stacks[i];
 entrypriceplot[i]=entryprice ;

}
Plot(Buy,"buy",colorLime,styleOwnScale);
Plot(step1,"st1",colorLime,styleOwnScale);
Plot(step2,"st2",colorLime,styleOwnScale);
Plot(step3,"st3",colorLime,styleOwnScale);
Plot(step4,"st4",colorLime,styleOwnScale);
Plot(step5,"st5",colorLime,styleOwnScale);
Plot(step6,"st6",colorLime,styleOwnScale);
Plot(step7,"st7",colorLime,styleOwnScale);

Plot(Sell,"sell",colorRed,styleOwnScale);

Plot(BuyPrice,"buyprice",colorViolet,styleOwnScale);
Plot(npos,"npos",colorPink,styleOwnScale);
Plot(stackplot,"stack",colorAqua,styleOwnScale);

Plot(entrypriceplot,"entryprice",colorBlue,styleOwnScale);

SetPositionSize(stackplot,spsShares);

//end

--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@xxx> wrote:
>
> Hello,
>
> ceil may be higher than high, that's why.
>
> Please read the manual
> http://www.amibroker.com/guide/h_backtest.html
>
> Quote:
> "During back-testing AmiBroker will check if the values you assigned to buyprice, sellprice, shortprice, coverprice fit into
> high-low range of given bar. If not, AmiBroker will adjust it to high price (if price array value is higher than high) or to the 
> low
> price (if price array value is lower than low)"
>
> You can turn that behaviour off using
> http://www.amibroker.com/f?setoption
>
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message ----- 
> From: "only_accept_the_real_thing" <olivermannion@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Monday, June 08, 2009 11:12 AM
> Subject: [amibroker] Equity(1) modifies sell price ignoring ceil
>
>
> > Hi,
> >
> > Running the code below on price data that includes decimals, the SellPrice used is the Close price (with decimals) rather than 
> > the
> > ceil price.
> >
> > If SellPrice is changed to round(C) it is correctly rounded, so why doesn't ceil(C) work??
> >
> >
> > NB: Remove Equity(1) and the SellPrice is correctly ceil(C).
> >
> >
> > ------
> > BuyPrice = Open;
> > SellPrice = ceil(C);
> >
> > Equity(1);
> >
> > // Extra columns to display in Exploration
> > Filter=1;
> > AddColumn(Open,"Open");
> > AddColumn(High,"High");
> > AddColumn(Low,"Low");
> > AddColumn(Close,"Close");
> > AddColumn(BuyPrice,"BuyPrice");
> > AddColumn(SellPrice,"SellPrice");
> >
> >
> >
> >
> >
> > ------------------------------------
> >
> > **** IMPORTANT PLEASE READ ****
> > This group is for the discussion between users only.
> > This is *NOT* technical support channel.
> >
> > TO GET TECHNICAL SUPPORT send an e-mail directly to
> > SUPPORT {at} amibroker.com
> >
> > TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> > http://www.amibroker.com/feedback/
> > (submissions sent via other channels won't be considered)
> >
> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> > http://www.amibroker.com/devlog/
> >
> > Yahoo! Groups Links
> >
> >
> >
>




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links





------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/