PlotShapes Not Showing Up in Backtest (No1)

I am trying to get the PlotShapes code to work in my backtest, but the trade arrows do not seem to show up on the chart. If I double click on the symbol in the results list, they show up, but they do not do it automatically and as per my code. Not sure what I am doing wrong.

I do have show trade arrows as Yes in the chart parameter.

Could it be that I have a couple of tabs of charts (bottom of Amibroker screen), and the one I am using is the 2nd tab (if that makes any sense!)?

//Buy XIV if $VXV >= $VIX
//Buy VXX if $VXV < $VIX
//Set Watchlist to XIV Only

#include_once "Formulas\Norgate Data\Norgate Data"

// Portfolio Settings
SetOption( "InitialEquity", 75000 ); /* starting capital */
SetOption( "CommissionMode", 3 ); /* set commissions AND costs as $ per share */
SetOption( "CommissionAmount", 0.005 ); /* commissions AND cost */
SetOption("MaxOpenPositions", 1);
SetPositionSize(100, spsPercentOfEquity);

// Sets the other tickers to reference to test the conditions for trading
VXV = Foreign( "$VXV", "C" );
VIX = Foreign( "$VIX", "C" );
XIV = Foreign( "XIV", "C" );
VXX = Foreign( "VXX", "C" );

// Sets the Buy and Sell conditions
BuyXIV = VXV >= VIX;
SellXIV = VXV < VIX;
//BuyVXX = VXV < VIX;
//SellVXX = VXV > VIX;

// Establish the Buy and Sell rules
Buy = BuyXIV;
	Buy = ExRem( BuyXIV, SellXIV ); //This removes all the trade arrows when there is no trade
	BuyPrice = Open * 1.001; //This adds some slippage to factor in not getting exact open price in real world
Sell = SellXIV;
	Sell = ExRem( SellXIV, BuyXIV);  //This removes all the trade arrows when there is no trade
	SellPrice = Open * 1.001;  //This adds some slippage to factor in not getting exact open price in real world
// Set the display paramaters on the chart
PlotShapes(Buy*shapeUpArrow, colorYellow, 0, BuyXIV);
PlotShapes(Sell*shapeDownArrow, colorWhite, 0, SellXIV);

@Jeremy did you try "show arrows for actual trades" ? Right click on your backtest in the analysis window,



1 Like

Thanks @portfoliobuilder. I did, and that works fine. It does not use the colors I specify in my code, but the green and red trade arrows do show.

Perhaps I don’t totally understand how this works, but what I was expecting by having PlotShapes in my code was that when I went to that chart for the ticker the trade arrows would show up automatically, with the colors and style I specified. Is that supposed to happen, or am I missing a step in there? Is my code right?

@Jeremy Try replacing your "Plots" with this and "Apply" after your backtest.

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;

Plot( Close, "Price", colorWhite, styleCandle );
PlotShapes( shape, IIf( Buy, colorYellow, colorWhite ), 0, IIf( Buy, Low, High ) );

 GraphXSpace = 5;


I'm not very knowledgeable about the charting, I just got this from the Plotshapes help file,


1 Like

Hi @Jeremy

Your issue is that you are using BuyXIV and SellXIV as 4th parameter of PlotShapes, which is the vertical positioning for the arrows. As this will be a value of True / 1 at the time of plotting, your arrows will be way off the bottom of the price chart.

Instead, try inserting the chart code below into your formula, which will display the price, and the arrows above or below the High / Low of the bar. It will also correctly position your signals on the action bars, allowing for your trade delays. Then Apply the code to the chart from the AFL Editor.

// Plot price
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) \n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

// Plot arrows
PlotShapes((Ref(Buy, -Status("BuyDelay")) > 0) * shapeUpArrow, colorYellow, 0, L, -12);
PlotShapes((Ref(Sell, -Status("SellDelay")) > 0) * shapeDownArrow, colorWhite, 0, H, -12);



Thank you @HelixTrader and @portfoliobuilder. Both of those worked - I appreciate the help on this. It makes sense know that I know I need to Apply the indicator as well and plot the price.

Thanks again!