MACCcrossOver_w_Alerts from indicator to strategy

Jesus Bueno

New member
Hi Ben. This indicator is called MACCcrossOver_w_Alerts. Is it possible to turn it into a strategy? How much does the job cost? Thanks for everything. Happy Days. Jesus

Code:
input EMAPeriod = 10;

input SMAPeriod = 20;

input price = close;

def na = double.nan;

plot fastema = ExpAverage(price, EMAPeriod);

plot slowema = Average(price, SMAPeriod);

def crossover = if fastema > slowema AND fastema[1] <= slowema[1] then 1 else 0;

def crossunder = if fastema < slowema AND fastema[1] >= slowema[1] then 1 else 0;

#Plot arrows

Plot up = if crossover then low - tickSize() else na;

Plot down = if crossunder then high + tickSize() else na;

up.SetPaintingStrategy(paintingStrategy.ARROW_UP);

down.SetPaintingStrategy(paintingStrategy.ARROW_DOWN);

#Trigger alerts

alert(crossover[1], "Crossover", Alert.Bar, Sound.Ding);

alert(crossunder[1], "Crossunder", Alert.Bar, Sound.Ding);
 

BenTen

Administrative
Staff
VIP
This will produce the backtesting strategy for you:

Code:
AddOrder(OrderType.BUY_TO_OPEN, condition = up, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long");
AddOrder(OrderType.SELL_TO_CLOSE, condition = down, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Cover");

The snippet above is basic buy when there is an up arrow and sell when there is a down arrow. You need to switch the buy/sell condition to create a short strategy for the indicator.
 

Similar threads

Top