Chance of failed morning spike (code modification)


Category:
0
0

Hello Pete,

A while ago, you provided the code below for a chart label. I wanted to know, how can we modify the code to only begin counting from the 52 week high.

 

input percent = 50.0;
def percentCloseWithinRange = if (high – low) == 0 then 0 else (close – low) / (high – low) ;
plot scan = percentCloseWithinRange * 100 <= percent;
def sum = TotalSum(scan);
def ChanceofFailedMorningSpike = Round(sum / BarNumber(), 3) * 100;
AddLabel(yes, Concat(“Chanceoffailedmorningspike: “, Concat(ChanceofFailedMorningSpike, “%”)), if ChanceofFailedMorningSpike > 64.0 then Color.RED else if ChanceofFailedMorningSpike < 50.0 then Color.GREEN else Color.yellOW);

 

Best

Marked as spam
Posted by (Questions: 22, Answers: 63)
Asked on December 19, 2018 8:32 pm
109 views
0

If the 52-week high isn’t possible to start counting from, a backup solution is to have the code start the count from the Highest candle on the daily chart (indicated by the HI Bubble).

( at December 19, 2018 8:40 pm)
0
Private answer

I think this should do the trick. I did not test it. Took me a few days to ponder a solution. Let us know.

input percent = 50.0;
def percentCloseWithinRange = if (high – low) == 0 then 0 else (close – low) / (high – low) ;
plot scan = percentCloseWithinRange * 100 <= percent; def is52WeekHigh = high > highest(high[1], 251);
rec counter = if is52WeekHigh then 0 else if percentCloseWithinRange then counter[1] + 1 else counter[1];
def ChanceofFailedMorningSpike = Round(counter / BarNumber(), 3) * 100;
AddLabel(yes, Concat(“Chanceoffailedmorningspike: “, Concat(ChanceofFailedMorningSpike, “%”)), if ChanceofFailedMorningSpike > 64.0 then Color.RED else if ChanceofFailedMorningSpike < 50.0 then Color.GREEN else Color.yellOW);

Edit: 12/24/18
After receiving feedback that the code was not working I took some time to troubleshoot and found some adjustments were still required. The code below is the updated version that computes the values correctly.

input percent = 50.0;
def percentCloseWithinRange = if (high – low) == 0 then 0 else (close – low) / (high – low) ;
def qualifiedBar = percentCloseWithinRange * 100 <= percent;
plot is52WeekHigh = high > highest(high[1], 251);
rec counter1 = if is52WeekHigh then 0 else if qualifiedBar then counter1[1] + 1 else counter1[1];
rec counter2 = if is52WeekHigh then 0 else if percentCloseWithinRange then counter2[1] + 1 else counter2[1];
def ChanceofFailedMorningSpike = Round(counter1 / counter2, 3) * 100;
AddLabel(yes, Concat(“Chanceoffailedmorningspike: “, Concat(ChanceofFailedMorningSpike, “%”)), if ChanceofFailedMorningSpike > 64.0 then Color.RED else if ChanceofFailedMorningSpike < 50.0 then Color.GREEN else Color.yellOW);

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on December 22, 2018 10:55 am
0

providing test results screenshot in ordinal post or maybe answer section if i cannot edit original post

( at December 22, 2018 12:37 pm)
0
So I tested the results, and it’s not accurate, but I see what you were thinking. To test, I used the symbol YECO and adjusted the timeframe on the Dailey chart to only show from the day of the 52 week high which was the also the highest candle on the daily chart as you can see based on my screenshot provided. The label percentage should be the same. The old code represents the intended behavior once when the daily chart is adjusted to start from the 52 week high. We want the new code to do this without the need for the chart time length to be adjusted for the 52 week high being the starting candle
( at December 23, 2018 4:41 pm)
0

Thanks for the feedback. I have updated my answer to include a modified version that works.

( at December 24, 2018 9:16 am)
0

Works better, thank you so much for making this happen.

The only thing I wonder is why do some tickers have no results with the new code sush as

SFET
XBIT
MRIN

( at December 24, 2018 10:50 am)
0

For SFET, there is less than 52 weeks of chart data. For the other two, they have each made a new 52 week high and the percentage is zero (not sure why the label won’t print. could be a glitch in Thinkorswim)

( at December 24, 2018 11:17 am)
0
Okay cool, my final request if how can we modify the original and new code to add a new condition. Everything should remain the same, expect only count candles that have more than 100,000 volume.
( at December 24, 2018 6:47 pm)
0

This is “mission creep”. When specifications are added after the final product has been delivered. You have been very active on this forum and your participation is greatly appreciated. Please be sure to state your complete specification from the start. We don’t do projects here. We provide direct solutions to clearly specified requests. As it is, this very post is a continuation from a previous one. End of the line for this one.

( at December 25, 2018 2:42 pm)
0

Okay, can I pay the rate to make this a project to include volume in the condition? This will be the last request.

Best

( at December 26, 2018 5:48 am)
0

Change this line:
def qualifiedBar = percentCloseWithinRange * 100 < = percent;

To this:
def qualifiedBar = percentCloseWithinRange * 100 <= percent and volume > 100000;

( at December 26, 2018 7:51 am)