Repaints Better Sine Waves For ThinkOrSwim

Repaints

Nomak

Member
2019 Donor
I was able to find this in my studies collection. I do like the bettersinewaves, I always think it can be improved upon.


BetterSineWaves

Code:
# TS_SineWaveCycles
# http://www.thinkscripter.com
# [email protected]
# Last Update 17 Apr 2010

input SineWaveLength = 25;

def MesaSW = MESASineWave(length = SineWaveLength)."Sine Wave";
def MesaLW = MESASineWave(length = SineWaveLength)."Lead Wave";

def trendChangeUp = if(MesaSW < MesaLW and MesaSW[1]>=MesaLW[1], 1, 0);
def trendChangeDown = if(MesaSW > MesaLW and MesaSW[1]<=MesaLW[1], 1, 0);

def thirBarClosed = if !isNan(close[-2]) then 1 else 0;

def lowPoint = if !isNan(close[-2]) then min(min(min(min(low[1],low),low[-1]),low[2]),low[-2]) else if !isNan(close[-1]) then min(min(min(low[1],low),low[-1]),low[2]) else min(min(low[1],low),low[2]);

def highPoint = if !isNan(close[-2]) then max(max(max(max(high[1],high),high[-1]),high[2]),high[-2]) else if !isNan(close[-1]) then max(max(max(high[1],high),high[-1]),high[2]) else max(max(high[1],high),high[2]);

rec support = compoundValue(1,if trendChangeUp then lowPoint else if trendChangeDown then double.nan else support[1], high);
rec resistance = compoundValue (1, if trendChangeDown then highPoint else if trendChangeUp then double.nan else resistance[1],low);

plot supportLevel = support;
supportLevel.setDefaultColor(color.red);
supportLevel.SetStyle(curve.POINTS);
supportLevel.SetLineWeight(3);

plot resistanceLevel = resistance;
resistanceLevel.setDefaultColor(color.white);
resistanceLevel.SetStyle(curve.POINTS);
resistanceLevel.SetLineWeight(3);
 
Last edited by a moderator:

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

Is it possible to convert this to a multiple time frame indicator? I made a run at it but couldn't get it to work. It's a fantastic indicator and I'd like to apply it on a longer time frame to various charts.

https://usethinkscript.com/threads/better-sine-waves-for-thinkorswim.11257/

This is what the existing code looks like on a 1 minute chart of AAPL:

eI4TSty.png


Code:
# Last Update 17 Apr 2010

input SineWaveLength = 25;

def MesaSW = MESASineWave(length = SineWaveLength)."Sine Wave";
def MesaLW = MESASineWave(length = SineWaveLength)."Lead Wave";

def trendChangeUp = if(MesaSW < MesaLW and MesaSW[1]>=MesaLW[1], 1, 0);
def trendChangeDown = if(MesaSW > MesaLW and MesaSW[1]<=MesaLW[1], 1, 0);

def thirBarClosed = if !isNan(close[-2]) then 1 else 0;

def lowPoint = if !isNan(close[-2]) then min(min(min(min(low[1],low),low[-1]),low[2]),low[-2]) else if !isNan(close[-1]) then min(min(min(low[1],low),low[-1]),low[2]) else min(min(low[1],low),low[2]);

def highPoint = if !isNan(close[-2]) then max(max(max(max(high[1],high),high[-1]),high[2]),high[-2]) else if !isNan(close[-1]) then max(max(max(high[1],high),high[-1]),high[2]) else max(max(high[1],high),high[2]);

rec support = compoundValue(1,if trendChangeUp then lowPoint else if trendChangeDown then double.nan else support[1], high);
rec resistance = compoundValue (1, if trendChangeDown then highPoint else if trendChangeUp then double.nan else resistance[1],low);

plot supportLevel = support;
supportLevel.setDefaultColor(color.red);
supportLevel.SetStyle(curve.POINTS);
supportLevel.SetLineWeight(3);

plot resistanceLevel = resistance;
resistanceLevel.setDefaultColor(color.white);
resistanceLevel.SetStyle(curve.POINTS);
resistanceLevel.SetLineWeight(3);
 
Last edited:
@autoloader : Try this...

