Hello Bary

Thanks for the input. I have used this trailing stop with metastock for some 
time and it came originally from the author Leon Wilson at a presentation he 
gave at the Australian Technical Analysis conference well before it was 
published in S & C tips 
(http://www.traders.com/documentation/FEEDbk_docs/2008/01/TradersTips/TradersTips.html#amibroker).
 It is part of my trading strategies and I would like to some how get it to 
work properly in AB if at all possible. The trailing stop differs from the 
commonly used relative stops (ie constant value offset, multiplier or 
percentage) and momentum stops (i.e. using a multiplier or variance value) by 
the way it takes advantage and responds to market conditions through the use of 
the RSI or any other such as directional movement ie bias stops are designed to 
avoid retracement activity in potentially unsustainable conditions while 
keeping the trader in stable and consistent trend movements;

So my interest in this type stop is to keep me in the trade as long as possible 
while the trend is sustainable. If I can avoid manipulating array elements 
using looping all the better. The problem I have is that the AB code does not 
work, as it should. The calculation and display on the chart of the stop should 
start at the input date and TL (the trailing stop) should have the same value 
(the low of the bar on "input date" in a long trade in this case or less) and 
the bias stop applies a changing value as defined by an indicator such as 
directional movement or RSI.  This keeps the effect of whipsaws to a minimum by 
giving enough volatility movement for the stock while the trend is sustainable 
and pulls the stop in tightly under the low when the trend becomes 
unsustainable eg oversold. 

The code given in S & C takes data from the left hand and continues the 
calculation to the right hand values with a result that ignores the starting 
values. If you have a downtrend and you apply the initial stop at the pivot 
point or any value happens to fall below the trailing stop set in motion from 
the left hand side of the chart you get a totally nonsensical result of a 
horizontal line above the price chart. 

I would be keen to know if someone has successfully solved this problem using 
arrays it would certainly go a long way in helping me to understand how it 
works. 

Lastly take your point on back testing as valid but I would like to see the 
results using AB and confirm a positive expectation when using this stop as 
part of a system.

Any input would be enormously appreciated. 

Thanks for listening to this long-winded explanation.
Cheers
Ed


--- In [email protected], "Barry Scarborough" <razzba...@...> wrote:
>
> Mostly I write auto trading programs and I send an order with a trailing stop 
> target and forget about it. If I control the exit ordering within the program 
> I set a static var with the trade price and use that when calculating the 
> stop. But, it seems you are trying to set this in back test, something I 
> don't waste much time on, and are trying to simulate your real time results. 
> 
> A trend starts when you have a buy or short signal. You can set the price of 
> the trade in BuyPrice or ShortPrice. Then you can use BarsSince to find that 
> value. If the BarsSince Short is a smaller number than BarsSince Buy you know 
> you are in a down trend and you would use the number of bars returned from 
> the short in Ref(ShortPrice, -BarsSinceShort); Then you don't care about 
> for{} loops. You access the ShortPrice directly and add your trailing offset 
> and compare that to the current C, MA crossover value or whatever. Exit the 
> position when the C is above the stop value, in the Short case, or below it 
> in the long case.
> 
> Give that a go and see if you can make it work. I think you will find the 
> code much more concise than using a loop. And it is a lot faster.
> 
> Barry
> 
> --- In [email protected], "edwol53" <edwol@> wrote:
> >
> > Hello Barry
> > 
> > Thankyou for the heads up on this issue - your valuable experience and 
> > comments are much appreciated.
> > 
> > As for your comments regarding a way of devising a dynamic way of accessing 
> > eaqrlier bars using standard AFL logic would be ideal, but I am trying to 
> > resolve a problem with a trailing stop which I refered to in message 138653 
> > Re: Trailing Stop S & C tips 1-2008   & 138598 Trailing Stop S & C tips 
> > 1-2008 
> >  
> > All the trailing stops I have seen in AB seem to fall back on using flow 
> > control structures such as "for i = " loops to ratchet the stop.
> > 
> > In this case it requires a starting point at a given date on the chart 
> > applying a stop value on that date to start the calculation (ie access to 
> > an array element).
> > 
> > If there is a way of using AFL array logic to circumvent array element 
> > manipulation,I am open to suggestion.
> > 
> > Thank again for your input and other suggestions that you have regarding my 
> > comments above are most welcome.
> > 
> > Cheers 
> > Ed
> > 
> > --- In [email protected], "Barry Scarborough" <razzbarry@> wrote:
> > >
> > > Unless you specify SetBarsRequired(nnnn,nnnn) where nnnn is larger than 
> > > the number of bars in your database Ami will only load enough bars, into 
> > > a temporary array, so that it can display your charts correctly. When you 
> > > add more bars to a window the temp array is enlarged and the indicator is 
> > > recalculated so that what is plotted will again be correct. So the number 
> > > you get in your test will be the number of bars displayed + the longest 
> > > period in any of your indicators. It gets worse. If you try to manually 
> > > access data that is beyond the scope of the temporary array you will get 
> > > an access violation which will either blow your program up or return 
> > > invalid data. 
> > > 
> > > There is another thing you need to know. When you set anything in an 
> > > array you will have to set it every time the indicator is scanned. When 
> > > the indicator is scanned all the indicators plotted are recalculated. In 
> > > real time trading this can be many times a second and since you will be 
> > > adding data the point you want to access may be outside the scope of the 
> > > bars. If you are using static data it will scan your indicator every time 
> > > you click on a bar or change the number of bars displayed or scroll 
> > > through the bars. Managing data as you plan will get very complicated and 
> > > hell to debug when it works incorrectly. Expect errors.
> > > 
> > > You will be much better off if you can devise a dynamic way to access 
> > > data in earlier bars using standard AFL logic. Then reference it with the 
> > > Ref() statement. I see some people using for, do and while loops in Ami. 
> > > Most of the time that can be replaced with AFL array logic which is much 
> > > faster and less prone to calculation errors. For example someone sent me 
> > > a formula the other day to debug. It was using all the bars in the 
> > > ticker. I was testing an auto trading formula on a 5 minute chart and 
> > > when I started his formula Ami ground to a crawl. It was processing his 
> > > loop three times a second, well it was trying to and doing badly. Avoid 
> > > loops wherever possible.
> > > 
> > > Barry
> > > 
> > > --- In [email protected], "edwol53" <edwol@> wrote:
> > > >
> > > > Hello 
> > > > 
> > > > I am trying to access/extract a subscript [i] if an array element a[i].
> > > > 
> > > > The aim is to input a date and extract the bar subscript from that 
> > > > date's bar so that the subscript can be used over-write/modify an 
> > > > associated array element[i] (if I understand how array data is 
> > > > constructed in AFL correctly ???)
> > > > 
> > > > A test code segment and debug outputis shown below. The issue I am 
> > > > having difficulty with is that in the first line the index and barcount 
> > > > are correct if all the data (including bars not displayed on the 
> > > > screen) is taken into account. In line 2 the barcount readjusts to 
> > > > number of bars displayed on the screen. I can accept that as a quirk 
> > > > but works. I then zoom out (as shown by barcount)loading all the bars 
> > > > (data) onto the screen(debug shows zoomout effect in line 9 - 26. But 
> > > > the subscript [i] is now empty from line 20 - as I continue to zoom out 
> > > > on the chart. Why?
> > > > 
> > > > Is this a bug or is there something I am missing?? 
> > > > 
> > > > Can anyone offer an explanation as to what is happening?
> > > > 
> > > > // Array or number ?
> > > > dt = ParamDate("Date of the trend", "2009-05-25" ,0);
> > > > i=0;
> > > > i = ValueWhen(DateNum() == dt, BarIndex(), 1);
> > > > 
> > > > _TRACE(" i = " +  NumToStr(i, 1.0) + " index date = " + NumToStr(dt, 
> > > > 1.0) + " Barcount = " + NumToStr(BarCount, 1.0) );
> > > > 
> > > > 00000000        0.00000000      [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 6,416       
> > > > 00000001        0.03319501      [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 69  
> > > > 00000002        2.32265329      [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 69  
> > > > 00000003        7.29352045      [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 69  
> > > > 00000004        12.29429150     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 69  
> > > > 00000005        17.29241562     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 69  
> > > > 00000006        22.29343414     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 69  
> > > > 00000007        27.29189682     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 69  
> > > > 00000008        32.29233551     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 69  
> > > > 00000009        36.40725327     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 92  
> > > > 00000010        36.77444458     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 127 
> > > > 00000011        37.05470276     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 179 
> > > > 00000012        37.29121780     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 179 
> > > > 00000013        37.30448532     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 257 
> > > > 00000014        37.54277802     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 374 
> > > > 00000015        37.72683716     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 550 
> > > > 00000016        37.91091156     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 814 
> > > > 00000017        38.09486389     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 1,210       
> > > > 00000018        38.33518219     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 1,804       
> > > > 00000019        39.79113770     [2440]  i = 6,413 index date = 
> > > > 1,090,525 Barcount = 2,695       
> > > > 00000020        40.27950287     [2440]  i = {EMPTY} index date = 
> > > > 1,090,525 Barcount = 4,031     
> > > > 00000021        40.58501816     [2440]  i = {EMPTY} index date = 
> > > > 1,090,525 Barcount = 6,035     
> > > > 00000022        40.80830765     [2440]  i = {EMPTY} index date = 
> > > > 1,090,525 Barcount = 6,416     
> > > > 00000023        42.29502487     [2440]  i = {EMPTY} index date = 
> > > > 1,090,525 Barcount = 6,416     
> > > > 00000024        47.29590988     [2440]  i = {EMPTY} index date = 
> > > > 1,090,525 Barcount = 6,416     
> > > > 00000025        52.29293823     [2440]  i = {EMPTY} index date = 
> > > > 1,090,525 Barcount = 6,416     
> > > > 00000026        57.29567719     [2440]  i = {EMPTY} index date = 
> > > > 1,090,525 Barcount = 6,416
> > > >
> > >
> >
>


Reply via email to