PureBytes Links
Trading Reference Links
|
Barry -
I thought I'd take this one since I'm here. I'm not going to answer your BarsSince() question directly, but rather address your goal from your first paragraph since BarsSince appears to be kind of a detour.
But, briefly, you have described a situation where there is a "ripple effect". For example, if you are on a buy, whether or not you take the stop and where you take it affects the stop for the subsequent sell. And then, it affects the subsequent buy ... and so on. IOW, it ripples through.
There are a couple of approaches to handling this, but the easiest to see is looping over bars. This ripple is problematic for basic array logic. Assuming that you just want a model for a solution and not a lengthy explanation of the array considerations, I suggest that you take a look at the following link to the Amibroker site members area. Tomasz posted a code example for June Stock & Commodities that included a "fixed percentage" trailing stop. Interesting approach also in handling the system state in the "trailstop" variable -
http://www.amibroker.com/members/traders/06-2009.html
I think that this is what you want. Hope this helps,
BruceR
--- In amibroker@xxxxxxxxxxxxxxx, "Barry" <razzbarry@xxx> wrote:
>
> I am trying to buy when the price rises a certain amount above the lowest close since the last sell or sell when price has fallen a certain amount below the highest close since the last buy.
>
> I am trying to use barssince to find the number of bars since the last buy or sell. But before there has been a buy or sell I want to use Lowest(C) or Highest(c) then switch to HHV and LLV once there has been a trade.
>
> So I wrote a test program to see how barssince works.
>
> periods = Param( "Periods", 14, 2, 30, 1 );
> fCCI = CCI( periods );
>
> Buy = Sell = 0;
>
> bsBuy = Nz(BarsSince(Buy), -1);
> bsSell = Nz(BarsSince(Sell), -1);
> printf(StrFormat("Bars since buy = %g \nBars since sell = %g", bsBuy, bsSell));
>
> theLo = IIf(bsSell == -1, Lowest(C), LLV(C, bsSell)); // lowest close since last sell
> theHi = IIf(bsBuy == -1, Highest(C), HHV(C, bsBuy)); // hignest close since last buy
>
> Buy = Cross(fCCi, -50);
> Sell = Cross( 50, fcci);
>
> When I put the buy and sell assignments below the barssince it always returns -1. Even after there is a buy or sell it still returns -1. If I move the buy and sell assignments above the bsBuy and bsSell it works fine. But in my program the buy and sell must be after barssince.
>
> What I don't understand is why barssince never sees that a buy or sell has occurred? Shouldn't it see the buy or sell after the CCI cross and start returning the number of bars rather than -1? I am using shapes to see the buy and sell points but after that barssince still returns -1. What is going on?
>
> The system does not use indicators so I can't set the buy or sell before the CCI cross as in this test. I have to use Lowest or Highest before the first trade then switch to HHV and LLV after that. How do I do that?
>
> Thanks,
> Barry
>
------------------------------------
**** 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/
|