Code:
input bsw_tf = {"MIN", default "FIVE_MIN", "TEN_MIN", "FIFTEEN_MIN", "THIRTY_MIN", "HOUR", "TWO_HOURS", "FOUR_HOURS", "DAY", "WEEK", "MONTH"};

def timeframe;

switch (bsw_tf){
case "MIN":
    timeframe = AggregationPeriod.MIN;
case "FIVE_MIN":
    timeframe = AggregationPeriod.FIVE_MIN;
case "TEN_MIN":
    timeframe = AggregationPeriod.TEN_MIN;
case "FIFTEEN_MIN":
    timeframe = AggregationPeriod.FIFTEEN_MIN;
case "THIRTY_MIN":
    timeframe = AggregationPeriod.THIRTY_MIN;
case "HOUR":
    timeframe = AggregationPeriod.HOUR;
case "TWO_HOURS":
    timeframe = AggregationPeriod.TWO_HOURS;
case "FOUR_HOURS":
    timeframe = AggregationPeriod.FOUR_HOURS;
case "DAY":
    timeframe = AggregationPeriod.DAY;
case "WEEK":
    timeframe = AggregationPeriod.WEEK;
case "MONTH":
    timeframe = AggregationPeriod.MONTH;
}

input SineWaveLength = 25;

def MesaSW = MESASineWave(length = SineWaveLength)."Sine Wave";
def MesaLW = MESASineWave(length = SineWaveLength)."Lead Wave";

def trendChangeUp = If(MesaSW < MesaLW and MesaSW[1] >= MesaLW[1], 1, 0);
def trendChangeDown = If(MesaSW > MesaLW and MesaSW[1] <= MesaLW[1], 1, 0);

def thirBarClosed = if !IsNaN(close(period = timeframe)[-2]) then 1 else 0;

def lowPoint = if !IsNaN(close(period = timeframe)[-2]) then Min(Min(Min(Min(low(period = timeframe)[1], low(period = timeframe)), low(period = timeframe)[-1]), low(period = timeframe)[2]), low(period = timeframe)[-2]) else if !IsNaN(close(period = timeframe)[-1]) then Min(Min(Min(low(period = timeframe)[1], low(period = timeframe)), low(period = timeframe)[-1]), low(period = timeframe)[2]) else Min(Min(low(period = timeframe)[1], low(period = timeframe)), low(period = timeframe)[2]);

def highPoint = if !IsNaN(close(period = timeframe)[-2]) then Max(Max(Max(Max(high(period = timeframe)[1], high(period = timeframe)), high(period = timeframe)[-1]), high(period = timeframe)[2]), high(period = timeframe)[-2]) else if !IsNaN(close(period = timeframe)[-1]) then Max(Max(Max(high(period = timeframe)[1], high(period = timeframe)), high(period = timeframe)[-1]), high(period = timeframe)[2]) else Max(Max(high(period = timeframe)[1], high(period = timeframe)), high(period = timeframe)[2]);

rec support = CompoundValue(1, if trendChangeUp then lowPoint else if trendChangeDown then Double.NaN else support[1], high(period = timeframe));
rec resistance = CompoundValue (1, if trendChangeDown then highPoint else if trendChangeUp then Double.NaN else resistance[1], low(period = timeframe));

plot supportLevel = support;
supportLevel.SetDefaultColor(Color.RED);
supportLevel.SetStyle(Curve.POINTS);
supportLevel.SetLineWeight(3);

plot resistanceLevel = resistance;
resistanceLevel.SetDefaultColor(Color.WHITE);
resistanceLevel.SetStyle(Curve.POINTS);
resistanceLevel.SetLineWeight(3);


1-Minute Chart with MTF set to 1-Minute

202302020303-bsw-test.png



30-Minute Chart with MTF set to 1 Day

202302020307-bsw-test2.png



Daily Chart with MTF set to Weekly


202302020319-bsw-test3.png
 
Last edited:
@autoloader : Try this...

Code:
input bsw_tf = {"MIN", default "FIVE_MIN", "TEN_MIN", "FIFTEEN_MIN", "THIRTY_MIN", "HOUR", "TWO_HOURS", "FOUR_HOURS", "DAY", "WEEK", "MONTH"};

def timeframe;

