Brilliant! There is nothing more beautiful than a brilliant mind. As 
for FindSignal, I could not get it to work.I think TJ needs to let us 
know if my usage of it is correct or there is a bug with it. Many 
thanks.

--- In [email protected], "Mike" <[EMAIL PROTECTED]> wrote:
>
> 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 [email protected], "tipequity" <l3456@> 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 [email protected], "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 [email protected], "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 );
> > > >                 }
> > > >         }
> > > > }
> > > >
> > >
> >
>


Reply via email to