Hello,
I am trying to create system that rotate tickers based on percent rank of other ticker.
This is my basic code:
SetOption("InitialEquity",10000);
SetOption("InterestRate",0);
SetOption("MaxOpenPositions",1);
SetOption("UsePrevBarEquityForPosSizing",True);
SetOption("AllowPositionShrinking", True);
SetOption("accountmargin",100);
SetForeign("$VIX");
VIXRank=PercentRank(C,252);
Plot( VIXRank, "VIXRank", colorRed );
RestorePriceArrays();
Buy=Sell=0;
if(Name() == "SPY")
{
IIf ((VIXRank>30 AND VIXRank<70), Buy=True, Sell=True);
}
if(Name() == "TLT")
{
IIf ((VIXRank>70), Buy=True, Sell=True);
}
BuyPrice=Close;
SellPrice=Close;
Filter = 1; // show all bars
AddColumn( C, "Close" );
AddColumn( VIXRank, "VIXRank", 1.0 );
AddColumn( Buy, "Buy", 1.0, colorBlack );
AddColumn( Sell, "Sell", 1.0, colorBlack );
SPY should be bought if VIXRank is between 30 and 70.
But it is not working - I can see Buy and Sell signal all the time:
Can you help me were is my mistake?
Thank you.