switch (bsw_tf){
case "MIN":
    timeframe = AggregationPeriod.MIN;
case "FIVE_MIN":
    timeframe = AggregationPeriod.FIVE_MIN;
case "TEN_MIN":
    timeframe = AggregationPeriod.TEN_MIN;
case "FIFTEEN_MIN":
    timeframe = AggregationPeriod.FIFTEEN_MIN;
case "THIRTY_MIN":
    timeframe = AggregationPeriod.THIRTY_MIN;
case "HOUR":
    timeframe = AggregationPeriod.HOUR;
case "TWO_HOURS":
    timeframe = AggregationPeriod.TWO_HOURS;
case "FOUR_HOURS":
    timeframe = AggregationPeriod.FOUR_HOURS;
case "DAY":
    timeframe = AggregationPeriod.DAY;
case "WEEK":
    timeframe = AggregationPeriod.WEEK;
case "MONTH":
    timeframe = AggregationPeriod.MONTH;
}

input SineWaveLength = 25;

def MesaSW = MESASineWave(length = SineWaveLength)."Sine Wave";
def MesaLW = MESASineWave(length = SineWaveLength)."Lead Wave";

def trendChangeUp = If(MesaSW < MesaLW and MesaSW[1] >= MesaLW[1], 1, 0);
def trendChangeDown = If(MesaSW > MesaLW and MesaSW[1] <= MesaLW[1], 1, 0);

def thirBarClosed = if !IsNaN(close(period = timeframe)[-2]) then 1 else 0;

def lowPoint = if !IsNaN(close(period = timeframe)[-2]) then Min(Min(Min(Min(low(period = timeframe)[1], low(period = timeframe)), low(period = timeframe)[-1]), low(period = timeframe)[2]), low(period = timeframe)[-2]) else if !IsNaN(close(period = timeframe)[-1]) then Min(Min(Min(low(period = timeframe)[1], low(period = timeframe)), low(period = timeframe)[-1]), low(period = timeframe)[2]) else Min(Min(low(period = timeframe)[1], low(period = timeframe)), low(period = timeframe)[2]);

def highPoint = if !IsNaN(close(period = timeframe)[-2]) then Max(Max(Max(Max(high(period = timeframe)[1], high(period = timeframe)), high(period = timeframe)[-1]), high(period = timeframe)[2]), high(period = timeframe)[-2]) else if !IsNaN(close(period = timeframe)[-1]) then Max(Max(Max(high(period = timeframe)[1], high(period = timeframe)), high(period = timeframe)[-1]), high(period = timeframe)[2]) else Max(Max(high(period = timeframe)[1], high(period = timeframe)), high(period = timeframe)[2]);

rec support = CompoundValue(1, if trendChangeUp then lowPoint else if trendChangeDown then Double.NaN else support[1], high(period = timeframe));
rec resistance = CompoundValue (1, if trendChangeDown then highPoint else if trendChangeUp then Double.NaN else resistance[1], low(period = timeframe));

plot supportLevel = support;
supportLevel.SetDefaultColor(Color.RED);
supportLevel.SetStyle(Curve.POINTS);
supportLevel.SetLineWeight(3);

plot resistanceLevel = resistance;
resistanceLevel.SetDefaultColor(Color.WHITE);
resistanceLevel.SetStyle(Curve.POINTS);
resistanceLevel.SetLineWeight(3);


1-Minute Chart with MTF set to 1-Minute

202302020303-bsw-test.png



30-Minute Chart with MTF set to 1 Day

202302020307-bsw-test2.png



Daily Chart with MTF set to Weekly


202302020319-bsw-test3.png
Awesome! Thank you, netarchitech. I will check it out.
 
I am curious how others use this indicator. I been using it for a couple years before I move onto intraday VPOC.
 
I am curious how others use this indicator. I been using it for a couple years before I move onto intraday VPOC.
I use it for support and resistance. By the way, when the support or resistance fail, there is usually a strong run in the direction of the failure, e.g., failed resistance often leads to a strong rally and failed support often leads to a strong selloff.

Thank you very much for posting this indicator. I know it's the same as the MESA sine wave but, in this form, it's much easier to read and for that reason is much more useful, in my opinion.
 
WARNING: The above indicator is not pinpointing the turning point in realtime, but looking ahead into the future by 2 bars ... So, it ends up redrawing the previous 2 bars based on what follows them.
 
