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

[amibroker] BarsSince question



PureBytes Links

Trading Reference Links

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/