|
Ted Penner
2016-01-24 09:36:37
|
|
I need to convert this into code for quantshare. Any assistance is greatly appreciated.
declare Once_Per_Bar;
# EMACross
input price = close;
input fastLength = 20;
input slowLength = 50;
input averageType = AverageType.EXPONENTIAL;
plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
FastMA.SetDefaultColor(GetColor(1));
SlowMA.SetDefaultColor(GetColor(2));
# ADX Strategy conversion -> Replace 'plot' with 'def', add the line below it, then comment out the GetColor line.
input length = 14;
input ADXaverageType = AverageType.WILDERS;
def ADX = DMI(length, ADXaverageType).ADX;
def ADXCheck = ADX > 20; # Create a filter using the variable we just defined.
#ADX.SetDefaultColor(GetColor(5));
# MACDHistogram Strategy conversion -> Replace 'plot' with 'def' add the line below it, then comment out the lines that begin with 'Diff'.
#plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
input MACDfastLength = 12;
input MACDslowLength = 26;
input MACDLength = 9;
input MACDaverageType = AverageType.EXPONENTIAL;
Def Diff = MACD(MACDfastLength, MACDslowLength, MACDLength, MACDaverageType).Diff;
def filterLongMACD = Diff > 0;
def filterShortMACD = Diff < 0;
#Diff.SetDefaultColor(GetColor(5));
#Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Diff.SetLineWeight(3);
#Diff.DefineColor("Positive and Up", Color.GREEN);
#Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
#Diff.DefineColor("Negative and Down", Color.RED);
#Diff.DefineColor("Negative and Up", Color.DARK_RED);
#Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up") else Diff.Color("Positive and Down") else if Diff < Diff[1] then Diff.Color("Negative and Down") else Diff.Color("Negative and Up"));
# ORDER CONDITIONS
AddOrder(OrderType.BUY_TO_OPEN, FastMA crosses above SlowMA and ADXCheck is true and filterLongMACD is true, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "LE");
AddOrder(OrderType.SELL_TO_CLOSE, FastMA crosses below SlowMA, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "LX");
|
|