Repaints Hull Turning Points & Concavity For ThinkOrSwim

Repaints
Hi,
I love this study. I having trouble trying to figure out how to get the value of the turning points.

I would like to get the value of the last 3 bullish and 3 bearish turning points is that possible?

Bullish turning point = DarkGreen to LightGreen
Bearish Turning Point = Orange to DarkRed

- StrategyNode
One way to carry data forward in ThinkScript is to use recursion.
def CarryForwardCalc = if YourConditionIsMet then Variable else KeepLooking If YourConditionIsNotMet then KeepPreviousCarryForwardCalc

Recursion is a resource-intensive. Doing three recursions on a repainting variable that uses future bars would not be recommended, as the script would be too complex to be used anywhere other than for plots on a chart.

Here are the top 50 posts that discuss recursion. Perhaps they will help you along on your quest.
 
One way to carry data forward in ThinkScript is to use recursion.
def CarryForwardCalc = if YourConditionIsMet then Variable else KeepLooking If YourConditionIsNotMet then KeepPreviousCarryForwardCalc

Recursion is a resource-intensive. Doing three recursions on a repainting variable that uses future bars would not be recommended, as the script would be too complex to be used anywhere other than for plots on a chart.

Here are the top 50 posts that discuss recursion. Perhaps they will help you along on your quest.
Hi MerryDay,
Thank You for the prompt reply I think I understand the first step but

How do I get the previous Turning Point Value after I get the first one?
Here is what I have till now (Once I understand the bullish then I can figure out the Bearish)

######### Labels for test
def DarkGreeN = if concavity == 1 and HMA <= HMA[1] then HMA else 0;
def LightGreeN = if concavity == 1 and HMA > HMA[1] then HMA else 0;

def DarkRed = if concavity == -1 and HMA < HMA[1] then HMA else 0;
def Orange = if concavity == -1 and HMA >= HMA[1] then HMA else 0;

def BullishTurningPoint = DarkGreen[1] and Lightgreen;

#BTP = BullishTurningPoint
def RecentBTP = if BullishTurningPoint == 1 then HMA[1] else RecentBTP[1];

AddLabel (Yes,RecentBTP);
 
mod note:
Both this indicator and The Pam indicator repaint. It is not possible to get any reliable backtesting results with these indicators, as all the bad signals are erased and only the good trades show up in the backtesting data.

@QUIKTDR1 @_Merch_Man_
 
Issue: Conditional study-based OCO order is not executing at all (let alone at desired entry point) and just sits unfilled riding along with market.
 
Last edited by a moderator:
@halcyonguy @MerryDay thanks, both, appreciate the feedback
i haven't used OCO code, but i'm guessing it is similar to a scan code.
i think tos expects the code to have a true or false plot value, not a number.


problems,
..you are trying to use a study to determine a true/false situation, but don't have any true/false outputs (plots)
..this study is set up to be an upper chart study.
..has 4 plots. there should be just 1 plot
..all the plots have number values, not true/false (not 0 or 1)


fix
..disable all outputs , plots, AssignPriceColor() , labels, bubbles, ...
..change all the plots to def. then create 1 plot formula that will be true or false
..figure out what condition you want this oco thing to trigger on and make a new plot formula for it.

--------------------------

i made a lower chart study for you to experiment with.

it plots a spike at 1 when plot z is true, when concavity is different from the previous bar.
..i copied a formula and replaced data with 1 and double.nan with 0.
..(true is the same as 1, false is 0)

plot z = if concavity[1] != concavity then 1 else 0;

Code:
# OCO_code_not_working_00_lower

#https://usethinkscript.com/threads/study-based-oco-trouble.14592/
#Study-based OCO trouble
#Issue: Conditional study-based OCO order is not executing at all

declare lower;

input Quantity = 2;
input numberOfBars = 20;
input AvgType = AverageType.HULL;
input STAtrMult = 2.75;
input nATR = 12;

def Point = (Quantity / TickSize()) * TickValue();
def day = GetDay();
def PMfirstBar = day != day[1];
def PMOpen = if PMfirstBar then open else PMOpen[1];
def currentDay = GetLastDay() == GetDay() and GetLastYear() == GetYear();
def PMO = if currentDay then PMOpen else Double.NaN;
def okToPlot = IsNaN(close[-numberOfBars]);

input average_type = AverageType.HULL;
input length1 = 55;
input price = close;
input signalSource = {default concavity, direction};
input paintbars = no;

def data = MovingAverage(average_type, price, length1);
#plot data = MovingAverage(average_type, price, length1);
#data.SetPaintingStrategy(PaintingStrategy.LINE);
#data.SetDefaultColor(Color.CYAN);
#data.SetLineWeight(3);
#data.HideTitle();
#data.HideBubble();

def direction = if data[1] < data then 1 else -1;
#def slope = reference LinearRegressionSlope(data, Max(RoundDown(length / 10,0), 2));
def slope = reference LinearRegressionSlope(data, Sqrt(length1));
def concavity = if slope  > slope [1] then 1 else -1;

#data.AssignValueColor(if concavity > 0 and direction > 0 then Color.GREEN else
#                      if concavity > 0 and direction < 0 then Color.DARK_GREEN else
#                      if concavity < 0 and direction < 0 then Color.RED else
#                      Color.DARK_ORANGE);

def ss = if signalSource == signalSource.concavity then concavity else direction;

