How to Backtest using PriceAverageCrossover?


New member

Found PriceAverageCrossover study in TOS but how do i simulate a buy and sell using this strategy? As it is, the Profit and Loss graph is not showing anything.

Am seeing the arrow signal on the chart but hope to improve it further. These are my thoughts.


Previous Open of price must be below moving average and today open is above moving average

Exit Option 1:

Price close below moving average

Exit Option 2:

Price had increase say 30% from entry.

Can anybody help ? Below is the script:

# TD Ameritrade IP Company, Inc. (c) 2009-2020

#wizard input: price
#wizard text: crosses
#wizard input: crossingType
#wizard input: averageType
#wizard text: Inputs: length:
#wizard input: length

input price = close;
input length = 15;
input averageType = AverageType.Simple;
input crossingType = {default above, below};

def avg = MovingAverage(averageType, price, length);

plot signal = crosses(price, avg, crossingType == CrossingType.above);

signal.DefineColor("Above", GetColor(6));
signal.DefineColor("Below", GetColor(7));
signal.AssignValueColor(if crossingType == CrossingType.above then signal.color("Above") else signal.color("Below"));

signal.SetPaintingStrategy(if crossingType == CrossingType.above
    then PaintingStrategy.BOOLEAN_ARROW_UP
    else PaintingStrategy.BOOLEAN_ARROW_DOWN);


Similar threads