Mike,
It does not seem to matter whether I put ProcessTradeSignals before or after 
the code fiddling with the trading signals.  I get the same result. Looking at 
Tomasz example (slide 26) in this doc 
(http://www.amibroker.com/docs/Houston2.pdf) he puts ProcessTradeSignals before 
scaling in the trade. 

Double checked and mixing those two seems to be the way it should be done.

Thanks for taking the time to look at my questions.
/Fredrik

--- In amibroker@yahoogroups.com, "Mike" <sfclimb...@...> wrote:
>
> Fredrik,
> 
> ProcessTradeSignals should come *after* you've done anything with the Signal 
> objects. 
> 
> Also, you may need to double check whether you are allowed to mix 
> ProcessTradeSignals (a mid level backtester method) with ExitTrade (a low 
> level backtester method) in the same script.
> 
> It's been a while since I'be read up on this, so see "AmiBroker Custom 
> Backtester Interface.pdf" in the Files section for additional detail.
> 
> Mike
> 
> --- In amibroker@yahoogroups.com, "broman1003" <fredrik_broman1003@> wrote:
> >
> > Came up with a solution. If I use Foreign and get the High/Low/Open arrays 
> > that way it works fine.
> > /Fredrik
> > 
> > --- In amibroker@yahoogroups.com, "broman1003" <fredrik_broman1003@> wrote:
> > >
> > > Ok, so I had a go at it :-) Not sure that this is how you should do 
> > > things but it is my first attempt. The below code does not work because 
> > > High[bar] and Low[bar] allways returns zero. Hints?
> > > 
> > > Thanks,
> > > /Fredrik
> > > 
> > > SetOption("UseCustomBacktestProc",True);
> > > if( Status("action") == actionPortfolio )
> > > {
> > >  bo = GetBacktesterObject();
> > >  bo.PreProcess();
> > > 
> > >  TradeEntryPrice = False;
> > >  ProfitTarget = False;
> > >  TrailingSL = False;
> > > 
> > >   for(bar=0; bar<BarCount; bar++)
> > >   {
> > >    bo.ProcessTradeSignals( bar );
> > > 
> > >    for( Sig = bo.GetFirstSignal(bar); Sig; Sig=bo.GetNextSignal(bar) )
> > >    {
> > >     if( Sig.IsEntry() ) 
> > >     { 
> > >      TradeEntryPrice = Sig.Price;
> > >      ProfitTarget = --something---;
> > >     }// if  
> > > 
> > >     if( Sig.IsExit() ) 
> > >     { 
> > >      TradeEntryPrice = False;
> > >      ProfitTarget = False;
> > >      TrailingSL = False;
> > >     }// if
> > >    }// for
> > > 
> > >    //Profit Target
> > >    if (TradeEntryPrice AND High[bar]>=ProfitTarget)
> > >    {
> > >     bo.ExitTrade(bar,"T5", Min(ProfitTarget,Open[bar]), 2);
> > >     TradeEntryPrice = False;
> > >     ProfitTarget = False;
> > >     TrailingSL = False;
> > >    }
> > > 
> > >    ----
> > >    //Calculate Trailing SL
> > >    ----
> > > 
> > >    //Trailing SL
> > >    if (TradeEntryPrice AND Low[bar]<TrailingSL)
> > >    {
> > >     bo.ExitTrade(bar,"T5", Min(TrailingSL,Open[bar]), 3);
> > >     TradeEntryPrice = False;
> > >     ProfitTarget = False;
> > >     TrailingSL = False;
> > >    }
> > >   } //for
> > > 
> > >   bo.PostProcess(); // Finalize backtester
> > > } // if
> > >                   
> > > 
> > > Buy = --- something ---
> > > Sell = --- something ---
> > > 
> > > 
> > > --- In amibroker@yahoogroups.com, "broman1003" <fredrik_broman1003@> 
> > > wrote:
> > > >
> > > > Mike,
> > > > Thanks, I'll have a go at it. I have managed to avoid using the 
> > > > customer backtester up till now but I guess it is time well spent 
> > > > learning it.
> > > > Cheers,
> > > > /Fredrik
> > > > 
> > > > --- In amibroker@yahoogroups.com, "Mike" <sfclimbers@> wrote:
> > > > >
> > > > > You can get the bar index of the trade by using ValueWhen and the 
> > > > > trade's entry date as follows (from within custom backtester code):
> > > > > 
> > > > >     bars = BarIndex(); 
> > > > >     dates = DateTime();
> > > > >     bo = GetBacktesterObject();
> > > > > 
> > > > >     ...
> > > > > 
> > > > >     for ( trade = bo.getFirstOpenPos(); trade; trade = 
> > > > > bo.getNextOpenPos() ) 
> > > > >     { 
> > > > >         entryBar = LastValue( ValueWhen( trade.EntryDateTime == 
> > > > > dates, bars ) ); 
> > > > > 
> > > > >      ...
> > > > > 
> > > > > There may be a better way of handling your stop loss, but the above 
> > > > > should should at least answer your question.
> > > > > 
> > > > > Mike
> > > > > 
> > > > > --- In amibroker@yahoogroups.com, "broman1003" <fredrik_broman1003@> 
> > > > > wrote:
> > > > > >
> > > > > > Hi,
> > > > > > I would like to get hold of the bar where a trade was entered when 
> > > > > > backtesting.
> > > > > > The reason I need it is that I would like to implement a trailing 
> > > > > > SL that is depending on the highest value the price has hit since 
> > > > > > the trade was initiated.
> > > > > > 
> > > > > > All hints are appreciated.
> > > > > > Thanks,
> > > > > > /Fredrik
> > > > > >
> > > > >
> > > >
> > >
> >
>


Reply via email to