PureBytes Links
Trading Reference Links
|
Came up with a solution. If I use Foreign and get the High/Low/Open arrays that way it works fine.
/Fredrik
--- In amibroker@xxxxxxxxxxxxxxx, "broman1003" <fredrik_broman1003@xxx> 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@xxxxxxxxxxxxxxx, "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@xxxxxxxxxxxxxxx, "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@xxxxxxxxxxxxxxx, "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
> > > >
> > >
> >
>
------------------------------------
**** 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/
|