EMA crossover strategy is not plotting

A

adw108

New member
VIP
Hello, scripters. I hope you're all well.

I'm hoping to get a little guidance on my first strategy. It's a simple moving-average cross-over strategy.

I mimicked a couple of different things, including the default strategies found in TOS. However, I can't seem to make it trigger any transactions. I figured that I'm missing something obvious and thought I should ask the experts...

I'm working on a simple cross-over strategy. Here's what I've got so far...

Code:
#INPUTS
input price = close;
input tradeSize = 2;
input fastLength = 5;
input slowLength = 12;
input averageType = averageType.EXPONENTIAL;

#def FastMA = MovingAverage(averageType, price, fastLength);
#def SlowMA = MovingAverage(averageType, price, slowLength);

#DEFINITIONS
def buySignal = fastLength crosses above slowLength;
def sellSignal = fastLength crosses below slowLength;
def sellShortSignal = fastLength crosses below slowLength;
def buyToCover = fastLength crosses above slowLength;

#SALES
AddOrder(orderType.BUY_TO_OPEN, buySignal, open[-1], tradeSize, Color.CYAN, Color.CYAN);
AddOrder(orderType.SELL_TO_CLOSE, sellSignal, open[-1], tradeSize, Color.GREEN, Color.GREEN);
AddOrder(orderType.SELL_TO_OPEN, sellShortSignal, open[-1], tradeSize, Color.ORANGE, Color.ORANGE);
AddOrder(orderType.BUY_TO_CLOSE, buyToCover, open[-1], tradeSize, Color.BLUE, Color.BLUE);

#PLOT
plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
FastMA.SetDefaultColor(GetColor(1));
SlowMA.SetDefaultColor(GetColor(2));

I can get the EMAs to plot but I cannot get any sales. Do you think someone can help with this?

Thank you in advance!
 
BenTen

BenTen

Administrative
Staff
VIP
The code was sort of incomplete. Try this:

Code:
#INPUTS
input price = close;
input tradeSize = 2;
input fastLength = 5;
input slowLength = 12;
input averageType = averageType.EXPONENTIAL;

def FastMA = MovingAverage(averageType, price, fastLength);
def SlowMA = MovingAverage(averageType, price, slowLength);

plot mva_1 = FastMa;
plot mva_2 = SlowMa;

#DEFINITIONS
def buySignal = FastMA crosses above SlowMA;
def sellSignal = FastMA crosses below SlowMA;
def sellShortSignal = FastMA crosses below SlowMA;
def buyToCover = FastMA crosses above SlowMA;

#SALES
AddOrder(orderType.BUY_TO_OPEN, buySignal, open[-1], tradeSize, Color.CYAN, Color.CYAN);
AddOrder(orderType.SELL_TO_CLOSE, sellSignal, open[-1], tradeSize, Color.GREEN, Color.GREEN);
AddOrder(orderType.SELL_TO_OPEN, sellShortSignal, open[-1], tradeSize, Color.ORANGE, Color.ORANGE);
AddOrder(orderType.BUY_TO_CLOSE, buyToCover, open[-1], tradeSize, Color.BLUE, Color.BLUE);
 
G

Greenbacks

New member
VIP
@BenTen

I would like to know if someone can help me with the a script to calculate the delta/difference between the 8 and 21 day ema as a lower study ? Any help would be appreciated. Thanks in advance.
 

Similar threads

Top