Problem Debugging

Using AB 6.35.1
I tried to solve this problem using AB's Debugger, but can't focus it on the time of error.
Please see chart image limiting barinterest from 6/16/2022 to 7/6/2022 (from Analysis From-To date), inclusive, and the Watch image as well.
As for the code, it should Buy on 6/23/2022 at $285.19 and sell on 6/28/2022 at $291.28.

// Show BuyH SellL.afl    2/19/2024

//  buy and hold simulation
	Short=Cover=0;
	Buy=Status("firstbarintest");
	Sell=Status("lastbarintest");
	Plot( Equity( 0, -2 ), "Buy&Hold", colorBlue );

Buy = BuyatOpen = Sell = SellatOpen = 0;
Short = Cover = 0; // long only 

// Can't see how to limit Buys & Sells to bars of interest
// using Analysis From-To dates and Debug using only those bars!
// should buy on 6/23/2022 & sell on 6/28/2022.
	Buy = Cross (High, Ref(High, -1));
	BuyatOpen = Cross (Open, Ref(High, -1));
	Sell = Cross (Ref(Low, -1), Low);
	SellatOpen = Cross (Ref(Low, -1), Open);

	Buyprice = IIf(BuyatOpen, Open, Ref(High, -1)+0.01);
	Sellprice = IIf(SellatOpen, Open, Ref(Low, -1)-0.01);

	Buy = ExRem(Buy, Sell);
	Sell = ExRem(Sell, Buy);
shapes = IIf(Buy, shapeUpArrow,
		IIf(Sell, shapeDownArrow, shapeNone));
shapecolors = IIf(Buy, colorGreen,					
			IIf(Sell, colorRed, colorWhite));
shapewhere = IIf(Buy, Low, High);
PlotShapes(shapes, shapecolors, 0, shapewhere);
Plot(Equity(1,-1,0,0), "Equity", colorGreen, styleThick);
![240219 AB Chart|555x450](upload://5vOua2rF4CSetYXazF0v3jQIsuK.png)
![240219 AB Watch Array|375x320](upload://8NhHVR4IUguM6tZBbPkGGTvOWuA.png)

If you scroll down to the bottom of the code, see:

240219 AB Chart

240219 AB Watch Array

I thought the two .png file would display. But, duh.

Moderator comment: they display, but only if you don't wrap the PNGS into code tags as you did. I removed code tags and as you can see, there are pictures visible.

Thank You very much, understand that now. Hoping for solution to this "Problem Debugging", shortly.

@KeithMcC, it's not very clear to me what you want to achieve.

In any case, it makes no sense to have multiple BUY/SELL conditions in the same formula where the second cancel the first...
Furthermore, as can also be seen from your "watch", the conditions of the second BUY/SELL block do not generate any BUY signal for the start date nor SELL for the end date of the range.

So to get the results you indicated the code could be modified like this (although personally I still don't understand the purpose):

// Show BuyH SellL.afl    2/19/2024
Buy = BuyatOpen = Sell = SellatOpen = 0;
Short = Cover = 0; // long only
Buy = Status( "firstbarinrange" );
Sell = Status( "lastbarinrange" );
// Plot( Equity( 0, -2 ), "Buy&Hold", colorBlue );
// Can't see how to limit Buys & Sells to bars of interest
// using Analysis From-To dates and Debug using only those bars!
// should buy on 6/23/2022 & sell on 6/28/2022.
BuyatOpen = Cross( Open, Ref( High, -1 ) );
SellatOpen = Cross( Ref( Low, -1 ), Open );
Buyprice = IIf( BuyatOpen, Open, Ref( High, -1 ) + 0.01 );
Sellprice = IIf( SellatOpen, Open, Ref( Low, -1 ) - 0.01 );
shapes = IIf( Buy, shapeUpArrow, IIf( Sell, shapeDownArrow, shapeNone ) );
shapecolors = IIf( Buy, colorGreen, IIf( Sell, colorRed, colorWhite ) );
shapewhere = IIf( Buy, Low, High );
PlotShapes( shapes, shapecolors, 0, shapewhere );
Plot( Close, "Price", colorDefault, styleCandle );
// Plot(Equity(1,-1,0,0), "Equity", colorGreen, styleThick);

By the way, here I used "firstbarinrange"/"lastbarinrange" (instead of "firstbarintest"/"lastbarintest". @Tomasz could you kindly explain the difference, because the description in the manual is not very clear to me: if I don't change the dates of the range between the various analysis modes are they equivalent? Thanks!

1 Like

"inrange" refers to range used in ANY analysis mode (scan/exploration/backtest/etc). "intest" refers to range used ONLY in backtest.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.