Aggregation/ multi time frame signal

Igor

New member
VIP
Good afternoon everyone!!! I’m looking to find out a way to be able to plot a signal, like arrow on from 1 min and 3min and 5min, bluish or bearish. From crossing SMI and avgSMI. For example if the SMI and AvgSMI is crossed on all those three time frames when bullish if not when bearish. Please let me know if you have any ideas on how to do it. Thank you!!!!
 
Solution
Good afternoon everyone!!! I’m looking to find out a way to be able to plot a signal, like arrow on from 1 min and 3min and 5min, bluish or bearish. From crossing SMI and avgSMI. For example if the SMI and AvgSMI is crossed on all those three time frames when bullish if not when bearish. Please let me know if you have any ideas on how to do it. Thank you!!!!

Here is one way with dots.

Since your request is using multiple timeframes, this will only work on a 1min chart and the indicator repaints the colored dots in the code below before the higher timeframes close. This can cause false readings.

The dots for each timeframe will when a bullish cross occurs, will color green and remain green until a bearish cross...
Good afternoon everyone!!! I’m looking to find out a way to be able to plot a signal, like arrow on from 1 min and 3min and 5min, bluish or bearish. From crossing SMI and avgSMI. For example if the SMI and AvgSMI is crossed on all those three time frames when bullish if not when bearish. Please let me know if you have any ideas on how to do it. Thank you!!!!

Here is one way with dots.

Since your request is using multiple timeframes, this will only work on a 1min chart and the indicator repaints the colored dots in the code below before the higher timeframes close. This can cause false readings.

The dots for each timeframe will when a bullish cross occurs, will color green and remain green until a bearish cross occurs, where the dots will color red and remain red until the next bullish cross.

The 'Sum" will have the same coloring scheme of green/red, but will only change colors when all 3 timeframess are in alignment and will remain the color at alignment until all timeframes are in the opposite alignment.

Capture.jpg
Ruby:
declare lower;
script smi {
    input agg = AggregationPeriod.MIN;

    input over_bought = 40.0;
    input over_sold = -40.0;
    input percentDLength = 3;
    input percentKLength = 5;

    def min_low = Lowest(low(period = agg), percentKLength);
    def max_high = Highest(high(period = agg), percentKLength);
    def rel_diff = close(period = agg) - (max_high + min_low) / 2;
    def diff = max_high - min_low;

    def avgrel = ExpAverage(ExpAverage(rel_diff, percentDLength), percentDLength);
    def avgdiff = ExpAverage(ExpAverage(diff, percentDLength), percentDLength);


    plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
    plot AvgSMI = ExpAverage(SMI, percentDLength);

    def overbought = over_bought;
    def oversold = over_sold;

}

def smi1 = if smi() crosses above smi().AvgSMI
           then 1
           else if smi() crosses below smi().AvgSMI
           then -1 else smi1[1];
plot s1  = if IsNaN(close) then Double.NaN else if smi1 then 1 else 1;
s1.SetPaintingStrategy(PaintingStrategy.POINTS);
s1.SetLineWeight(5);
s1.AssignValueColor(if smi1 == 1 then Color.GREEN else if smi1 == -1 then Color.RED else Color.GRAY);
s1.hidebubble();

def smi2 = if smi(agg = "THREE_MIN") crosses above smi(agg = "THREE_MIN").AvgSMI
           then 1
           else if smi(agg = "THREE_MIN") crosses below smi(agg = "THREE_MIN").AvgSMI
           then -1 else smi2[1];
plot s2  = if IsNaN(close) then Double.NaN else if smi2 then 2 else 2;
s2.SetPaintingStrategy(PaintingStrategy.POINTS);
s2.SetLineWeight(5);
s2.AssignValueColor(if smi2 == 1 then Color.GREEN else if smi2 == -1 then Color.RED else Color.GRAY);
s2.hidebubble();

def smi3 = if smi(agg = "FIVE_MIN") crosses above smi(agg = "FIVE_MIN").AvgSMI
           then 1
           else if smi(agg = "FIVE_MIN") crosses below smi(agg = "FIVE_MIN").AvgSMI
           then -1 else smi1[1];
plot s3 = if IsNaN(close) then Double.NaN else if smi3 then 3 else 3;
s3.SetPaintingStrategy(PaintingStrategy.POINTS);
s3.SetLineWeight(5);
s3.AssignValueColor(if smi3 == 1 then Color.GREEN else if smi3 == -1 then Color.RED else Color.GRAY);
s3.hidebubble();

def sum = if smi1 == 1 and smi2 == 1 and smi3 == 1
          then 1
          else if smi1 == -1 and smi2 == -1 and smi3 == -1
          then -1 else sum[1];

plot line1 = if IsNaN(close) then Double.NaN else 4;
line1.SetPaintingStrategy(PaintingStrategy.DASHES);
line1.SetDefaultColor(Color.WHITE);
line1.HideBubble();

plot sum1 = if IsNaN(close) then Double.NaN else if sum then 5 else 5;
sum1.SetPaintingStrategy(PaintingStrategy.POINTS);
sum1.SetLineWeight(5);
sum1.AssignValueColor(if sum == 1 then Color.GREEN else if sum == -1 then Color.RED else Color.GRAY);
sum1.hidebubble();

plot top = if IsNaN(close) then Double.NaN else 6;
top.SetPaintingStrategy(PaintingStrategy.DASHES);
top.SetDefaultColor(Color.BLACK);
top.HideBubble();

plot bottom = if IsNaN(close) then Double.NaN else 0;
bottom.SetPaintingStrategy(PaintingStrategy.DASHES);
bottom.SetDefaultColor(Color.BLACK);
bottom.HideBubble();

input showbubbles = yes;
input bubblemover = 3;
def bm = bubblemover;
def bm1 = bm + 1;
AddChartBubble(showbubbles and !IsNaN(close[bm1]) and IsNaN(close[bm]), s1[bm1], 1, Color.WHITE);
AddChartBubble(showbubbles and !IsNaN(close[bm1]) and IsNaN(close[bm]), s2[bm1], 3, Color.WHITE);
AddChartBubble(showbubbles and !IsNaN(close[bm1]) and IsNaN(close[bm]), s3[bm1], 5, Color.WHITE);
AddChartBubble(showbubbles and !IsNaN(close[bm1]) and IsNaN(close[bm]), sum1[bm1], "Sum", Color.WHITE);
 
Solution
@sonnytrader

This was a specific request. It only works on a 1min chart timeframe setting. See this note from above:

Since your request is using multiple timeframes, this will only work on a 1min chart and the indicator repaints the colored dots in the code below before the higher timeframes close. This can cause false readings.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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