MTF Script: changing signals via input?

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:

Similar threads

Top