Love Amibroker and slowly learning how to program (very little experience with this). I am currently working on some code to buy either XIV or VXX. Here are the rules I want to backtest:
Buy XIV if $VXV >= $VIX
Buy VXX if $VXV < $VIX
Right now I am able to make it work so I can buy and sell XIV, but I am trying to get the second rule to work so that I sell XIV and buy VXX when the signal says to, and visa versa as per the rules. I am running this with a watchlist set up with just XIV - I can add one with XIV and VXX as well of course.
Here is the code I have started with - are you able to help me with how to make this work for the rule as stated above?:
//Buy XIV if $VXV >= $VIX
//Buy VXX if $VXV < $VIX
#include_once "Formulas\Norgate Data\Norgate Data Functions.afl"
// 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);
SetTradeDelays(1,1,1,1);
BuyPrice = Open;
SellPrice = Open;
VXV = Foreign( "$VXV", "C" );
VIX = Foreign( "$VIX", "C" );
XIV = Foreign( "XIV", "C" );
VXX = Foreign( "VXX", "C" );
BuyXIV = VXV >= VIX;
SellXIV = VXV < VIX;
//BuyVXX = VXV < VIX;
//SellVXX = VXV > VIX;
Buy = BuyXIV;
Sell = SellXIV;