Reduce complexity of code


0
0

Hi,

I like to add aggregation period 1 hour to the 1st clause of the code below for a study alert in one sentence. I want the aggregation period of the 1st clause to be set at 1 hour, while the 2nd clause is set to the primary period (ie, 5min), which I can choose from thinkorswim. Is it possible?

—-
MACD(“fast length” = 20, “slow length” = 40, “macd length” = 30).”Diff” is greater than 0 AND
MACDHistogramCrossover(“fast length” = 30, “slow length” = 90, “macd length” = 80, “crossing type” = “negative to positive”)
—–

i can make the code more detail like below but it’s too long and cumbersome for study alerts.

input fastLength = 20;
input slowLength = 40;
input MACDLength = 30;
input averageType = AverageType.EXPONENTIAL;
input TimeFrame = AggregationPeriod.hour;

def Value = MovingAverage(averageType, close(period = TimeFrame), fastLength) – MovingAverage(averageType, close(period = TimeFrame), slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

def Diff = Value – Avg;

plot UP = diff >0 and  MACDHistogramCrossover(“fast length” = 30, “slow length” = 90, “macd length” = 80, “crossing type” = “negative to positive”);

thanks.

Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on March 30, 2020 11:18 pm
93 views
0
Private answer

Sorry but the answer is no. What you have there is already the least complex form.

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on March 31, 2020 7:08 am