Thank you very much for any assistance you guys can provide.
Code: Select all
#RULES
#Buy to Open should occur when The fastLength MA crosses above the slowLength MA as shown
#AND #The ADX is over 20
#AND the MACDHistogram is above 0.
#Sell to Exit should ONLY occur when the MACDHistogram is below 0.
#Built-In Moving Average Cross Strategy
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 Study
#To convert this to a Strategy, 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 filterLongADX = ADX > 20; #Create a filter using the variable we just defined.
#ADX.SetDefaultColor(GetColor(5));
#MACDHistogram
#To convert this to a Strategy, 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"));
#Moved the AddOrder syntax below so that it appears below the MACross, ADX and MACDCross inputs, plots, and definitions.
AddOrder(OrderType.BUY_TO_OPEN, FastMA crosses above SlowMA and filterLongADX is true and filterLongMACD is true, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "LE");
AddOrder(OrderType.SELL_TO_CLOSE, filterShortMACD is true, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "LX");