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