Re: Fun with ThinkScript July 03, 2015 04:01PM |
Registered: 8 years ago Posts: 26 |
Re: Fun with ThinkScript July 03, 2015 11:11PM |
Registered: 8 years ago Posts: 161 |
Re: Fun with ThinkScript July 04, 2015 12:34AM |
Registered: 8 years ago Posts: 59 |
Re: Fun with ThinkScript July 04, 2015 06:44AM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript July 04, 2015 06:58AM |
Registered: 8 years ago Posts: 26 |
Re: Fun with ThinkScript July 04, 2015 07:42AM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript July 04, 2015 08:15AM |
Registered: 8 years ago Posts: 26 |
Quote
baffled1
for that next candle, i.e., an average for, say, the last 50 instances of that "next" candle, instead of an average for all the non-event intervening candles.
Re: Fun with ThinkScript July 04, 2015 08:37AM |
Registered: 8 years ago Posts: 26 |
declare lower; input RSI_length = 14; input over_bought = 80; input over_sold = 20; input cross_over = 40; input RSI_average_type = AverageType.WILDERS; def RSI_price = close(period=AggregationPeriod.FOUR_HOURS); input KPeriod = 14; input DPeriod = 3; input slowing_period = 1; input averageType = AverageType.SIMPLE; def RSI = RSI(price = RSI_price, length = RSI_length, averageType = RSI_average_type); plot FullK = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullK; plot FullD = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullD; plot OverBought = over_bought; plot OverSold = over_sold; plot crossOver = cross_over; FullK.SetDefaultColor(GetColor(5)); FullD.SetDefaultColor(GetColor(0)); OverBought.SetDefaultColor(GetColor(1)); OverSold.SetDefaultColor(GetColor(1)); CrossOver.SetDefaultColor(GetColor(1));
Re: Fun with ThinkScript July 04, 2015 09:33AM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript July 04, 2015 11:41AM |
Registered: 10 years ago Posts: 615 |
Quote
baffled1
my question is:
How do I get an average for a conditional event? Base code works fine and is:
def runup1 = close>close[1];
def runup2 = close>close[2];
#Most people write the next line as ISTRUE but this works fine for me
plot Above = runup1 and runup2;
Above.SetDefaultColor(Color.blue);
Above.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
So that pops me a nice arrow when true. And it's excellent long signal. So I enter long at the next candle. But I want an average (high-close) value for that next candle, i.e., an average for, say, the last 50 instances of that "next" candle, instead of an average for all the non-event intervening candles. Your help much appreciated.
Quote
howo3579
I was thinking all night and try to come up with some thing but it just made my head hurt. I was trying to use compoundvalue() and fold to do it but I have no idea how to get the barnumber of the previous 50th "eventful next" candle. I suppose Rob or some math genius can help us with that. I'm curious to know how thinkscript code can be done.
def Range = High - Low;
def AfterRunup = Above[1];
def RangeAfterRunup = if AfterRunup then Range else 0;
def TheSum = TotalSum(RangeAfterRunup);
def counter = if AfterRunup then counter[1] + 1 else counter[1];
def OverallAverage = TheSum / counter;
input AverageLength = 50; def TheSum = TotalSum(if counter > HighestAll(counter) - AverageLength then RangeAfterRunup else 0);
input AverageLength = 4; def TheSum = TotalSum(if counter > HighestAll(counter) - AverageLength then RangeAfterRunup else 0); def AvgRange = TheSum / AverageLength;
def runup1 = close > close[1]; def runup2 = close > close[2]; plot Above = runup1 and runup2; Above.SetDefaultColor(Color.BLUE); Above.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); # --- define range --- def Range = high - low; # --- define the candle immediately following a run-up --- def AfterRunup = Above[1]; # --- define the range after a run-up --- def RangeAfterRunup = if AfterRunup then Range else 0; # --- count the number of AfterRunup occurrences --- def counter = if AfterRunup then counter[1] + 1 else counter[1]; # --- add up only the last [x] number of afterRunup range values --- input AverageLength = 50; def TheSum = TotalSum(if counter > HighestAll(counter) - AverageLength then RangeAfterRunup else 0); # --- calculate the average range of the past [x] number of run-ups --- def AvgRange = TheSum / AverageLength; # --- display the AvgRange in a chart label --- AddLabel(yes, "The average range for the past " + AverageLength + " run-ups is: " + Round(AvgRange), Color.YELLOW);
Re: Fun with ThinkScript July 04, 2015 03:27PM |
Registered: 10 years ago Posts: 615 |
Quote
Ralph53
Robert I have 3 more quick questions
1) How should this line appear if I don't want the Bubble hidden? condition.HideBubble();
Quote
Ralph53
2) Is there a condition line for selecting 'Leftaxis' on a chart?
Quote
Ralph53
3) On this script you wrote for me;
def X = (open("period" = AggregationPeriod.DAY) - .05);
def lastbar = HighestAll(if IsNaN(close) then 0 else BarNumber());
plot condition = if BarNumber() <= lastbar - 10 and BarNumber() >= lastbar - 25 then GetValue(X, BarNumber() - lastbar) else Double.NaN;
Is there a way to place 2 different 'def' lines in the same script at once? I need the line to switch to 'def L' if the candlestick is red and 'def H' if it's green;
def L = Lowest(Low +.01, 6) 'if' close <= Open;
def H = Highest(High -.01, 6) 'if' close >= Open;
def CandleUp = close > open; def X = if CandleUp then Highest(high - 0.01, 6) else Lowest(low + 0.01, 6); def lastbar = HighestAll(if IsNaN(close) then 0 else BarNumber()); plot condition = if BarNumber() <= lastbar - 10 and BarNumber() >= lastbar - 25 then GetValue(X, BarNumber() - lastbar) else Double.NaN;
Re: Fun with ThinkScript July 04, 2015 03:48PM |
Registered: 8 years ago Posts: 26 |
Robert your genius. But I'm still confused how this code gave us sum of rangeafterrunup of only the averagelength.Quote
robert
def TheSum = TotalSum(if counter > HighestAll(counter) - AverageLength then RangeAfterRunup else 0);
Re: Fun with ThinkScript July 04, 2015 06:23PM |
Registered: 8 years ago Posts: 161 |
Re: Fun with ThinkScript July 04, 2015 06:45PM |
Registered: 8 years ago Posts: 161 |
Re: Fun with ThinkScript July 05, 2015 05:45AM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript July 05, 2015 07:39AM |
Registered: 8 years ago Posts: 26 |
This is to see the moving average range of current candle if the previous candle broke out above its previous 2 candles. Any time frame. If you want to go long on the open of current bar when the condition is met (blue arrow), you probably need the range of close-open instead of high-low. This way you can see whether the trend is up or down. You can avoid to buy when the average range is negative.Quote
tampman
what this code is supposed to do
Re: Fun with ThinkScript July 05, 2015 09:24AM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript July 05, 2015 10:21AM |
Registered: 8 years ago Posts: 26 |
To short, you can just have another study of the same script and just change the break out condition.Quote
Tampman
what do I change it to if I want to short?
def rundown1 = close < close[1]; def rundown2 = close < close[2]; plot Below = rundown1 and rundown2; Below.SetDefaultColor(Color.Red); Below.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); # --- define range --- def Range = high - low; # --- define the candle immediately following a run-down --- def AfterRundown = below[1]; # --- define the range after a run-down --- def RangeAfterRundown = if AfterRundown then Range else 0; # --- count the number of AfterRundown occurrences --- def counter = if AfterRundown then counter[1] + 1 else counter[1]; # --- add up only the last [x] number of afterRundown range values --- input AverageLength = 50; def TheSum = TotalSum(if counter > HighestAll(counter) - AverageLength then RangeAfterRundown else 0); # --- calculate the average range of the past [x] number of run-ups --- def AvgRange = TheSum / AverageLength; # --- display the AvgRange in a chart label --- AddLabel(yes, "The average range for the past " + AverageLength + " run-downs is: " + Round(AvgRange), Color.YELLOW);If you change the range to close-open, then you want to avoid short when average range is positive.
The blue arrows have nothing to do with the range of the next bar. The arrow is painted only when condition of runup1 and runup2 are met. Then we calculate the range of the next bar after the arrow. If you change the range to close-open, the average range shown on the banner on the top left of the chart will change. Read through Robert's script and compare to the chart, you should understand what each step does to the calculation and output.Quote
Tampman
Actually after changing code to open-close... it showed same arrows... so made no difference unless I did it wrong..?
Add this code at the end of StochRSI_4H script.Quote
Tampman
Also, did you see my questions from yesterday?
just wondering if it would be better visually to make that Yellow line in the lower indicator turn Red when below 50% and Green when above 50%..to reflect bullish/bearish position
FUllK.AssignValueColor(if FUllK >= 50 then Color.Green else Color.Red);
Re: Fun with ThinkScript July 05, 2015 10:50AM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript July 05, 2015 10:59AM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript July 05, 2015 11:57AM |
Registered: 8 years ago Posts: 26 |
Re: Fun with ThinkScript July 05, 2015 12:14PM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript July 05, 2015 03:55PM |
Registered: 8 years ago Posts: 26 |
Re: Fun with ThinkScript July 05, 2015 04:25PM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript July 08, 2015 06:33AM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript July 08, 2015 04:52PM |
Registered: 8 years ago Posts: 26 |
Re: Fun with ThinkScript July 08, 2015 05:24PM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript July 09, 2015 08:49AM |
Registered: 8 years ago Posts: 3 |
input n = 1 ; #Charting the 1st Order Pivot Highs and Lows def pH1 = CompoundValue(1, if high[-1] <= high and high >= high[1] then high else Double.NaN, 0); def pL1 = CompoundValue(1, if low[-1] >= low and low <= low[1] then low else Double.NaN, 0); #Creating different counts to see what the heck is going on... rec c1 = CompoundValue(1, if !IsNaN(pH1) then c1[1] + 1 else 0, 0); rec c2 = CompoundValue(1, if !IsNaN(pH1) then 0 else c2[1] + 1, 0); #c2 counts the number of bars between each 1st #order pivot point rec c3 = CompoundValue(1, if !IsNaN(pH1) then c3[1] + 1 else c3[1], 0); rec c4 = CompoundValue(1, if !IsNaN(pH1) then c4[1] else c4[1] + 1, 0); rec c5 = CompoundValue(1, c3 + c4, 0); rec before = CompoundValue(1, if pH1 > 0 then -c2[n]-1 else 0, 0); rec after = CompoundValue(1, if pH1 > 0 then c2[n]+1 else 0, 0); AddChartBubble(yes, if pH1 > 0 then pH1 else Double.NaN, barnumber(), Color.Yellow, yes); #Shows the barNumber at #pivot point AddChartBubble(yes, if pH1 > 0 then pH1 else Double.NAN,pH1, Color.Yellow, yes); #Shows the value of underlying at #pivot point AddChartBubble(yes, if pH1 > 0 then pH1 else Double.NAN,after, Color.Yellow, yes); #Shows the number of bars to the #left to next pivot point not counting current bar. AddChartBubble(yes, if pH1 > 0 and pH1[n] <= pH1[n] and pH1[n] >= pH1[n] then pH1 else Double.NaN, pH1, Color.Red,yes); #Plotting 1st Order highs and lows plot pivotH_1st = if pH1 > 0 then pH1 else Double.NaN ; plot pivotL_1st = if pL1 > 0 then pL1 else Double.Nan ; pivotH_1st.SetStyle(Curve.POINTS); pivotH_1st.SetDefaultColor(Color.RED); pivotH_1st.SetLineWeight(5); pivotL_1st.SetStyle(Curve.POINTS); pivotL_1st.SetDefaultColor(Color.DARK_GREEN); pivotL_1st.SetLineWeight(5); #Maybe useful counts... AddLabel(yes, "Total # of Bars:" + BarNumber()) ; AddLabel(yes, "# of Bars to the Left:" + n); AddLabel(yes, "Total # of 1st Pivots:" + c3) ; #AddLabel(yes, "Total # of Bars Not 1st Pivots:" + c4) ; AddLabel(yes, "# Bars to the Right:" + c5) ; #AddLabel(yes, "Pivot Value:" + pH2[n]) ; AddLabel(yes, "Is 1st Pivot:" + if c1[n] == 0 then "NO" else "YES" ; AddLabel(yes, "# of Bars to Next 1st Pivot:" + c2) ;
Re: Fun with ThinkScript July 09, 2015 09:13AM |
Registered: 9 years ago Posts: 31 |
Re: Fun with ThinkScript July 09, 2015 01:15PM |
Registered: 8 years ago Posts: 161 |