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

Re: [amibroker] Re: Checking the past by referencing current bar price?



PureBytes Links

Trading Reference Links

Thanks Sebastian, it seems you understood correctly... forgive me if I
go on asking, hope you (as well as others) can also find inspiration
while helping, read on...

>If the "buy" condition
> is met today, "buy", but only if the last "buy" signal would have
> resulted in a losing trade.
Problem is there are NO losing trades with the strategy I'm
backtesting. No stop loss ever. Scary, eh?
Maybe the condition can be reversed? Buy only if the last buy resulted
in a winning trade, that was my aim with Cond2

> I used the ValueWhen function to find the entry and exit points on
> the trade previous to the one currently being signaled, then made
> reference to them as a condition of the new trade being signalled.
That's what I had in mind, maybe the inherent recursion (last trade
was taken on the same basis) makes it difficult for me.

> The distinction being that I wasn't referring to an actual "trade"
> but "the conditions under which the previous trade would have been
> made."  
let's simplify and imagine that Cond1 is: Buy if L>int(C), we're going
to buy (or scale in) at every integer price level (multiple open
positions when price goes south) but only *once* per integer price
level.
Cond2 is the take profit (next higher integer price): Sell if L>int(c)
this is closing only the trade taken at int(C) - 1
So in the past the latest Buy condition *for the current level* was
true when L>int(currentC), but if I use
valuewhen( L>int(C), Barindex() )
I don't necessarily get the buy signal corresponding to the current
price, just the last time L>int(C) for some C in the past

now if I could compare L>int(C[currentBar]) I could take the trade when
valuewhen( L>int(C[currentBar]), Barindex() ) <  valuewhen(
H>int(C[currentBar] + 1), Barindex() )

> Another tip, the latest signal is the most recent occurrence
> of a "buy" condition, but the previous "buy" signal is the 2nd-most
> recent occurrence, and that was an important point in defining the
> previous condition.
I guess this depends on the condition used, I could have any number of
buy conditions in the past that didn't correspond to an actual trade
before the actual one.

>What helped me solve the problem was
> to display the code that I started with as buy/sell arrows on a
> chart, so that I could eyeball the signals for errors and zero-in on
> where my definitions weren't correct.
I did this while coding the loops, don't we all love TJ for making
this sooo easy to do

> Hope that helps give you an idea how to solve your "deal.":)
thanks so far, seems I need more boost to kill those inefficient loops
and varget/set pseudoarrays :)

> Luck,
and "edge" to you

neuro

> 
> --- In amibroker@xxxxxxxxxxxxxxx, neurotic self <neuroticself@xxxx>
> wrote:
> > Figured it out somehow
> >
> > Running the code via Scan after adding
> >
> > AddToComposite(Indicator, "~Indicator", "X");
> >
> > and then plotting the resulting symbol with Foreign instead of
> > plotting Indicator directly I can see that the correct adjustment
> have
> > been made.
> >
> > I guess that for the sake of efficiency the bars used when graphing
> > are less than when scanning (there I have full control of the period
> > used), I tried
> >
> > SetBarsRequired(-100000, 100000);
> >
> > in the graph also but it didn't seem to work
> >
> > Still it would have been nice to obtain this with VALUEWHEN to look
> at
> > the past instead of looping, if somebody feels like giving
> > suggestions... I'm beginning to think it can't be made w/o loop
> >
> > On 9/10/05, neurotic self <neuroticself@xxxx> wrote:
> > > Maybe somebody could have a look at what's wrong with this code?
> runs
> > > ok, but I don't get the indicator adjusted
> > >
> > > remember that:
> > > > Trying to build an indicator along the following lines:
> > > > if price at bar satisfies condition Cond1 then Indicator = 1
> > > > UNLESS the price did NOT satisfy Cond2 from last time Indicator
> was 1
> > > > AND Close was == Close at bar, in which case Indicator = 0
> > >
> > > Indicator = IIf(Cond1, 1, 0); // first just check Cond1 on all
> history
> > >
> > >  //adjust for Cond2
> > > for (i= 1; i < BarCount; i++) {
> > >
> > >    if ( Cond1[i]  )
> > >    for (k=i-1; k > 0 ; k--) { // looking at the past of  bar i
> > >       if ( Close[k] == Close[i]  AND Cond1[k]  ) { Indicator[i] =
> 0; j
> > > = 0;} // adjust bar i, exit loop
> > >       if ( Cond2[k] ) k = 0; // Cond 2 met, exit loop
> > >
> > >    }
> > >
> > > }
> > >
> > > On 9/9/05, neurotic self <neuroticself@xxxx> wrote:
> > > > This is causing me a big headache, hope I can express my
> problem clearly...
> > > >
> > > > Trying to build an indicator along the following lines:
> > > > if price at bar satisfies condition Cond1 then Indicator = 1
> > > > UNLESS the price did NOT satisfy Cond2 from last time Indicator
> was 1
> > > > AND Close was == Close at bar, in which case Indicator = 0
> > > >
> > > > I thought of using ValueWhen so
> > > >
> > > > bi = BarIndex();
> > > > Indicator[0] = Cond1[0];
> > > > Indicator = IIf (ValueWhen(bi, Ind == 1 AND Close ==
> CloseAtBar) <
> > > > ValueWhen(bi, Cond2 ), Cond1, 0)
> > > >
> > > > Can't find a way to reference CloseAtBar, tried via Barindex()
> with
> > > > C[Barindex()] but that makes no sense given that Barindex() is
> an
> > > > array and can't be used as a subscript
> > > >
> > > > Also tried to explicitly loop back in the past from current bar
> to
> > > > check if Cond2 was met before price touched again price at bar
> and
> > > > Indicator was 1, kind of like
> > > >
> > > > for (i=BarIndex() ; i > 0; i--) {...
> > > >
> > > > but again Barindex() is not the "current" bar but an array
> > > >
> > > > Maybe I should loop all the history
> > > >
> > > > for( i = 1; i < BarCount ; i++)
> > > >
> > > > and compute Indicator bar by bar? I did something similar with
> the
> > > > custom backtester but I'd really like a simplier solution, feel
> like
> > > > valuewhen could do the job, but that function always escaped me
> > > > somehow :(
> > > >
> > > > Thanks for any help
> > > > n.
> > > >
> > > > --
> > > > Janeczko for President!
> > > >
> > >
> > >
> > > --
> > > Janeczko for President!
> > >
> >
> >
> > --
> > Janeczko for President!
> 
> 
> 
> 
> 
> 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 other support material please check also:
> http://www.amibroker.com/support.html
> 
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 
> 
> 


-- 
Janeczko for President!


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Help tsunami villages rebuild at GlobalGiving. The real work starts now.
http://us.click.yahoo.com/njNroD/KbOLAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

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 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/

<*> 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/