input magnitude = 2;
input showValues = yes;
def top = high >= Highest(high[1], magnitude) and high >= Highest(high[-magnitude], magnitude);
def topvalue = if BarNumber() < magnitude then Double.NaN else if top then high else topvalue[1];
plot topline = topvalue;
def countp = if IsNaN(top) and !IsNaN(top[1]) then 1 else countp[1] + 1;
plot peaktop = if IsNaN(top) then GetValue(topline, countp) else Double.NaN;
def bottom = low <= Lowest(low[1], magnitude) and low <= Lowest(low[-magnitude], magnitude);
def bottomValue = if BarNumber() < magnitude then Double.NaN else if bottom then low else bottomValue[1];
plot bottomline = bottomValue;
topline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
topline.SetDefaultColor(Color.RED);
peaktop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
peaktop.SetDefaultColor(Color.RED);
bottomline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bottomline.SetDefaultColor(Color.GREEN);
input show_bubble_labels = yes;
AddLabel(yes, if close>high then "👍" else "NA", if close>high is true then color.green else color.black);
Hi Joshua, have you solved the problem?ok so lets try this again. the code is below. all im wanting is that thumbs up if the price is greater then the prev resistance line. ive been trying to steal parts of the script from auto piv to try and figure out the code. the Auto piv has a box that says the price is above trend... i want the same type of thing for the script below. is this even possible? ive spent hours trying to figure it out.
Code:input magnitude = 2; input showValues = yes; def top = high >= Highest(high[1], magnitude) and high >= Highest(high[-magnitude], magnitude); def topvalue = if BarNumber() < magnitude then Double.NaN else if top then high else topvalue[1]; plot topline = topvalue; def countp = if IsNaN(top) and !IsNaN(top[1]) then 1 else countp[1] + 1; plot peaktop = if IsNaN(top) then GetValue(topline, countp) else Double.NaN; def bottom = low <= Lowest(low[1], magnitude) and low <= Lowest(low[-magnitude], magnitude); def bottomValue = if BarNumber() < magnitude then Double.NaN else if bottom then low else bottomValue[1]; plot bottomline = bottomValue; topline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); topline.SetDefaultColor(Color.RED); peaktop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); peaktop.SetDefaultColor(Color.RED); bottomline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); bottomline.SetDefaultColor(Color.GREEN); input show_bubble_labels = yes; AddLabel(yes, if close>high then "👍" else "NA", if close>high is true then color.green else color.black);
#MARKET DIRECTION
input averageLength = 21;
input marketIndex = "NDX";
def Cond1 = expAverage(close(marketIndex), averageLength);
#SUPPORT
input price = close;
input startingMA = 21;
input endingMA = 90;
def inc = (endingMA - startingMA) / 7;
plot RS1 = ExpAverage(price, startingMA + 0 * inc);
plot RS2 = ExpAverage(price, startingMA + 1 * inc);
plot RS3 = ExpAverage(price, startingMA + 2 * inc);
plot RS4 = ExpAverage(price, startingMA + 3 * inc);
plot RS5 = ExpAverage(price, startingMA + 4 * inc);
plot RS6 = ExpAverage(price, startingMA + 5 * inc);
plot RS7 = ExpAverage(price, startingMA + 6 * inc);
plot RS8 = ExpAverage(price, startingMA + 7 * inc);
def rs9 = SimpleMovingAvg(close, 200);
RS1.SetDefaultColor(CreateColor(255, 65, 0));
RS2.SetDefaultColor(CreateColor(255, 90, 0));
RS3.SetDefaultColor(CreateColor(255, 115, 0));
RS4.SetDefaultColor(CreateColor(255, 140, 0));
RS5.SetDefaultColor(CreateColor(255, 165, 0));
RS6.SetDefaultColor(CreateColor(255, 190, 0));
RS7.SetDefaultColor(CreateColor(255, 215, 0));
RS8.SetDefaultColor(CreateColor(255, 240, 0));
def Cond2 = low > rs1 and RS1 > RS2 and RS2 > RS3 and RS3 > RS4 and RS4 > RS5 and RS5 > RS6 and RS6 > RS7 and RS7 > RS8 and low > rs9;
#EXIT
input AtrMult = 7;
input ATRlength = 10;
input lookbackLength = 21;
input highestHigh = high;
input lowestLow = low;
input AvgType = averageType.EXPONENTIAL;
input PaintBars = no;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), ATRlength);
def longstop = Highest(highestHigh, lookbackLength) - AtrMult * ATR;
def shortstop = Lowest(lowestLow, lookbackLength) + AtrMult * ATR;
def shortvs = if IsNaN(shortvs[1]) then shortstop else if close > shortvs[1] then shortstop else Min(shortstop, shortvs[1]);
def longvs = if IsNaN(longvs[1]) then longstop else if close < longvs[1] then longstop else Max(longstop, longvs[1]);
def longswitch = if close >= shortvs[1] and close[1] < shortvs[1] then 1 else 0;
def shortswitch = if close <= longvs[1] and close[1] > longvs[1] then 1 else 0;
def direction = if IsNaN(direction[1]) then 0 else if direction[1] <= 0 and longswitch then 1 else if direction[1] >= 0 and shortswitch then -1 else direction[1];
def pc = if direction > 0 then longvs else shortvs;
plot VolatilityStop = pc;
VolatilityStop.AssignValueColor(if direction < 0 then Color.RED else Color.GREEN);
AssignPriceColor(if PaintBars and direction < 0
then Color.RED
else if PaintBars and direction > 0
then Color.GREEN
else Color.CURRENT);
def cond3 = direction>0;
#ENTRY
def Entry = cond1 and cond2 and cond3;
plot signal = if entry then 1 else 0;
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
AddOrder(OrderType.BUY_TO_OPEN, signal, open [-1], tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Buy2");
#
# TD Ameritrade IP Company, Inc. (c) 2014-2021
#
script VariableMinOffset {
input price = close;
input length = 0;
plot VMin;
if !IsNaN(price) and !IsNaN(length) {
VMin = fold i = 0 to length with o do if GetValue(price, i) < GetValue(price, o) then i else o;
} else {
VMin = Double.NaN;
}
}
script VariableLRS {
input price = close;
input length = 0;
plot VLRS;
if !IsNaN(price) and length != 1 {
VLRS = 6 * ( ( fold i1 = 0 to length with s1 do s1 + (length - i1) * GetValue(price, i1) ) / ( (1 + length) / 2 * length ) - ( fold i2 = 0 to length with s2 do s2 + GetValue(price, i2) ) / length ) / (length - 1);
} else if length == 1 {
VLRS = 0;
} else {
VLRS = Double.NaN;
}
}
input maxFlagLength = 15;
input maxFlagHeight = 2.5;
input maxPoleLength = 23;
input minPoleHeight = 5.5;
input upTrendLength = 70;
input minAtrPercentChange = 5.0;
Assert(maxPoleLength > 0, "'maxPoleLength' must be positive: " + maxPoleLength);
def x1 = GetMaxValueOffset(close, maxFlagLength)[2] + 2;
def x2 = x1 + 1;
def lfOffset = VariableMinOffset(close, x2);
def lf = GetValue(close, lfOffset);
def top = Max(GetValue(close, x1), GetValue(close, x1 + 1));
def atr = Average(TrueRange(high, close, low), 40);
def LRSX = VariableLRS(close[1], x1);
def LRSX1 = VariableLRS(close, x1);
def LRSX2;
if x1 == 2 {
LRSX2 = LRSX2[1];
} else if x1 > 2 {
LRSX2 = VariableLRS(close[2], x1 - 1);
} else {
LRSX2 = Double.NaN;
}
def condition1 = top - lf < maxFlagHeight * atr and x2 > 2 and x2 <= maxFlagLength;
def condition2 = if IsNaN(LRSX) or IsNaN(LRSX1) or IsNaN(LRSX2) then no else LRSX < 0 and (LRSX1 < 0 or LRSX2 < 0);
def y23 = VariableMinOffset(close, maxPoleLength + x2);
def bottom = GetValue(close, y23);
def pole = top - bottom;
def condition3 = pole > minPoleHeight * atr and y23 > x2;
def condition4 = bottom - Lowest(low, upTrendLength) > 0;
def condition5 = (atr / GetValue(atr, y23) - 1) * 100 > minAtrPercentChange;
plot Flag = condition1 and condition2 and condition3 and condition4 and condition5;
Flag.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Flag.SetLineWeight(3);
#
# TD Ameritrade IP Company, Inc. (c) 2014-2021
#
input maxFlagLength = 15;
input maxFlagHeight = 2.5;
input maxPoleLength = 23;
input minPoleHeight = 5.5;
input upTrendLength = 70;
input minLengthBetweenFlags = 50;
input minAtrPercentChange = 5.0;
input strictBreakout = yes;
input profitTargetConstant = 1.2;
input stopLossDelayLength = 5;
input stopAtr = 3.0;
input trailStopLength = 5;
input trailStopAtr = 3.0;
input inactivityExitLength = 70;
input inactivityAtr = 4.0;
input timeExitLength = 100;
Assert(maxFlagLength > 0, "'maxFlagLength' must be positive: " + maxFlagLength);
Assert(maxPoleLength > 0, "'maxPoleLength' must be positive: " + maxPoleLength);
Assert(stopLossDelayLength > 0, "'stopLossDelayLength' must be positive: " + stopLossDelayLength);
Assert(inactivityExitLength > 0, "'inactivityExitLength' must be positive: " + inactivityExitLength);
Assert(timeExitLength > 0, "'timeExitLength' must be positive: " + timeExitLength);
def atr = Average(TrueRange(high, close, low), 40);
def isFlag = reference IntradayFlagFormation(maxFlagLength = maxFlagLength, maxFlagHeight = maxFlagHeight, maxPoleLength = maxPoleLength, minPoleHeight = minPoleHeight, upTrendLength = upTrendLength, minAtrPercentChange = minAtrPercentChange).Flag;
def pole = reference IntradayFlagFormation(maxFlagLength = maxFlagLength, maxFlagHeight = maxFlagHeight, maxPoleLength = maxPoleLength, minPoleHeight = minPoleHeight, upTrendLength = upTrendLength, minAtrPercentChange = minAtrPercentChange).pole;
def lf = reference IntradayFlagFormation(maxFlagLength = maxFlagLength, maxFlagHeight = maxFlagHeight, maxPoleLength = maxPoleLength, minPoleHeight = minPoleHeight, upTrendLength = upTrendLength, minAtrPercentChange = minAtrPercentChange).lf;
def flagSum = Sum(isFlag, minLengthBetweenFlags) == 1;
def poleSave;
def lfSave;
if isFlag and flagSum {
poleSave = pole;
lfSave = lf;
} else {
poleSave = poleSave[1];
lfSave = lfSave[1];
}
AddOrder(OrderType.BUY_TO_OPEN, isFlag and flagSum, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "FlagLE");
def entryPrice = EntryPrice();
def afterEntryCount = if IsNaN(entryPrice[1]) and !IsNaN(entryPrice) then 1 else if !IsNaN(entryPrice) then afterEntryCount[1] + 1 else Double.NaN;
AddOrder(OrderType.SELL_TO_CLOSE, close >= entryPrice + profitTargetConstant * poleSave, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "FlagProfitTargetLX");
AddOrder(OrderType.SELL_TO_CLOSE, afterEntryCount > stopLossDelayLength and close < lfSave - stopAtr * atr, tickcolor = GetColor(3), arrowcolor = GetColor(3), name = "FlagStopLX");
AddOrder(OrderType.SELL_TO_CLOSE, close < Highest(close, trailStopLength) - trailStopAtr * atr, tickcolor = GetColor(4), arrowcolor = GetColor(4), name = "FlagTrailStopLX");
AddOrder(OrderType.SELL_TO_CLOSE, afterEntryCount > inactivityExitLength and close < entryPrice + inactivityAtr * atr, tickcolor = GetColor(5), arrowcolor = GetColor(5), name = "FlagInactivityLX");
AddOrder(OrderType.SELL_TO_CLOSE, afterEntryCount > timeExitLength, tickcolor = GetColor(6), arrowcolor = GetColor(6), name = "FlagTimeLX");
input aroonlength = 14;
Assert(aroonlength > 0, "'length' must be positive: " + aroonlength);
input rsilength = 8;
input price = close;
input averageType = AverageType.WILDERS;
def Up = (aroonlength - 1 - GetMaxValueOffset(high, aroonlength)) * 100.0 / (aroonlength - 1);
def Down = (aroonlength - 1 - GetMinValueOffset(low, aroonlength)) * 100.0 / (aroonlength - 1);
def rsi = RSI(rsilength, 70, 30, price, averageType).RSI;
def startOfScan = SecondsFromTime(0830) > 0 and secondsfromTime(0935);
def endOfScan = SecondsTillTime(1600) > 0 and secondstillTime(0930) and secondstillTime(0931) and secondstillTime(0932) and secondstillTime(0933) and secondstillTime(0934);
plot scanPeriod = startOfScan and endOfScan; scanPeriod.setDefaultColor(color.plum);
plot arooncross = Up[1] < Down[1] and Up equals 100 or down[1] < up [1] and down equals 100; arooncross.setDefaultColor(getcolor(3));
# scan for up line crossing above down line
plot scanup = Up equals 100 and rsi is greater than 70;
scanup.SetDefaultColor(GetColor(1));
# scan for down line crossing above up line
plot scanDown = Down equals 100 and rsi is less than 30;
scandown.SetDefaultColor(GetColor(2));
Alert(arooncross, "Main Cross", Alert.BAR, Sound.Chimes);
Hi, I am new to here and TOS.So, I discovered there's a function for the HistoricalEPS (https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Stock-Fundamentals), I've been playing around but have found no examples and so far have been unable to get any code to work because I don't know how the constant fiscalperiod.QUARTER is to be defined (e.g. =1? =Q1?).
Google search showed that basically no one uses these functions, but if I can figure out how to define the fiscalperiod I think we could swap that in instead of the corporate actions getearnings pull.
def EPS1 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, -1));
def EPS2 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, -2));
input EarningsTimes = 10;
def X = EarningsTimes;
def EPSYes = IF hasEarnings() then GetActualEarnings() else Double.NaN;
def EPScount = if !IsNan(EPSYes) THEN IF IsNan(EPScount[1]) THEN 1 ELSE EPScount[1] + 1 ElSE EPScount[1];
def Split1 = IF GetSplitDenominator() or GetSplitNumerator() then GetSplitDenominator() else Double.NaN;
def Splitcount1 = if !IsNan(Split1) THEN IF IsNan(Splitcount1[1]) THEN 1 ELSE Splitcount1[1] + 1 ElSE Splitcount1[1];
AddLabel(Yes, "EPS Reports: " + EPScount + " ("+X+") ", if Splitcount1>0 then color.red else color.light_GRAY);
def EPS1 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, X-1));
def EPS2 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, X-2));
def EPS3 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, X-3));
def EPS4 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, X-4));
def EPS5 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, X-5));
def EPS6 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, X-6));
def EPS7 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, X-7));
def EPS8 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, X-8));
def EPS9 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, X-9));
def EPS10 = GetValue(GetActualEarnings(), GetEventOffset(Events.EARNINGS, X-10));
def EPS5a = if EPS5<0 then EPS5*-1 else EPS5;
def EPS6a = if EPS6<0 then EPS6*-1 else EPS6;
def EPS7a = if EPS7<0 then EPS7*-1 else EPS7;
def EPS8a = if EPS8<0 then EPS8*-1 else EPS8;
def EPS9a = if EPS9<0 then EPS9*-1 else EPS9;
def EPS10a = if EPS10<0 then EPS10*-1 else EPS10;
def C1 = (EPS1 - EPS5) / EPS5a * 100;
def C2 = (EPS2 - EPS6) / EPS6a * 100;
def C3 = (EPS3 - EPS7) / EPS7a * 100;
def C4 = (EPS4 - EPS8) / EPS8a * 100;
def C5 = (EPS5 - EPS9) / EPS9a * 100;
def C6 = (EPS6 - EPS10) / EPS10a * 100;
def isBar = BarNumber() == 1;
AddChartBubble(isBar, 100,
"[CQ] " + EPS1 + " (" + Round(C1,2) + "%)\n" +
"[Q3] " +EPS2 + " (" + Round(C2,2) + "%)\n" +
"[Q2] " +EPS3 + " (" + Round(C3,2) + "%)\n" +
"[Q1] " +EPS4 + " (" + Round(C4,2) + "%)\n" +
"[L 4] " +EPS5 + " (" + Round(C5,2) + "%)\n" +
"[L 3] " +EPS6 + " (" + Round(C6,2) + "%)\n"
, Color.WHITE, no);
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
W | Question about GetMaxValueOffset/GetMinValueOffset | Questions | 0 | |
D | Toggle question? | Questions | 2 | |
M | Question about scanner | Questions | 1 | |
SwingArm Question | Questions | 1 | ||
J | Completed Heikin_Ashi Indicator Question | Questions | 1 |