MTF Script: changing signals via input?

RedToGreen

Active member
I'm not sure if this is possible, I've tried and haven't come up with a solution.

The following code is part of a script I'm working on with MACD

I could...

def Long = Macdfastgreen1

or

def Long = MacdFastGreen1 and MacdSlowup1A

to sum up what I'm trying to figure out, if possible, if you can go into the study settings and apply all the signals I want for a certain aggperiod without going into the actual code and changing things there?

hope that makes sense
Thank you

Code:
input Time1 = {"5 min", "10 min", "15 min", "Hour", "4 Hour", "Daily", default "Weekly", "Monthly"};
input Time2 = {"5 min", "10 min", "15 min", "Hour", "4 Hour", "Daily", default "Weekly", "Monthly"};
input Time3 ={"5 min", "10 min", "15 min", "Hour", "4 Hour", "Daily", default "Weekly", "Monthly"};
#============TIME=========================

def Agg1;

switch (Time1) {
case "5 min":
    Agg1 = AggregationPeriod.FIVE_MIN;
case "10 Min":
    Agg1 = AggregationPeriod.TEN_MIN;
case "15 min":
    Agg1 = AggregationPeriod.FIFTEEN_MIN;
case "Hour":
    Agg1 = AggregationPeriod.HOUR;
case "4 Hour":
    Agg1 = AggregationPeriod.FOUR_HOURS;
case "Daily":
    Agg1 = AggregationPeriod.DAY;
case "Weekly":
    Agg1 = AggregationPeriod.WEEK;
case "Monthly":
    Agg1 = AggregationPeriod.MONTH;
}

def Agg2;

switch (Time2) {
case "5 min":
    Agg2 = AggregationPeriod.FIVE_MIN;
case "10 Min":
    Agg2 = AggregationPeriod.TEN_MIN;
case "15 min":
    Agg2 = AggregationPeriod.FIFTEEN_MIN;
case "Hour":
    Agg2 = AggregationPeriod.HOUR;
case "4 Hour":
    Agg2 = AggregationPeriod.FOUR_HOURS;
case "Daily":
    Agg2 = AggregationPeriod.DAY;
case "Weekly":
    Agg2 = AggregationPeriod.WEEK;
case "Monthly":
    Agg2 = AggregationPeriod.MONTH;
}

input fastLengthMACD = 8;
input slowLengthMACD = 21;
input MACDLength = 5;
input averageTypeMACD = AverageType.WEIGHTED;
input showBreakoutSignals = no;

def FastMacD1 = MovingAverage(averageTypeMACD, close(PERIOD = Agg1), fastLengthMACD) - MovingAverage(averageTypeMACD, close(period = Agg1), slowLengthMACD);
def FastMacD2 = MovingAverage(averageTypeMACD, close(PERIOD = Agg2), fastLengthMACD) - MovingAverage(averageTypeMACD, close(period = Agg2), slowLengthMACD);
def FastMacD3 = MovingAverage(averageTypeMACD, close(PERIOD = Agg3), fastLengthMACD) - MovingAverage(averageTypeMACD, close(period = Agg3), slowLengthMACD);

def SlowMacd1 = MovingAverage(averageTypeMACD, FastMacD1, MACDLength);
def SlowMacd2 = MovingAverage(averageTypeMACD, FastMacD2, MACDLength);
def SlowMacd3 = MovingAverage(averageTypeMACD, FastMacD3, MACDLength);

#def Diff = FastMacD1 - SlowMacd1;

def MacDSlowGreen1 = SlowMacd1 > SlowMacd1[1];
def MacDSlowGreen2 = SlowMacd2 > SlowMacd2[1];
def MacDSlowGreen3 = SlowMacd3 > SlowMacd3[1];

def MacDSlowRed1 = SlowMacd1 < SlowMacd1[1];
def MacDSlowRed2 = SlowMacd2 < SlowMacd2[1];
def MacDSlowRed3 = SlowMacd3 < SlowMacd3[1];

#def MacdFastup1A = FastMacD1[1] > FastMacD1[2];
#def MacdFastup2A = FastMacD2[1] > FastMacD2[2];
#def MacdFastup3A = FastMacD3[1] > FastMacD3[2];

#def MacdFastdn1A = FastMacD1[1] < FastMacD1[2];
#def MacdFastdn2A = FastMacD2[1] < FastMacD2[2];
#def MacdFastdn3A = FastMacD3[1] < FastMacD3[2];
 
Solution
Think I've found a solution

H7k6wUR.png


Code:
input useMacdGreenSignals = yes;
def na = Double.NaN;
def MacDSlowGreen1 = (if usemacdGreenSignals then SlowMacd1 > SlowMacd1[1] and FastMacD1 > FastMacD1[1] else na );

This MTF script contains more than what I posted...

Momentum
Heiken Ashi
RSI
Stochastic
MACD

I'll share once completed
Something like this, except at this point, no matter what I select, its not linked to an actual agg period (Can that be done?)
and what if I want to have multiple signals for a particular agg period

Not sure if this is possible, I'm thinking not but would make things easier

sKPFi88.png
 
Think I've found a solution

H7k6wUR.png


Code:
input useMacdGreenSignals = yes;
def na = Double.NaN;
def MacDSlowGreen1 = (if usemacdGreenSignals then SlowMacd1 > SlowMacd1[1] and FastMacD1 > FastMacD1[1] else na );

This MTF script contains more than what I posted...

Momentum
Heiken Ashi
RSI
Stochastic
MACD

I'll share once completed
 
Solution
Ok, I've run into a roadblock

I've inputted everything for all the signals for all timeframes.

The following code works, but I still need to have both inputs checked "yes"

What if I want to check yes on numerous inputs, do I need to change the code each time to also reflect those inputs?

To summarize, I was hoping I could change the signals I want via the study settings and not have to change the code as well.

I know the code pasted here, is going to do exactly what it says, if those inputs are "yes" and If I select another input thats not listed in assignpricecolor....it will have no bearing.
Not sure if there's a certain format to use or not to accomplish this.

Code:
assignPriceColor(if macdfastGreen1 and macdfastAbove01 then createColor(24,76,107) else if macdfastRed1 and macdfastbelow01 then color.DARK_ORANGE else color.current);


EU9cvuy.png
 
Last edited:

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

Thread starter Similar threads Forum Replies Date
F How to make an MTF version of a custom script? Questions 4
B MTF Stochastic Questions 1
E MTF Stacked Moving Averages Questions 3
M MTF AMA Questions 2
C MTF EMA cloud Questions 1

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
442 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