WARNING: The above indicator is not pinpointing the turning point in realtime, but looking ahead into the future by 2 bars ... So, it ends up redrawing the previous 2 bars based on what follows them.
The indicator might adjust on the first two candles but it remains fixed wherever it is after that. That doesn't really strike me as quite the same thing as repainting.

Also, look at the indicator in the charts posted above. Are any of the levels two dots or less? This isn't an indicator that's going to throw up a neon arrow saying ”BUY!” or “SELL!” It gives an idea of where there may be support or resistance and often does a really good job of that. When one of those levels fails, the security often makes a strong run in the direction of the failure. And failed resistance becomes support; failed support becomes resistance.
 
I use this on ES and SPY. I have a quad chart grid with 1, 2, 3, and 5 minute charts for the ES and SPY. Why? Because some days this indicator works best on a particular time. Some days it draws the most accurate levels on the 2 or 3 minute instead of the one minute. I think that's really related to the cycle number on the indicator which is set by default to 25. I don't know of a way to test for the correct cycle number so I use the different chart times instead.
 
I use this on ES and SPY. I have a quad chart grid with 1, 2, 3, and 5 minute charts for the ES and SPY. Why? Because some days this indicator works best on a particular time. Some days it draws the most accurate levels on the 2 or 3 minute instead of the one minute. I think that's really related to the cycle number on the indicator which is set by default to 25. I don't know of a way to test for the correct cycle number so I use the different chart times instead.

Finding the best cycle on a given time frame is difficult. I too ran it in several time frames.
A key part is probably trying to figure out this indicator is finding it: https://www.tradingview.com/script/nzvqcuSh-Detrended-Rhythm-Oscillator-DRO/
 
I reflected a good deal as I followed this particular thread. I appreciate the sharing of the contributors. I can add that ( for me at least) it is important to be mindful as to what component of the market do I want to follow:
A. example differences in Close, in H-L/2, Vwap, Volume, Tick Count, Implied Volatility? all of these can be subjected to a Wave analysis over any time frame of your choice. I find that a 45 degree shift in the MesaSineWave is and can be excellent in all respects with the exception of lack of control with supression, making it oversensitive in a volatile choppy period. Any mathematical adjustments will adjust the resulting signal and we all need to be cognizant of the basics as are outlined below. That seems simple enough:

Plot Description
Sine Wave Displays the sine of the measured phase angle over time.
Lead Wave Displays the sine of the phase angle advanced by 45 degrees.
ZeroLine Zero level.
B. Second, what time do I want to observe ? or what Multi-Time frame Spectrum to I want to follow?
C. Thirdly, To what combination of Wave variation do I give most weight in deciding when to enter and when to exit?
Where to Begin in our considerations:

Our individual observations are filtered by our own process. While I see some things I don't see other things as a result of my own process. All things contract and expand. This is obvious and not to be overlooked!
To get to the essential point: It occurs to me that introducing a Polarized Fractal overlay on the particular time frame might be a good idea. That way my Brain is alerted to a shift that I otherwise might miss:
Since the auction includes Price and Volume, the easiest Polarized Fractal overlay, although it's a lagging derivative of the market is a VWAP or even a more precise Pt of Control (intraday pt of control) to see where the aggressive trade has joined in. If I run with the pack I don't want to be run over when it stampedes and is spooked in the opposite direction.
Periods of consolidation can build potential energy for the next collective market auction impulse in one direction or the next.
As a point of reference: I greatly admire the traders that are able to not only spot the reversals and pts of inflections ( ) no matter what the time period, but staying in the impulsive move long enough, enduring the tension of uncertainty to profit from a majority of the move is a separate skill- both technical and psychological.
I appreciate any comments or further observations along these lines: how to maximize and monetize the skill set: a. identify reversals and wave displacements in a consistent manner and b. knowing when to pull the trigger, so as we are paid at the end of the day for the effort expended...
With gratefulness to all and in all humility . Best wishes :) MagicQuotes
 
Thread starter Similar threads Forum Replies Date
H Better RSI For ThinkOrSwim Custom 2
TraderZen Shark_Fins Indicator: B4 indicator meets Volume Waves For ThinkOrSwim Custom 5

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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