|
Post by EBTrader on Feb 23, 2015 3:32:17 GMT
I tweaked the hull a bit to take into account the close vs. the hull ma. Here is the new and improved version:
#Hull Moving Average #Colors and arrows and labels by EBTrader 02.22.15
input price = close; input length = 9; input displace = 0;
plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];
HMA.DefineColor("Up", color.green); HMA.DefineColor("Down", color.red); HMA.AssignValueColor(if price > HMA then HMA.color("Up") else HMA.color("Down")); AssignPriceColor(if price > HMA then HMA.color("Up") else HMA.color("Down"));
#===================start arrows and labels
input crossingType = {default any, above, below}; def signal = CompoundValue(1, if crosses(price, HMA,crossingDirection.ABOVE) then 1 else if crosses(price, HMA, crossingDirection.BELOW) then -1 else signal[1], 0); input showarrows = yes; plot U1 = showarrows and signal > 0 and signal[1] <= 0; U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); U1.SetDefaultColor(Color.green); U1.SetLineWeight(3); plot D1 = showarrows and signal < 0 and signal[1] >= 0; D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); D1.SetDefaultColor(Color.red); D1.SetLineWeight(3);
input usealerts = no; Alert(usealerts and U1, "UP", Alert.BAR, Sound.Bell); Alert(usealerts and D1, "DOWN", Alert.BAR, Sound.Chimes);
def uptrend = price > HMA; def downtrend = price < HMA;
addlabel(uptrend, "Uptrend", color.green); addlabel(downtrend, "Downtrend", color.red);
#================end arrows and labels
|
|
serm
New Scripter
Posts: 2
|
Post by serm on Mar 11, 2015 23:28:37 GMT
thanks for sharing...
|
|
serm
New Scripter
Posts: 2
|
Post by serm on Mar 11, 2015 23:42:03 GMT
Ebtrader, please keep the new ideas (from wherever, including TOS LOUNGE) coming... they're always appreciated.
This is (a very tentative) invention based on a webinar about candlestick math... I use it to confirm other signals. Usually the reading of a hammer, or other variations of a doji-like candle can be very useful signs of a new trend...
- I've also applied a bunch of other logics to these new types of candles (needs a lot of cleaning up!) But anyways, this was one of my first codes in Tos. I hope it's useful to somebody. (please share any new applications/variations for it)
#MOIMEICHEGO_CANDLESTICKMath
def tk = TickSize(); AddLabel(yes, "tk: " + tk, Color.WHITE);
declare lower; # from Pinto Dynamic line #input NumberOfBarsToPlot = 200; input PercentOfChartToPlotLevels = 0 ; #25 def NumberOfBarsToPlot = Floor(PercentOfChartToPlotLevels * BarNumber() / 100);
input AskToBidWeight = 100; ### 70 is original 100% means Limit = Ask, 0% means Limit = Bid
def last = close(priceType = "Last"); def bid = close(priceType = "Bid" ); def ask = close(priceType = "Ask" ); def limit = if last > (bid + ask) / 2 then ( AskToBidWeight * ask + (100 - AskToBidWeight) * bid ) / 100 else ( AskToBidWeight * bid + (100 - AskToBidWeight) * ask ) / 100;
script dynamic { input BarsToPlot = 200; input level = close; def barNumber = if IsNaN(level) then barNumber[1] else BarNumber(); def ThisBar = HighestAll(barNumber); def cLine = if barNumber == ThisBar then level else Double.NaN; plot levelToPlot = if ThisBar - BarsToPlot <= barNumber then HighestAll(cLine) else Double.NaN; }
plot dynClose = dynamic(BarsToPlot = Floor(NumberOfBarsToPlot / 2), level = close); dynClose.AssignValueColor(Color.GRAY);
# very, very tentative... based on candlestick lecture on bigmike (look for it on ytube)
#declare lower; # basic defs #def p= getaggregationPeriod(); def o = open;#(period=p); def h = high;#(period=p); def c = close;#(period=p); def l = low;#(period=p); def rg = h - l; def na = Double.NaN; input _tick = 0.1; #Hint Adjust to tk size def tick = tk; #_tick def sp = tick * 4; input n = 5; input chart = ChartType.CANDLE;
input cond = yes; #plug whatever condition here. # CandleStick addition / subtraction based on last n bars; def hc = if cond then Highest(h, n) else h; #def hc = average(_hc, n); def lc = if cond then Lowest(l, n) else l; #def lc = average(_lc,n); def oc = if cond then o[n] else o; #def oc=average(_oc,n); def cc = if cond then c else c; #def cc = average(_cc,n);
def rgc = hc - lc; #range of current chart input avgtype = AverageType.EXPONENTIAL; input avglength = 10; def avgrgc = MovingAverage(avgtype, rgc, avglength); def bodyC = AbsValue (cc - oc); def mid = (hc + lc) / 2;
#AddChart(high = hc, low = lc, open = oc, close = cc, type = chart, growColor = Color.WHITE, fallColor = color.red, neutralColor = Color.GRAY);
AddChart(high = hc, low = lc, open = oc, close = cc, type = chart, growColor = Color.WHITE, fallColor = Color.RED, neutralColor = Color.GRAY); #broken on new Tos version. All red colors.
########## hi/lo channels def hhc = Highest(hc, n); def llc = Lowest(lc, n); plot hhcBU = if hc > hhc[1] then llc - sp else na; #Channel BreakOut plot llcBD = if lc < llc[1] then hhc + sp else na; #channel Breakdown
hhcBU.SetPaintingStrategy(PaintingStrategy.ARROW_UP); hhcBU.SetLineWeight(3); hhcBU.SetDefaultColor(Color.ORANGE); hhcbu.hide();
llcBD.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); llcBD.SetLineWeight(3); llcBD.SetDefaultColor(Color.BLUE); llcbd.hide();
#### Doji def doji = bodyC <= 0.05; plot _doji = if doji then lc - sp else Double.NaN; _doji.SetPaintingStrategy(PaintingStrategy.ARROW_UP); _doji.SetLineWeight(5); _doji.Hide();
# dojiBands breakout def dojihh = if doji then hhc else dojihh[1]; #hc is normal h hhc is highest from nbars; def dojill = if doji then llc else dojill[1];
def priceDojiU = dojihh + tick; def priceDojiD = dojill - tick;
def DojiBUp = h > dojihh[1]; def dojiBDn = l < dojill[1];
plot _DojiBup = if DojiBUp and !DojiBUp[1] then llc - sp else na; plot _dojiBDn = if dojiBDn and !dojiBDn[1] then hhc + sp else na; _DojiBup.SetPaintingStrategy(PaintingStrategy.TRIANGLES); _DojiBup.SetDefaultColor(Color.RED); _DojiBup.SetLineWeight(3); #_dojibup.hide();
_dojiBDn.SetPaintingStrategy(PaintingStrategy.TRIANGLES); _dojiBDn.SetDefaultColor(Color.RED); _dojiBDn.SetLineWeight(3); #_dojibdn.hide();
plot _dojihh = dojihh; plot _dojill = dojill; _dojihh.Hide(); _dojill.Hide(); #AddCloud(_dojihh, _dojill, Color.GRAY);
#plot dynA = dynamic(BarsToPlot = Floor(NumberOfBarsToPlot / 2), level = _dojihh + tick); #dynA.AssignValueColor(Color.VIOLET);
#plot dynB = dynamic(BarsToPlot = Floor(NumberOfBarsToPlot / 2), level = _dojill - tick); #dynB.AssignValueColor(Color.RED);
#### NR4 calculated - narrowest of the last 4bars def confirmed = !IsNaN(c[-1]); def llrg4 = Lowest(rgc, 3); def NR4 = llrg4 < llrg4[1]; plot _NR4 = if NR4 then l else na; _NR4.SetPaintingStrategy(PaintingStrategy.POINTS); _NR4.SetLineWeight(3); _NR4.SetDefaultColor(Color.YELLOW); _NR4.Hide(); #addChartBubble(nr7p, low , "nr7", color.red, no); #serm
### Triangle, It's actually an IntraDay bar IB if lowest 2 period input Tn = 3; #2 Two is equal IntraDay Bar, three is equal triangle input _nr4filter = yes; def nr4filter = if _nr4filter == yes then NR4 else yes;
def T = hc < Highest(hc, Tn) and lc > Lowest(lc, Tn) and confirmed and nr4filter; #using narrowest range filter
def _thh = if T then hc else _thh[1]; def _tll = if T then lc else _tll[1]; plot thh = _thh; plot tll = _tll; thh.Hide(); tll.Hide(); #AddCloud(thh, tll, Color.LIGHT_GRAY, Color.BLUE);
#plot TlineH = dynamic(BarsToPlot = Floor(NumberOfBarsToPlot / 2), level = thh + TickSize()); #TlineH.AssignValueColor(Color.VIOLET); #tlineH.HideBubble();
#plot TlineL = dynamic(BarsToPlot = Floor(NumberOfBarsToPlot / 2), level = tll - TickSize()); #TlineL.AssignValueColor(Color.RED); #tlineL.HideBubble(); #AddChartBubble(T, h, "t", Color.YELLOW, yes); #serm
#### Hammer (probably more useful than a doji in this context of avg candlesticks def third = rgc / 3; def hammer = bodyC <= third; def hammerU = hammer and oc > mid and cc > mid;# and cc>=oc ; #check these... def hammerD = hammer and oc < mid and cc < mid;# and cc<=oc;
plot _hammerU = if hammerU then lc - sp else Double.NaN; _hammerU.SetPaintingStrategy(PaintingStrategy.ARROW_UP); _hammerU.SetLineWeight(2); _hammerU.SetDefaultColor(Color.MAGENTA); #_hammer.hide();
plot _hammerD = if hammerD then hc + sp else Double.NaN; _hammerD.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); _hammerD.SetLineWeight(2); _hammerD.SetDefaultColor(color.orange); #_hammer.hide();
## CLOSE > or < OPEN def u = cc > oc; def d = cc < oc;
## alerts
Alert(hammerU, "Buy - HammerU", Alert.BAR, Sound.Bell ); Alert(hammerD, "Sell - HammerD", Alert.BAR, Sound.Ding);
#### Profit / Reversal Bar??? (lower bar close at low, higher bar close at high) ... ADD range must be wider... and a factor for proximity, not only exactly == def PBarU = d and cc == lc and rgc > avgrgc; #lower close, close==low and range is greater than average range; def PBarD = u and cc == hc and rgc > avgrgc;
plot _PBarU = if PBarU then lc - sp else Double.NaN; _PBarU.SetPaintingStrategy(PaintingStrategy.POINTS); _PBarU.SetLineWeight(5); _PBarU.SetDefaultColor(Color.WHITE); #_pbarU.hide();
plot _PBarD = if PBarD then hc + sp else Double.NaN; _PBarD.SetPaintingStrategy(PaintingStrategy.POINTS); _PBarD.SetLineWeight(5); _PBarD.SetDefaultColor(Color.WHITE); #_pbarD.hide();
# Stochastic of CANDLESTICK MATH input kperiod = 5; input dperiod = 3; def ob = 80; def os = 20;
def lls = Lowest(lc, kperiod); def hhs = Highest(h, kperiod); def fastk = if (hhs - lls) <= 0 then 0 else 100 * (cc - lls) / (hhs - lls); def fastD = MovingAverage(avgtype, fastk, dperiod); addlabel(fastd, "Stoch: "+fastd, color.white);
## Plot close>open or close<open plot CgreaterthanO = if u then lc - sp - (tick * 2) else Double.NaN; plot ClessthanO = if d then hc + sp + (tick * 2) else Double.NaN; CgreaterthanO.Hide(); ClessthanO.Hide();
CgreaterthanO.SetPaintingStrategy(PaintingStrategy.ARROW_UP); CgreaterthanO.SetLineWeight(1); CgreaterthanO.SetDefaultColor(Color.MAGENTA);
ClessthanO.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); ClessthanO.SetLineWeight(1); ClessthanO.SetDefaultColor(Color.RED);
# Price Strategy Bubbles input bubbles = no; def dir = CompoundValue(1, if hammerU then 1 else if hammerD then -1 else dir[1], 0);
def orderDir = dir; def isOrder = orderDir crosses 0;
def orderCount = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder then orderCount[1] + 1 else orderCount[1], 0);
def noBar = IsNaN(open[-1]);
def orderPrice = if isOrder then if noBar then close else open[-1] else orderPrice[1]; # then close... def profitLoss = if !isOrder or orderCount == 1 then 0 else if orderDir > 0 then orderPrice[1] - orderPrice else if orderDir < 0 then orderPrice - orderPrice[1] else 0; def profitLossSum = CompoundValue(1, if IsNaN(isOrder) then 0 else if isOrder then profitLossSum[1] + profitLoss else profitLossSum[1], 0);
AddLabel(yes, orderCount + " orders | P/L " + AsDollars((profitLossSum / TickSize()) * TickValue()), if profitLossSum > 0 then Color.GREEN else if profitLossSum < 0 then Color.RED else Color.GRAY);
AddChartBubble(bubbles and isOrder and orderDir > 0, lc, profitLoss, if noBar then Color.LIGHT_GRAY else Color.GREEN, 0); AddChartBubble(bubbles and isOrder and orderDir < 0, hc, profitLoss, if noBar then Color.GRAY else Color.RED, 1);
#AddVerticalLine(vLine and isOrder, "", if orderDir > 0 then Color.GREEN else Color.RED, vLine);
######################### VSA GREEN ARROW Plugged onto CANDLESTICK MATH...
# Arguments
input volumeEMALength = 30; input narrowSpreadFactor = 0.7; input wideSpreadFactor = 1.5; input aboveAvgVolfactor = 1.5;
####### # Calculations
rec spread = hc - lc; def median = (hc + lc ) / 2; rec avgVolume = CompoundValue(volumeEMALength, ExpAverage(volume, volumeEMALength), Double.NaN);
# Calculate Volume moving average and it's standard deviation rec sAvgVolume = CompoundValue(volumeEMALength, Average(volume, volumeEMALength), Double.NaN); def sAvgVolumeSTD = StDev(sAvgVolume, volumeEMALength);
# check if the vloume has been decreasing in the past two days. def isTwoDaysLowVol = (volume < volume[1] && volume[0] < volume[2]);
# Calculate Range information def avgSpread = WildersAverage(spread, volumeEMALength)[0]; rec isWideSpreadBar = (spread > (wideSpreadFactor * avgSpread)); rec isNarrowSpreadBar = (spread < (narrowSpreadFactor * avgSpread));
# Check if the close is in the Highs/Lows/Middle of the bar. # C_RP 20100809 # original code - def x1 = if (close == low) then avgSpread else (spread /(close - low)); def x1 = if (hc == lc) then 2.0 else if (cc == lc) then 2.65 else (spread / (cc - lc)); # C_RP try the line below with various divisors totalSum result in a minimum of 2.3 on a spread of 1 pip instead of using a fixed 2.3 as in the line above # def x1 = if (high==low) then 2.0 else if (close == low) then (spread / 0.43 ) else (spread / (close - low));
# Price information rec isUpBar = cc > cc[1]; rec isDownBar = cc < cc[1]; def isUpCloseBar = (x1 < 2); def isDownCloseBar = (x1 > 2); def isMidCloseBar = (x1 < 2.2 && x1 > 1.8); def isVeryHighCloseBar = (x1 < 1.35); # C_RP 20100809 added isVeryLowCloseBar def isVeryLowCloseBar = (x1 >= 2.65);
# Trend Definitions
rec fiveDaysSma = CompoundValue(5, Average(cc, 5)[0], Double.NaN); def LongTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length = 40)[0]; def ShortTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length = 5)[0]; def MiddleTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length = 15)[0];
# stdn, stdn0, stdn1, stdn2 def strengthInDownTrend = (volume[0] > volume[1] && isDownBar[1] && isUpBar[0] && (isUpCloseBar or isMidCloseBar) && ShortTermTrendSlope < 0 && MiddleTermTrendSlope < 0);
def strengthInDownTrend1 = (volume[0] > (sAvgVolume[0] * aboveAvgVolfactor) && isDownBar[1] && isUpBar[0] && (isUpCloseBar or isMidCloseBar) && ShortTermTrendSlope < 0 && MiddleTermTrendSlope < 0 && LongTermTrendSlope < 0); def strengthInDownTrend2 = (volume[1] < sAvgVolume[0] && isUpBar[0] && isVeryHighCloseBar && volume[0] > sAvgVolume[0] && ShortTermTrendSlope < 0);
rec bycond1 = (strengthInDownTrend or strengthInDownTrend1); # bycond
def isStrengthConfirmationBar = (isUpBar[0] && bycond1[1]);
# bycond2 C_RP UpClose on higher volume with all slopes down adds extra strength def isStrengthConfirmationBar2 = (isUpBar[0] && isUpCloseBar[0] && volume[0] > volume[1] && LongTermTrendSlope < 0 && bycond1[1]);
# Plot with green arrow
# green triangle up at bottom of the bar C_RP Green arrow up 4 * tickSize for strong strength_In_DownTrend plot VSAGreenArrow = if isStrengthConfirmationBar then (lc - 5 * TickSize()) else if isStrengthConfirmationBar2 then (lc - 9 * TickSize()) else Double.NaN; VSAGreenArrow .SetPaintingStrategy(PaintingStrategy.ARROW_UP); VSAGreenArrow .SetLineWeight(5); VSAGreenArrow .SetDefaultColor(Color.GREEN);
#Order green arrow #AddOrder(OrderType.BUY_AUTO, isstrengthConfirmationBarPlot, name = "VolU", price = open[-1], arrowcolor = Color.BLACK, tickcolor = Color.BLACK); #priceTup
############## VSA Red Down ARROW #Here's the code for Red DownArrow, seems to be working. But it's messy I'll try to clean up later. #I tested it with Russell 2000 and 1000.
# utbar
#rec isWideSpreadBar = (spread > (wideSpreadFactor * avgSpread));
#def MiddleTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length = midTermLength)[0]; # 15
rec isUpThrustBar = isWideSpreadBar && isDownCloseBar && ShortTermTrendSlope > 0 && MiddleTermTrendSlope > 0; #C_RP added positive middleTermTrendSlope requirement to filter out upThrusts in trends that are only short term. Consider adding longTermTrendSlope requirement as well.
# utcond1
def upThrustConditionOne = (isUpThrustBar[1] && isDownBar);
# utcond2
def upThrustConditionTwo = (isUpThrustBar[1] && isDownBar[0] && volume > volume[1]);
# utcond3
def upThrustConditionThree = (isUpThrustBar[0] && volume > 2 * sAvgVolume[0]);
# scond1
rec isConfirmedUpThrustBar = (upThrustConditionOne or upThrustConditionTwo or upThrustConditionThree);
# scond
rec isNewConfirmedUpThrustBar = (isConfirmedUpThrustBar[0] && !isConfirmedUpThrustBar[1]);
#Plot with Red Down Arrow
# new confirmed upthrust bar - red triangle (down) on top C_RP red arrow down at 4 * tickSize for conditions 2 and 3
#plot isNewConfirmedUpThrustBarPlot23 = if isNewConfirmedUpThrustBar && (upThrustConditionTwo or upThrustConditionThree) then (high + 4 * TickSize()) else Double.NaN;
plot VSARedArrow = if isNewConfirmedUpThrustBar && (upThrustConditionTwo or upThrustConditionThree) then (hc + 4 * TickSize()) else Double.NaN;
VSARedArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
VSARedArrow.SetDefaultColor(Color.RED); VSARedArrow.SetLineWeight(5); VSARedArrow.HideBubble(); VSARedArrow.HideTitle();
|
|
|
Post by EBTrader on Mar 12, 2015 2:14:51 GMT
Thx Sergio! Will do! Look for our tweets every morning on Stocktwits. Handle is tradershubinfo.
|
|
|
Post by Sharyl on Feb 19, 2021 2:54:49 GMT
|
|
|
Post by Willian on Feb 19, 2021 20:07:17 GMT
|
|
|
Post by cialis 20mg on Nov 14, 2021 15:29:20 GMT
<a href="https://cialiswithdapoxetine.com/#">cialis coupon</a> cialis dosage
|
|
|
Post by cialis 20 mg on Nov 17, 2021 19:10:50 GMT
<a href="https://cialiswithdapoxetine.com/#">buy cialis usa</a> cialis alternative
|
|
|
Post by cialis generic on Nov 21, 2021 14:04:43 GMT
cialis 20mg <a href="https://cialiswithdapoxetine.com/#">cialis 20 mg</a>
|
|
cialis without a doctor prescr
Guest
|
Post by cialis without a doctor prescr on Nov 28, 2021 13:43:05 GMT
<a href="https://cialiswithdapoxetine.com/#">cialis dosage</a> cialis 20 mg
|
|
|
Post by cialis generic on Dec 2, 2021 3:55:31 GMT
cialis 20 mg <a href="https://cialiswithdapoxetine.com/#">cialis pills</a>
|
|
|
Post by generic cialis on Dec 6, 2021 3:05:19 GMT
<a href="https://cialiswithdapoxetine.com/#">buy cialis online</a> cialis 20mg
|
|
|
Post by buy cialis online on Dec 9, 2021 18:43:23 GMT
|
|
|
Post by cialis support 365 on Dec 13, 2021 2:58:44 GMT
|
|
|
Post by cialis generic on Dec 17, 2021 11:48:10 GMT
cialis without a doctor prescription <a href="https://cialiswithdapoxetine.com/#">cialis tablets</a>
|
|