Adding Input for Average Type

Ricky_005

New member
I've added a Input for Average Type for the PPO MacD created by North Vanhooser. The issue is when set to Exponential it's no where near matching the signal of Exponential comparing it to the standard TOS MacD study, MacD line, Signal line and Historgram is way off. Change it to Simple MA its a match. o_O Anyhow was hoping someone could help me out to get the problem solved.


Code:
# PPO - North Vanhooser 
declare lower;

input fastPeriod   = 12;
input slowPeriod   = 26;
input signalPeriod = 9;
input price        = close;

input avgType = {
    default EXPONENTIAL,
    SIMPLE,
    WEIGHTED,
    WILDERS,
    HULL
};

input histoColorStyle = {
    default Original,
    Green_Red,
    Cyan_Blue
};

def fastMA   = MovingAverage(avgType, price, fastPeriod);
def slowMA   = MovingAverage(avgType, price, slowPeriod);
def periodOK = fastPeriod < slowPeriod;

AddLabel(!periodOK, "ERROR: fastPeriod MUST be less than slowPeriod", Color.YELLOW);

def ppo      = if periodOK then ((fastMA - slowMA) / slowMA) * 100 else Double.NaN;
def signal   = MovingAverage(avgType, ppo, signalPeriod);
def histo    = ppo - signal;

plot PpoLine     = ppo;
PpoLine.SetDefaultColor(Color.BLUE);
PpoLine.HideBubble();

plot SignalLine  = signal;
SignalLine.SetDefaultColor(Color.CYAN);
SignalLine.HideBubble();

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.BLACK);
ZeroLine.HideBubble();

plot HistoPlot = histo;
HistoPlot.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
HistoPlot.SetLineWeight(3);

# === Slope Detection
def isUp   = histo > histo[1];
def isDown = histo < histo[1];

# === Define color index for styles
def colorIndex =
    if histoColorStyle == histoColorStyle.Original then
        if isUp then 1
        else if isDown then 2
        else 3
    else if histoColorStyle == histoColorStyle.Green_Red then
        if isUp and histo > 0 then 4          # Green
        else if isDown and histo > 0 then 5   # Dark Green
        else if isDown and histo < 0 then 6   # Red
        else if isUp and histo < 0 then 7     # Dark Red
        else 3
    else if histoColorStyle == histoColorStyle.Cyan_Blue then
        if isUp then 8
        else if isDown then 9
        else 3
    else 3;

# === Assign color once
HistoPlot.AssignValueColor(
    if colorIndex == 1 then Color.UPTICK
    else if colorIndex == 2 then Color.DOWNTICK
    else if colorIndex == 3 then Color.GRAY
    else if colorIndex == 4 then Color.GREEN
    else if colorIndex == 5 then Color.DARK_GREEN
    else if colorIndex == 6 then Color.RED
    else if colorIndex == 7 then Color.DARK_RED
    else if colorIndex == 8 then Color.CYAN
    else if colorIndex == 9 then Color.BLUE
    else Color.LIGHT_GRAY
);
 
Solution
The issue may have something to do with the order of the average types.
This is the order in the tos MACD study:

1754011448185.png


Changing your code to the following and the issue was resolved:
Code:
input avgType = {
    SIMPLE,
    default EXPONENTIAL,
    WEIGHTED,
    WILDERS,
    HULL
};
The issue may have something to do with the order of the average types.
This is the order in the tos MACD study:

1754011448185.png


Changing your code to the following and the issue was resolved:
Code:
input avgType = {
    SIMPLE,
    default EXPONENTIAL,
    WEIGHTED,
    WILDERS,
    HULL
};
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Im posting from my phone at the moment, but I believe you can just assign the input directly to an average type constant. Which ever one you pick will serve as the default, and the others will auto populate in the indicator's settings. Recreating the enumerated variable yourself is not necessary in these cases. It should work for all enumerated constants with the exception of, I believe, the color constants.
 
I've added a Input for Average Type for the PPO MacD created by North Vanhooser. The issue is when set to Exponential it's no where near matching the signal of Exponential comparing it to the standard TOS MacD study, MacD line, Signal line and Historgram is way off. Change it to Simple MA its a match. o_O Anyhow was hoping someone could help me out to get the problem solved.


Code:
# PPO - North Vanhooser
declare lower;

input fastPeriod   = 12;
input slowPeriod   = 26;
input signalPeriod = 9;
input price        = close;

input avgType = {
    default EXPONENTIAL,
    SIMPLE,
    WEIGHTED,
    WILDERS,
    HULL
};

input histoColorStyle = {
    default Original,
    Green_Red,
    Cyan_Blue
};

def fastMA   = MovingAverage(avgType, price, fastPeriod);
def slowMA   = MovingAverage(avgType, price, slowPeriod);
def periodOK = fastPeriod < slowPeriod;

AddLabel(!periodOK, "ERROR: fastPeriod MUST be less than slowPeriod", Color.YELLOW);

def ppo      = if periodOK then ((fastMA - slowMA) / slowMA) * 100 else Double.NaN;
def signal   = MovingAverage(avgType, ppo, signalPeriod);
def histo    = ppo - signal;

plot PpoLine     = ppo;
PpoLine.SetDefaultColor(Color.BLUE);
PpoLine.HideBubble();

plot SignalLine  = signal;
SignalLine.SetDefaultColor(Color.CYAN);
SignalLine.HideBubble();

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.BLACK);
ZeroLine.HideBubble();

plot HistoPlot = histo;
HistoPlot.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
HistoPlot.SetLineWeight(3);

# === Slope Detection
def isUp   = histo > histo[1];
def isDown = histo < histo[1];

# === Define color index for styles
def colorIndex =
    if histoColorStyle == histoColorStyle.Original then
        if isUp then 1
        else if isDown then 2
        else 3
    else if histoColorStyle == histoColorStyle.Green_Red then
        if isUp and histo > 0 then 4          # Green
        else if isDown and histo > 0 then 5   # Dark Green
        else if isDown and histo < 0 then 6   # Red
        else if isUp and histo < 0 then 7     # Dark Red
        else 3
    else if histoColorStyle == histoColorStyle.Cyan_Blue then
        if isUp then 8
        else if isDown then 9
        else 3
    else 3;

# === Assign color once
HistoPlot.AssignValueColor(
    if colorIndex == 1 then Color.UPTICK
    else if colorIndex == 2 then Color.DOWNTICK
    else if colorIndex == 3 then Color.GRAY
    else if colorIndex == 4 then Color.GREEN
    else if colorIndex == 5 then Color.DARK_GREEN
    else if colorIndex == 6 then Color.RED
    else if colorIndex == 7 then Color.DARK_RED
    else if colorIndex == 8 then Color.CYAN
    else if colorIndex == 9 then Color.BLUE
    else Color.LIGHT_GRAY
);

i suspect this line
def ppo = if periodOK then ((fastMA - slowMA) / slowMA) * 100 else Double.NaN;

turn off extended hours and see how it compares
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
337 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top