PureBytes Links
Trading Reference Links
|
You will probably need to add additional conditions, or maybe another
function to ensure you have something that gives a value. You need to
go through to work out what and why something does not give an answer,
you have done this up to a certain point, just a bit more required. If
the MA or any indicator is null, which is often the case with
indicators requiring minimum bars to calculate, you would need to
convert the null value effect somewhere. Remember that null-1=null or
null+1=null. Any calculation with null will give a null result. Below
I have just ensured you get a previous value to get the bassince from,
or in the second remove the actual null values
Buy = myBuy and cum(mybuy)>0 AND nz( bsBuy ) -
nz( bsSel ) > 0;
etc
or maybe just this
bsBuy = nz( Ref(BarsSince(myBuy), -1) );
These may not be the whole solution as I have just quickly typed
typical methods. You need to check values of the variables to see what
effect the null's have. eg perhaps myBuy needs to be nz(mybuy) or
other items like this. I always find running exploration the best
method to find possible problems.
Sometimes you may be required to use a bar loop (last resort as loops
will slow things down becasue all bars are needed) if the above simple
type methods do not help.
These lines are not required
Buy = Sell = Short = Cover = 0;
myBuy = mySell = myShort = myCover = 0;
--
Cheers
Graham Kav
AFL Writing Service
http://www.aflwriting.com
2009/5/15 Barry Scarborough <razzbarry@xxxxxxxxxxxx>:
> I found a way to accomplish what I want to do. I cannot get the first assignment of barssince to work. Teh code is below.
>
> Barry
>
> // BarsSince test
> #include <AT Functions\Colors.afl>
>
> fMA = MA(C, 5);
> fMAup = fMA >= Ref(fMA, -1);
> fMAdn = fMA < Ref(fMA, -1);
>
> Plot(fMA, "MA", MA1color);
> Plot( C, "Close", pricecolor, styleNoTitle | styleBar ); // shows all style options
>
> Buy = Sell = Short = Cover = 0;
> myBuy = mySell = myShort = myCover = 0;
>
> myBuy = fMAup;
> myShort = fMAdn;
> mySell = fMAdn;
> myCover = fMAup;
>
> // barssince returns the true values here
> bsBuy = Ref(BarsSince(myBuy), -1);
> bsSel = Ref(BarsSince(mySell), -1);
> bsSht = Ref(BarsSince(myShort), -1);
> bsCov = Ref(BarsSince(myCover), -1);
> StrFormat("\nBS buy=%g, BS sell=%g \nBS short=%g, BS cover=%g", bsBuy , bsSel, bsSht, bsCov);
> StrFormat("\nBBbuy > BSsell = %g barindex = %g", bsSel - bsBuy, BarIndex());
>
> Buy = myBuy AND bsBuy - bsSel > 0;
> Short = myShort AND bsSht - bsCov > 0;
> Sell = mySell AND bsSel - bsBuy > 0;
> Cover = myCover AND bsCov - bsSht > 0;
> StrFormat("\nBS buy=%g, BS sell=%g \nBS short=%g, BS cover=%g", Buy , Sell, Short, Cover);
>
> PlotShapes(myBuy * shapeUpArrow, uparrow, 0, Low, -5);
> PlotShapes(mySell * shapeDownArrow, dnarrow,0, High, -5 );
> PlotShapes(Short * shapeHollowDownArrow, dnarrow, 0, High, -20 );
> PlotShapes(Cover * shapeHollowUpArrow, uparrow, 0, Low, -20);
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>>
>> It's not clear what code you were testing since your mixing two snippets together that don't coincide with each other.
>>
>> The point that I'm trying to make is this: BarsSince returns the number of bars since the *last non zero value*.
>>
>> Breaking it down to the most simplified form;
>>
>> -- begin file --
>> // At this point BarsSince(Buy) is "never" or an error depending on whether Buy array is considered undefined here. Sorry I don't have AmiBroker at my disposal.
>>
>> Buy = 0;
>> // At this point BarsSince(Buy) is "never", there are no non zero values.
>>
>> Buy = <any non zero value or array>
>> // At this point BarsSince(Buy) is the number of bars since last non zero value.
>> -- end file --
>>
>> Your observations would seem to suggest that "never" maps to 1e+010. If 1e+010 is the representation of null, then so be it. Again, I don't have AmiBroker in front of me right now to test.
>>
>> Are you suggesting that you have found a case where you have assigned a *non zero value* to Buy and then found BarsSince(Buy) to be null?
>>
>> Mike
>>
>> --- In amibroker@xxxxxxxxxxxxxxx, "Barry Scarborough" <razzbarry@> wrote:
>> >
>> > Lets forget the logic and figure out why the first barssince assignment always returns nulls. I took all the time and other conditions out and just assigned
>> >
>> > buy = cover = maUp;
>> > sell = short = maDn;
>> >
>> > I assigned sinceBars for all 4 cases above and below the assignment of buy, sell, short and cover and barssince still returns nulls before and true values after. If barssince can never return good values before a logic statement how can it ever be used? I have used barssince before and never ran into this. I must be missing something very basic.
>> >
>> > Buy = Sell = Short = Cover = 0;
>> >
>> > // barssince returns null here
>> > bsBuy = BarsSince(Buy);
>> > bsSel = BarsSince(Sell);
>> > bsSht = BarsSince(Short);
>> > bsCov = BarsSince(Cover);
>> > StrFormat("\nBS buy=%g, BS sell=%g \nBS short=%g, BS cover=%g", bsBuy , bsSel, bsSht, bsCov);
>> >
>> > Buy = fMAup;
>> > Short = fMAdn;
>> > Sell = fMAdn;
>> > Cover = fMAup;
>> >
>> > // barssince returns the true values here
>> > bsBuy = BarsSince(Buy);
>> > bsSel = BarsSince(Sell);
>> > bsSht = BarsSince(Short);
>> > bsCov = BarsSince(Cover);
>> > StrFormat("\nBS buy=%g, BS sell=%g \nBS short=%g, BS cover=%g", bsBuy , bsSel, bsSht, bsCov);
>> >
>> > Why is the first barssince always null?
>> >
>> > Thanks,
>> > Barry
>> >
>> >
>> >
>> > --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
>> > >
>> > > I haven't tested this out. But, what value would you expect if the condition you are looking for has never happened?
>> > >
>> > > Zero means most recent occurence is current bar, 1 means one bar ago, 2 means two bars ago, etc. What value means "never happened yet"?
>> > >
>> > > Based on your observations, presumably the answer is 1e+010. You will need to handle that scenario in your logic.
>> > >
>> > > Mike
>> > >
>> > > --- In amibroker@xxxxxxxxxxxxxxx, "Barry Scarborough" <razzbarry@> wrote:
>> > > >
>> > > > I must be brain dead this morning. BarsSince is not working as expected. I am trying to use BarsSince in the signal logic but when I try to set the values before the buy sell short and cover the value returned is null, 1e+010. That doesn't make sense. If I get the values after the signals are set the values are correct. But this prevents them from being use in the signal logic.
>> > > >
>> > > > Why doesn't BarsSince return the correct values in the first assignment?
>> > > >
>> > > > The code follows.
>> > > >
>> > > > Thanks,
>> > > > Barry
>> > > >
>> > > > // BarsSince test
>> > > > #include <AT Functions\Colors.afl>
>> > > >
>> > > > fMA = MA(C, 5);
>> > > > fMAup = fMA >= Ref(fMA, -1);
>> > > > fMAdn = fMA < Ref(fMA, -1);
>> > > > Plot(fMA, "MA", MA1color);
>> > > >
>> > > > sysTime = TimeNum();
>> > > > tradeTime = IIf(sysTime >= 73000 AND sysTime < 161500, True, False);
>> > > >
>> > > > Plot( C, "Close", pricecolor, styleNoTitle | styleBar ); // shows all style options
>> > > >
>> > > > Buy = Sell = Short = Cover = 0;
>> > > >
>> > > > // #### First assignment
>> > > > // barssince returns null here
>> > > > bsBuy = BarsSince(Buy);
>> > > > bsSel = BarsSince(Sell);
>> > > > bsSht = BarsSince(Short);
>> > > > bsCov = BarsSince(Cover);
>> > > > StrFormat("sysTime=%g, TradeTime=%g \nBS buy=%g, BS sell=%g \nBS short=%g, BS cover=%g",sysTime, tradeTime, bsBuy , bsSel, bsSht, bsCov);
>> > > >
>> > > > Buy = tradeTime AND fMAup; // works fine
>> > > > // when I try to use barssince the buy logic is never true.
>> > > > Buy = tradeTime AND fMAup AND bsBuy > bsSell; // never true
>> > > >
>> > > > Short = tradetime AND fMAdn;
>> > > > Sell = tradetime AND fMAdn;
>> > > > Cover = tradetime AND fMAup;
>> > > >
>> > > > // #### Second assignment
>> > > > // barssince returns the true values here
>> > > > bsBuy = BarsSince(Buy);
>> > > > bsSel = BarsSince(Sell);
>> > > > bsSht = BarsSince(Short);
>> > > > bsCov = BarsSince(Cover);
>> > > >
>> > > > StrFormat("\nBS buy=%g, BS sell=%g \nBS short=%g, BS cover=%g", bsBuy , bsSel, bsSht, bsCov);
>> > > >
>> > > > PlotShapes(Buy * shapeUpArrow, uparrow, 0, Low, -5);
>> > > > PlotShapes(Sell * shapeDownArrow, dnarrow,0, High, -5 );
>> > > > PlotShapes(Short * shapeHollowDownArrow, dnarrow, 0, High, -20 );
>> > > > PlotShapes(Cover * shapeHollowUpArrow, uparrow, 0, Low, -20);
------------------------------------
**** 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/
|