buywall
New member
Hi all,
I'm trying to write a stategy backtest for ema crossovers and I'm using a couple of videos as reference (the attached code is just adjustments of what I'm finding). Right now, I'm just trying to solve a problem where the entry isn't being done where the cross happens, but instead a bar, or a few bars later. I'm at a loss trying to solve this simple thing.
Any ideas?
Thank you -
Code:
I'm trying to write a stategy backtest for ema crossovers and I'm using a couple of videos as reference (the attached code is just adjustments of what I'm finding). Right now, I'm just trying to solve a problem where the entry isn't being done where the cross happens, but instead a bar, or a few bars later. I'm at a loss trying to solve this simple thing.
Any ideas?
Thank you -
Code:
Code:
input price = close;
input fastMALength = 10;
input slowMALength = 20;
input averageTypeFast = AverageType.EXPONENTIAL;
input averageTypeSlow = AverageType.EXPONENTIAL;
input quantity = 100;
plot fastMA = MovingAverage(averageTypeFast, close, fastMALength);
plot slowMA = MovingAverage(averageTypeSlow, close, slowMALength);
AddOrder(OrderType.BUY_TO_OPEN, fastMA crosses above slowMA, close, quantity, name="open");
AddOrder(OrderType.SELL_TO_CLOSE, price crosses below fastMA, price, quantity, tickcolor = Color.ORANGE, arrowcolor = Color.ORANGE,name="close");