PureBytes Links
Trading Reference Links
|
Hi,
I was not suggesting that you change your existing looping code, but
rather that you replace your call to bo.FindSignal with an
*additional* loop (assuming that you could not get bo.FindSignal to
work the way you expect).
So, your code becomes:
for (pos = bo.GetFirstOpenPos(); pos; pos = bo.GetNextOpenPos()) {
if (pos.BarsInTrade >= Nbar) {
newSignal = false;
// Substitute for bo.FindSignal
for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i)) {
if (sig.isEntry() && sig.Symbol == pos.Symbol) {
newSignal = true;
break;
}
}
if (newSignal) {
// ignore sell signal if we also have a buy signal
} else {
NextDayOprice = pos.getprice(i,"O");
bo.ExitTrade(i, pos.symbol, NextDayOprice, 5);
}
}
}
Mike
--- In amibroker@xxxxxxxxxxxxxxx, "tipequity" <l3456@xxx> wrote:
>
> Mike
>
> Thanks for your response. Theoretically, since I am trying to exit
> after Nbars on NO buy siganls I should not be looping thru buy or
> sell signals. However, I did try it at follows and it did not work.
> TIA
>
> for ( sig = bo.GetFirstSignal( i ); sig; sig = bo.GetNextSignal(
i ) )
> {
> Pos = bo.FindOpenPos( sig.Symbol );
> if ( (sig.IsEntry() == False) AND (pos == True) AND
> (pos.BarsInTrade >= Nbar) )
> {
> NextDayOprice = pos.getprice(i,"O");
> bo.ExitTrade( i, pos.symbol, NextDayOprice, 5);
> _TRACE("i= " + i + " Date: " + dtstr + " Symbol: :" +
> pos.Symbol + " BarsinTrade: " +
> pos.BarsInTrade + " We DONT
> have Buy Signal: " );
> }
> }
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> >
> > Hi,
> >
> > I'm not familiar with the FindSignal method that you describe.
But,
> > it sounds like you could get the same thing by looping through
the
> > list of signals using GetFirstSignal(i) and GetNextSignal(i)
> > http://www.amibroker.com/guide/a_custombacktest.html
> >
> > Mike
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "tipequity" <l3456@> wrote:
> > >
> > > The following CBT code is supposed to sell a long position
after
> > nth
> > > bar if I don't have a buy signal on the nth bar. The logic for
> the
> > > code is as follows:
> > >
> > > 1. loop thru open position list
> > > 2. if a positions has been open for nbar then check the buy
list
> > > 3. if the symbols exits in the buy list do nothing else sell
the
> > > position.
> > >
> > > For some reason that I can not figure out, the new function
> > > FindSignal always return a null value. Can anybody provide some
> > > insight or an alternative solution? TIA
> > >
> > >
> > > for ( pos = bo.GetFirstOpenPos(); pos; pos = bo.GetNextOpenPos
() )
> > > {
> > > if ( pos.BarsInTrade >= Nbar )
> > > {
> > > _TRACE("i= " + i + " Date: " + dtstr + " Symbol: :" +
> > > pos.Symbol + " BarsinTrade: " + pos.BarsInTrade + " Max
Holding
> > > Period");
> > > if ( Sig = bo.FindSignal( i, pos.Symbol, 1 ) )
> > > {
> > > // ignore sell signal if we also have a buy
> > > signal
> > > _TRACE("i= " + i + " Date: " + dtstr + "
> > > Symbol: :" + pos.Symbol + " BarsinTrade: " + pos.BarsInTrade
+ "
> > > ignore sell signal, we have Buy Signal, don't sell: " + sig);
> > > }
> > > else
> > > {
> > > NextDayOprice = pos.getprice(i,"O");
> > > bo.ExitTrade( i, pos.symbol, NextDayOprice,
> > > 5);
> > > _TRACE("i= " + i + " Date: " + dtstr + "
> > > Symbol: :" + pos.Symbol + " BarsinTrade: " + pos.BarsInTrade
+ "
> > We
> > > DONT have Buy Signal: " + sig );
> > > }
> > > }
> > > }
> > >
> >
>
------------------------------------
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
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/
|