#AssignPriceColor(if !paintbars then Color.CURRENT else if ss > 0 then Color.GREEN else Color.RED);

def MA_Max = if data[-1] < data and data > data[1] then data else Double.NaN;
#plot MA_Max = if data[-1] < data and data > data[1] then data else Double.NaN;
#MA_Max.SetDefaultColor(Color.WHITE);
#MA_Max.SetPaintingStrategy(PaintingStrategy.SQUARES);
#MA_Max.SetLineWeight(5);
#MA_Max.HideBubble();
#MA_Max.HideTitle();

def MA_Min = if data[-1] > data and data < data[1] then data else Double.NaN;
#plot MA_Min = if data[-1] > data and data < data[1] then data else Double.NaN;
#MA_Min.SetDefaultColor(Color.WHITE);
#MA_Min.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
#MA_Min.SetLineWeight(5);
#MA_Min.HideBubble();
#MA_Min.HideTitle();

#def turning_point = if concavity[1] != concavity then data else Double.NaN;
#plot turning_point = if concavity[1] != concavity then data else Double.NaN;
#turning_point.SetLineWeight(3);
#turning_point.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
#turning_point.SetDefaultColor(Color.WHITE);
#turning_point.HideBubble();
#turning_point.HideTitle();

plot z = if concavity[1] != concavity then 1 else 0;

#

uJSfmqJ.jpg
@halcyonguy

apologies, I'm trying to learn what I'm still doing wrong. Regardless of the code needing to be worked through, I am just still struggling getting the OCO to execute using the updated lower study that you provided. When setting up the conditional order, I have it set up with the same market order rules and then the condition being that when the study plots z as true within 1 bar, but its not executing. I have tried setting it up also as the plot z equal to Value 1 within 1 bar but also fails. Would you mind please letting me know what I could be doing wrong? Again, not even considering having to work on the code, just trying to learn conceptually what I'm doing wrong to not have the OCO execute at all. Thank you for your help.
 
@halcyonguy

apologies, I'm trying to learn what I'm still doing wrong. Regardless of the code needing to be worked through, I am just still struggling getting the OCO to execute using the updated lower study that you provided. When setting up the conditional order, I have it set up with the same market order rules and then the condition being that when the study plots z as true within 1 bar, but its not executing. I have tried setting it up also as the plot z equal to Value 1 within 1 bar but also fails. Would you mind please letting me know what I could be doing wrong? Again, not even considering having to work on the code, just trying to learn conceptually what I'm doing wrong to not have the OCO execute at all. Thank you for your help.

You seem to be having difficulty following the instructions provided here:
https://usethinkscript.com/threads/...avity-for-thinkorswim.7847/page-3#post-120489

So to start, we have deleted @halcyonguy's post as it may have added to the confusion.
Let's go over a couple of important points to keep in mind:
  1. As it was explained before, using the signal within 1 bar is not allowed since the signal did not occur within 1 bar. Change to: within 2 bars.
  2. Before you start writing an OCO, it's important to make sure that you are getting valid results in both the scanner test and the chart alert test. You can find more details on this in the instructions here: https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-80482
We hope this clears things up a bit and helps you move forward on your quest.
 
Last edited:
is that math correct on the Divergence display in AddLabel??

Ruby:
addLabel(yes, concat("DIVERGENCE: " , divergence * 10000), color = if concavity < 0 then if divergence[1] > divergence then Color.dark_RED else color.PINK else if divergence[1] < divergence then color.dark_green else color.dark_orange);

def divergence_stddev = StandardDeviation(price = divergence, length = stddev_len);
addLabel(yes, concat("STDDEV: " , divergence_stddev * 10000), color = if absValue(divergence) > absValue(divergence_stddev) then color.blue else color.dark_gray);
 
I really like this code I tried to add a label with buy and sell signal using and have not been able to get it to work you have any ideas. I posted the code below
AddLabel(yes, " BUY ", if turning_point and concavity ==1 then CreateColor(153, 255, 153) else Color.WHITE);
 
Last edited by a moderator:
This is a repainting indicator. It uses future bars. Meaning, it waits until the future happens and then goes back and paints the triggers that you see on your charts.

Scripts that repaint should NOT be used in Scans, Labels, Watchlists, Alerts, Conditional Orders or Backtesting Strategies.
a. It will falsely show up in your Scans, Labels, Watchlists, Alerts, Conditional Orders or Backtesting Strategies, but the signal will not be painted on your chart. You will think the script is broken.
b. Or the opposite. It will be painted on your chart but NOT show up in your Scans, Labels, Watchlists, Alerts, Conditional Orders or Backtesting Strategies. This is because it wasn't there in real time! It was painted on afterward.
You will think the script is broken.

As stated above: this should NOT be used in Scans, Labels, Watchlists, Alerts, Conditional Orders
But if you insist, this future bar repainter can be made to work, however be aware there will be a lag which has shown to result in unprofitable trades.
The workaround: requires that you add the "within 2 bars" syntax to your statement.

Here is a scan to test for your concavities. You can use it as a basis for your Scans, Labels, Watchlists, Alerts, Conditional Orders or Backtesting Strategies.
https://usethinkscript.com/threads/...avity-2nd-derivatives.1803/page-21#post-66454


@dannyboi11 @halcyonguy @bakktrader
 
Last edited:

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
164 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