Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Re: Fun with ThinkScript
July 24, 2019 07:08PM
Hoping one of the genius coders here could help me setting up a scan that I can also turn into a dynamic watchlist. I have a simple Opening Range Breakout study with an alert when the opening range of the first 30 minutes is broken either up or down using a 5 minute chart. Can this be turned into a scan and a dynamic watchlist? Here is the code for the study:

input opentime = 0930;
input ORend = 1000;
def na = Double.NaN;
#
# Check if the opening range time is now
#
def ORActive = if GetLastDay() == GetDay() and SecondsFromTime(opentime) >= 0 and SecondsFromTime(ORend) < 0 then 1 else 0;
#
# Track the OR high and low
#
def ORHigh = if ORActive then high else na;
def ORLow = if ORActive then low else na;
#
# Plot the OR high and low
#
plot ORAH = if GetLastDay() != GetDay() or !ORActive then na else HighestAll(ORHigh);
plot ORAL = if GetLastDay() != GetDay() or !ORActive then na else LowestAll(ORLow);
plot ORH = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else HighestAll(ORHigh);
plot ORL = if GetLastDay() != GetDay() or SecondsFromTime(ORend) < 0 then na else LowestAll(ORLow);
#
# Formatting
#
ORAH.SetStyle(Curve.SHORT_DASH);
ORAL.SetStyle(Curve.SHORT_DASH);
ORAH.SetDefaultColor(Color.GREEN);
ORAL.SetDefaultColor(Color.RED);
ORH.SetStyle(Curve.SHORT_DASH);
ORL.SetStyle(Curve.SHORT_DASH);
ORH.SetDefaultColor(Color.GREEN);
ORL.SetDefaultColor(Color.RED);
#
# Add Cloud creates the shading
#
AddCloud(ORH, ORL);
AddCloud(ORAL, ORAH);
#
# Alerts:
#
def alerttrigger = if (high >= ORH and low <= ORH) or (high >= ORL and low <= ORL) then 1 else 0; #replace the 1 with your definition
# BLOCK CODE BELOW
input alerttext = "OR Breakout!";
input UseAlerts = {false, default true};
input AlertType = {default "BAR", "ONCE", "TICK"};
def at = AlertType;
input AlertSound = {"Bell", "Chimes", default "Ding", "NoSound", "Ring"};
Alert(alerttrigger and UseAlerts, alerttext, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);
Re: Fun with ThinkScript
July 25, 2019 12:44AM
Finally was able to get verified and logged into here. Really want to give a lot of thanks and appreciation to this board/forum and especially to Robert.
Re: Fun with ThinkScript
July 27, 2019 07:12PM
I've solved my Question.



Edited 2 time(s). Last edit at 07/28/2019 12:24PM by 1uni_verse.
Re: Fun with ThinkScript
July 28, 2019 06:47AM
I need help with a fairly easy thinkscript. I’d like a paint bar indicator for a candle with no wicks. I’m not at all good with coding. If Anyone out there can help it’s much appreciated. Thanks
Symbol Crosses Moving Average Alert
July 28, 2019 12:29PM
I need help to add "within 2 bars" of this script. I think the Scan script is by thinkorswim


#Hint: The MovingAverage Scan allows you to filter out securities that have a Moving Average that is any given percent above or below then securities current price.
#Wizard text: The 
#Wizard input: price
#Wizard text: is at least 
#Wizard input: percentdiff
#Wizard text:% 
#Wizard input: choice
#Wizard text:   the  
#Wizard input: length
#Wizard text:  period
#Wizard input: AverageType
#Wizard text:  Moving Average


input price = close;
input length = 4;
input choice = {default "Above"};
input AverageType = averageType.EXPONENTIAL;
input percentdiff = 1;
def avg = movingAverage(averageType,price,length);

plot scan;
    scan = price >= avg * (1 + percentdiff / 100 )  within 2 bars;

The plot is picking up symbols that have been above the MA at least 2 bars. I want it to pick up instruments that are above the MA up to only 2 bars . Any help would be appreciated. Thanks!
Fibonacci
July 27, 2019 09:51PM
Does anyone have a Fibonacci code for thinkorswim?
Elliot wave
July 27, 2019 09:50PM
Does anyone have an elliot wave code for thinkorswim?
Elliot Wave
July 26, 2019 11:37PM
Does anyone have an Elliot Wave Alert for thinkorswim?
Re: Fibonacci
July 30, 2019 11:43AM
krazythinkorswim Wrote:
-------------------------------------------------------
> Does anyone have a Fibonacci code for thinkorswim?

See below

#hint: <b>Fibonacci Retracements</b>\nFibonacci retracements use horizontal lines to indicate areas of support or resistance at the key Fibonacci levels before it continues in the original direction. These levels are created by drawing a trendline between two extreme points and then dividing the vertical distance by the key Fibonacci ratios of: 23.6%, 38.2%, 50%, 61.8%, 78.6%, and 100%.


#hint Price: Price used in the alerts on crossing retracement lines. <b>(Default is Close)</b>
#hint onExpansion: Determines if the retracement lines are projected past the current bar into the right side expansion <b>(Default is Yes)</b>
#hint Extend_to_left: Determines if the retracement lines are extended to the left side of the chart. <b>(Default is No)</b>

#hint Coefficient0: Retracement Line 0: Retracement from the highest high to the lowest low.\n <b>(Default is 0%)</b>
#hint Coefficient_1: Retracement Line 1: Retracement from the highest high to the lowest low.\n <b>(Default is 23.6%)</b> 
#hint Coefficient_2: Retracement Line 2: Retracement from the highest high to the lowest low.\n <b>(Default is 38.2%)</b>
#hint Coefficient_3: Retracement Line 3: Retracement from the highest high to the lowest low.\n <b>(Default is 50%)</b>
#hint Coefficient_4: Retracement Line 4: Retracement from the highest high to the lowest low.\n <b>(Default is 61.8%)</b>
#hint Coefficient_5: Retracement Line 5: Retracement from the highest high to the lowest low.\n <b>(Default is 78.6%)</b>
#hint Coefficient_6: Retracement Line 6: Retracement from the highest high to the lowest low.\n <b>(Default is 100%)</b>

#wizard input: Price
#wizard text: Inputs: Price:
#wizard input: onExpansion
#wizard text: onExpansion:
#wizard input: Extend_to_left
#wizard text: Extend_to_left:
#wizard input: Coefficient0 
#wizard text: Coefficient0:
#wizard input: Coefficient_1 
#wizard text: Coefficient_1:
#wizard input: Coefficient_2 
#wizard text: Coefficient_2:
#wizard input: Coefficient_3 
#wizard text: Coefficient_3:
#wizard input: Coefficient_4
#wizard text: Coefficient_4:
#wizard input: Coefficient_5
#wizard text: Coefficient_5:
#wizard input: Coefficient_6 
#wizard text: Coefficient_6:

#SOURCE  [usethinkscript.com]
# COLORS and line style revised to match small dog auto fib
# USE this script with small dog autofib

input price = close;
input high = high;
input low = low;
input onExpansion = Yes;
input Extend_to_left = no;
input Coefficient0 = 0.000;
input coefficient_1 = .236;
input Coefficient_2 = .382;
input Coefficient_3 = .500;
input Coefficient_4 = .618;
Input Coefficient_5 = .786;
input Coefficient_6 = 1.000;




def a = HighestAll(high);
def b = LowestAll(low);
def barnumber = barNumber();
def c = if high == a then barnumber else double.nan;
def d = if low == b then barnumber else double.nan;
rec highnumber = compoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = compoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);

def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;

def x = AbsValue(lownumberall - highnumberall );

def slope = (a - b) / x;
def slopelow = (b - a) / x;

def day = getDay();
def month = getMonth();
def year = getYear();
def lastDay = getLastDay();
def lastmonth = getLastMonth();
def lastyear = getLastYear();
def isToday = if(day == lastDay and month == lastmonth and year == lastyear, 1, 0);
def istodaybarnumber = HighestAll(if isToday then barnumber else double.nan);

def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));

def currentlinelow = if barnumber <= lownumberall then linelow else double.nan;
def currentline = if barnumber <= highnumberall then line else double.nan;

Plot FibFan =  if  downward then currentlinelow else if upward then currentline else double.nan;
FibFan.SetStyle(Curve.SHORT_DASH);
FibFan.AssignValueColor(color.red);
fibfan.hidebubble();

def range =  a - b;

Plot Retracement0 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient0))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient0)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient0))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient0)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient0))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient0)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient0))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient0)) else double.nan;
Retracement0.assignvaluecolor(color.red);
retracement0.hidebubble();
Retracement0.SetStyle(Curve.FIRM);
#AddChartBubble((barnumber == istodaybarnumber +10), retracement0, concat( "$", round(retracement0, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement0, concat( (coefficient0 * 100), "%"winking smiley, color.red, yes);
AddChartBubble((upward and barnumber == lownumberall), retracement0, concat( (coefficient0 * 100), "%"winking smiley, color.red, yes);

## Retracement 1 = 0.236
Plot Retracement1 =  if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_1))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_1)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_1))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_1)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_1))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_1)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_1))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_1)) else double.nan;
Retracement1.assignvaluecolor(createcolor(46, 204, 113));
retracement1.hidebubble();
Retracement1.SetStyle(Curve.MEDIUM_DASH);
#AddChartBubble((barnumber == istodaybarnumber+10), retracement1, concat( "$", round(retracement1, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement1, concat( (coefficient_1 * 100), "%"winking smiley, (createcolor(46, 204, 113)));
AddChartBubble((upward and barnumber == lownumberall), retracement1, concat( (coefficient_1 * 100), "%"winking smiley, (createcolor(46, 204, 113)), yes);


## Retracement 2 = 0.382
Plot Retracement2 =if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_2))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_2)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_2))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_2)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_2))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_2)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_2))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_2)) else double.nan;
Retracement2.assignvaluecolor((createcolor(0,0,255)));
retracement2.hidebubble();
Retracement2.SetStyle(Curve.LONG_DASH);
#AddChartBubble((barnumber == istodaybarnumber+10), retracement2, concat( "$", round(retracement2, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement2, concat( (coefficient_2 * 100), "%"winking smiley,(createcolor(0,0,255)), yes);
AddChartBubble((upward and barnumber == lownumberall), retracement2, concat( (coefficient_2 * 100), "%"winking smiley, (createcolor(204, 204, 255)), yes);

## Retracement 3 = 0.50
Plot Retracement3 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_3))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_3)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_3))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_3)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_3))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_3)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_3))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_3)) else double.nan;
Retracement3.assignvaluecolor((createcolor(255, 238, 88)));
retracement3.hidebubble();
Retracement3.SetStyle(Curve.LONG_DASH);
Retracement3.setLineWeight(2);
#AddChartBubble((barnumber == istodaybarnumber+10), retracement3, concat( "$", round(retracement3, 2)), color.red, yes);
#AddChartBubble((upward and barnumber == lownumberall), retracement3, concat( (coefficient_3 * 100), "%"winking smiley, (createcolor( 255, 238, 88)), yes);
AddChartBubble((downward and barnumber == highnumberall), retracement3, concat( (coefficient_3 * 100), "%"winking smiley, (createcolor( 255, 238, 88)), yes);
AddChartBubble((upward and barnumber == lownumberall), retracement3, concat( (coefficient_3 * 100), "%"winking smiley, (createcolor( 255, 238, 88)), yes);

##Coefficient_4 = .618
Plot Retracement4 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_4))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_4)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_4))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_4)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_4))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_4)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_4))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_4)) else double.nan;
Retracement4.assignvaluecolor((createcolor(0, 230, 255)));
retracement4.hidebubble();
Retracement4.SetStyle(Curve.MEDIUM_DASH);
#AddChartBubble((barnumber == istodaybarnumber+10), retracement4, concat( "$", round(retracement4, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement4, concat( (coefficient_4 * 100), "%"winking smiley, (createcolor(0, 230, 255)), yes);
AddChartBubble((upward and barnumber == lownumberall), retracement4, concat( (coefficient_4 * 100), "%"winking smiley, (createcolor(0, 230, 255)), yes);


## Coefficient_5 = .786;
Plot Retracement5 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_5))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_5)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_5))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_5)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_5))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_5)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_5))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_5)) else double.nan;
Retracement5.assignvaluecolor((createcolor(153, 0, 255)));
retracement5.hidebubble();
Retracement5.SetStyle(Curve.LONG_DASH);
#AddChartBubble((barnumber == istodaybarnumber+10), retracement5, concat( "$", round(retracement5, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement5, concat( (coefficient_5 * 100), "%"winking smiley, (createcolor(153, 0, 255)), yes);
AddChartBubble((upward and barnumber == lownumberall), retracement5, concat( (coefficient_5 * 100), "%"winking smiley, (createcolor(153, 0, 255)), yes);


Plot Retracement6 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_6))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_6)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_6))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_6)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_6))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_6)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_6))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_6)) else double.nan;
Retracement6.assignvaluecolor(color.red);
retracement6.hidebubble();
Retracement6.SetStyle(Curve.FIRM);
#AddChartBubble((barnumber == istodaybarnumber+10), retracement6, concat( "$", round(retracement6, 2)), color.red, yes);

AddChartBubble((downward and barnumber == highnumberall), retracement6, concat( (coefficient_6 * 100), "%"winking smiley, color.red, yes);
AddChartBubble((upward and barnumber == lownumberall), retracement6, concat( (coefficient_6 * 100), "%"winking smiley, color.red, yes);


alert((price crosses below Retracement0) , "Price crosses below Retracement Line 0"winking smiley;
alert((price crosses above Retracement0) , "Price crosses above Retracement Line 0"winking smiley;
alert((price crosses below Retracement1) , "Price crosses below Retracement Line 1"winking smiley;
alert((price crosses above Retracement1) , "Price crosses above Retracement Line 1"winking smiley;
alert((price crosses below Retracement2) , "Price crosses below Retracement Line 2"winking smiley;
alert((price crosses above Retracement2) , "Price crosses above Retracement Line 2"winking smiley;
alert((price crosses below Retracement3) , "Price crosses below Retracement Line 3"winking smiley;
alert((price crosses above Retracement3) , "Price crosses above Retracement Line 3"winking smiley;
alert((price crosses below Retracement4) , "Price crosses below Retracement Line 4"winking smiley;
alert((price crosses above Retracement4) , "Price crosses above Retracement Line 4"winking smiley;
alert((price crosses below Retracement5) , "Price crosses below Retracement Line 5"winking smiley;
alert((price crosses above Retracement5) , "Price crosses above Retracement Line 5"winking smiley;
alert((price crosses below Retracement6) , "Price crosses below Retracement Line 6"winking smiley;
alert((price crosses above Retracement6) , "Price crosses above Retracement Line 6"winking smiley;
Re: Fun with ThinkScript
August 03, 2019 12:59PM


[i.imgur.com]

Image

Multi time frame (MTF) On-Balance Volume (OBV) custom thinkorswim TOS indicator.
Signals Reversal when current OBV(yellow) crossover the longer term OBV(blue).

Looking to see if anyone could help make something like this?



Edited 1 time(s). Last edit at 08/03/2019 01:01PM by 1uni_verse.
Re: Fun with ThinkScript
August 04, 2019 04:51AM
netarchitect

If I un-comment your lines what I got in the scan is :

com.devexperts.tos.thinkscript.runtime.TooComplexException: The complexity of the expression suggests that it may not be reliable with real-time data.

So, it doesn't allow to save the script. Scan are know for not accepting (working well ) with complex studies.
Multi time frame (MTF) On-Balance Volume (OBV)
August 04, 2019 04:59AM
Hi

I have shown some examples coding multi-ttime frames in an indicator. Please search my post.

Rgds
R
The Schaff Trend Cycle
August 04, 2019 05:16AM
Coding for TOS from Francesco original



# [www.prorealcode.com]

#From Prorealcode to TOS by Rigel
# [researchtrade.com]


declare lower;
#//input parameters
input TCLen = 10;
input MA1 = 23;
input MA2 = 50;

def Factor= 0.5;


# //{Calculate a MACD Line}
def XMAC = ExpAverage(Close,MA1) - ExpAverage(Close,MA2);

# //{1st Stochastic: Calculate Stochastic of a MACD}
def Value1 = Lowest(XMAC,TCLen);
def Value2 = Highest(XMAC,TCLen) - Value1;

# //{%Fast K of MACD}
def Frac1= if Value2 > 0 then
   ((XMAC - Value1)/Value2) * 100
 else
   Frac1[1];


# //{Smoothed Calculation for % Fast D of MACD}
def PF = PF[1] + (Factor * (Frac1 - PF[1]));

# //{2nd Stochastic: DCalculate Stochastic of smoothed Percent Fast D, 'PF', above}
def Value3 = Lowest(PF,TCLen);
def Value4 = Highest(PF,TCLen) - Value3;

# //{% of Fast K of PF}
def Frac2= if Value4 > 0 then
  ((PF - Value3)/Value4) * 100
 else
   Frac2[1];

# //{Smoothed Calculation for %Fast D of PF}
def PFF = PFF[1] + (Factor * (Frac2 - PFF[1]));
plot SFTC=PFF;

#plot horizontal lines
plot OverSold = 25;
plot OverBought = 75;



Edited 1 time(s). Last edit at 08/04/2019 05:17AM by rigel.
Re: Multi time frame (MTF) On-Balance Volume (OBV)
August 04, 2019 12:43PM
Doesn't address what I'm looking for.I don't care about the mtf part, per se, I just think it may be what's behind the indicator. I'm trying to replicate what's pictured and I think the workings behind it are just two OBV's but with different settings, but I'm not sure and looking for help in identifying that and possibly recreating it.

Mind you I've played with the settings of the obv you had posted awhile ago before you even mentioned looking back at your posts (I've gone through every page of this forum) and putting two together with those different settings to see if results elicit similar to what i'm wanting to replicate but it wasn't that great of results, I may try to mess with it more though.



Edited 1 time(s). Last edit at 08/04/2019 12:49PM by 1uni_verse.
Re: Fun with ThinkScript
August 04, 2019 12:45PM
EDIT: I'VE SOLD IT!


Anybody can help seems like simple request, I just want to be able to add text for given outcome. The first set of parenthesis doesn't work because it just makes everything that label. I would like if bulldiv is true then add "text" and if beardiv is true then "text".

AddLabel(yes, " " +(Round(uptrendcounter + downTrendCounter, 2)), if bulldiv > 0 then color.green else if beardiv < -0 then Color.red else Color.black);

Solved

AddLabel(yes, " Smi: " +(" X: "+(Round(uptrendcounter + downTrendCounter, 1))) + (" Y: "+(Round(bulldiv + beardiv, 2))), if bulldiv > 0 then color.uptick else if beardiv < -0 then color.downtick else Color.black);



Edited 1 time(s). Last edit at 08/04/2019 06:47PM by 1uni_verse.
Re: Multi time frame (MTF) On-Balance Volume (OBV)
August 06, 2019 12:36PM
Quote
1uni_verse
I just think it may be what's behind the indicator. I'm trying to replicate what's pictured and I think the workings behind it are just two OBV's but with different settings

All depends on how you want to program it.
As you seem to want two OBV, one with whatever the chart TF is (5 min, 15 min, etc) and a OBV with time frame week, then you can code the couple in the same indicator

See here



Edited 2 time(s). Last edit at 08/06/2019 12:45PM by rigel.
Re: Fun with ThinkScript
August 11, 2019 03:52PM
Hello genius coders, hoping there is an easy way to add a red or green arrow indicator to a chart whenever there is a candle close above or below the 9ema. Thank you in advance.
how to find alternating high and low values within X bars
August 15, 2019 11:34AM
Hi,
How would I find alternating highs and lows of a source value?

source = moving average for example...

what I am looking to do is find:

barnumberA = barnumber of highest(source,100);
valueA = source at barnumberA

barnumberB = barnumber of lowest(source,barnumberA);
valueB = source at barnumberB

barnumberC = barnumber of highest(source,barnumbercool smiley;
valueC = source at barnumberC

barnumberD = barnumber of lowest(source,barnumberC);
valueD = source at barnumberD

Unfortunately, the lengths cannot be dynamic and are throwing errors.

Any help would be greatly appreciated!

Bill
Re: how to find alternating high and low values within X bars
August 15, 2019 02:50PM
Do you want the four values (A,B,C,D) or the "n" values that can happen in your time frame?
Re: how to find alternating high and low values within X bars
August 15, 2019 05:24PM
I want the 4 values and the 4 bar numbers associated with each value.
Re: how to find alternating high and low values within X bars
August 16, 2019 11:20AM
You can do it using getValue(source, i) where i is a variable to iterate bar numbers.


You will need to use getValue in a fold loop.

For example to find the highest value:

def valueA = fold i = 1 to 100 with sourcemax=0 do if getValue(source, i) >sourcemax then getValue(source, i) else sourcemax;

Now for the bar number:

def barnumberA = fold m= 1 to 100 do if getValue(source,m) ==valueA then m else 0;

Haven't tested that, but I think you get the idea.
Re: Fun with ThinkScript
August 18, 2019 06:35PM
Does anyone have anything regarding Moon Cycles? I'm very interested in finding ToS Moon Phase indicators.
Re: how to find alternating high and low values within X bars
August 18, 2019 10:09PM
Thanks for the help rigel!

I'll play around with the code you provided.

Funny... "but I think you get the idea."

I don't know why, but the FOLD is just so confusing to me.

I was kind of on the same path but so far my FOLD statement, while syntactically correct, only returns a result visible in the land of missing socks!

Bill
Price Movement
August 18, 2019 02:16PM
Hello,
I would like to keep track of the number of times (count) that the price moves up and moves down within a 20-minute period. I assume I'd have to script on the 1-minute bars, the logic being something like this:

if close < close[1] then increment lowerprice counter else increment higherprice counter

I've been reading about looping with fold, but I'm not comfortable with it yet. My struggle is with how to make the loop start at the beginning of the 20 minutes and end at the 20-minute expiration.

Thank you in advance.
Re: Fun with ThinkScript
August 20, 2019 07:39AM
Newbie here. Trying to write a think or swim script but having some difficulties. What I am trying to do is signal an alert when a bearish outside bar crosses the 25 ema

input length = 25;
input displace = 0;
input showBreakoutSignals = no;
#defining engulfing bars
def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
BodyMin < BodyMin[1];
#defining the bullish / bearish signals
def bullish_signal = ExpAverage(price[-displace], length < over_Sold and Isengulfing and close > open;
def bearish_signal = ExpAverage(price[-displace], length > over_Bought and Isengulfing and close < open;
#plotting the bullish / bearish signals
plot bullish = bullish_signal;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot bearish = bearish_signal;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
alert(bullish_signal, “BULLISH ENGULFING”, alert.bar, sound.Ring);
alert(bearish_signal, “BEARISH ENGULFING”, alert.bar, sound.Ring);
Re: how to find alternating high and low values within X bars
August 20, 2019 04:25PM
If you post your code we can have a look together
Re: Fun with ThinkScript
August 21, 2019 07:37AM
Can someone help me with this code for a conditional order?

input trgprice= 100;
input PercentVolChng=10;
input pricATRChange=2;

plot trg = close less then trgprice and volume less then
1+(PercentvolChng/100)*VolumeAvg("length"=30)."vol" and close Less then
close[1]+pricATRChange*ATR();
Re: Fun with ThinkScript
August 21, 2019 08:45PM
It is possible to control how far the extensions lines go to? For example, on a change of direction of an ema, sma, etc, I draw rays from that turning point out from the price chart into space.

Not horizontal lines, but rays or extensions that plot depending of the angle. A line painting strategy can no be used as it plot continuously. Now, I painting strategy type dots, it does paint with an auto limitation.

It looks like the line starts where the study line changes direction and comes out as a ray from the chart, but then it ends where the next direction starts.

It is possible to control how far it goes? Thanks.
Re: Fun with ThinkScript
August 22, 2019 10:28PM
I have TOS code that automatically plots fibonacci lines from the previos day close and the close of the first 5 min bar of the next day. It works great with gap ups but I cant figure out how get it to work with gap downs? Any help? Also, help adding chart bubbles to the lines. Thanks in advance.

input targetTime = 1555;
input fibOne = 127.2;
input fibTwo = 161.8;
Input fibThree = 261.8;
Input fibFour = 88.7;
Input fibFive = 78.6;
Input fibSix = 61.8;
input marketOpen = 1555;
input marketClose = 930;
def targetBarStart = SecondsFromTime(targetTime) == 0;
def targetBarEnd = SecondsFromTime(marketClose) == 0;
rec targetCloseStart = if targetBarStart then close else targetCloseStart[1];
rec targetCloseEnd = if targetBarEnd then close else targetCloseEnd[1];
def startCounter = SecondsFromTime(marketOpen);
def endCounter = SecondsTillTime(marketClose);
def targetHours = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
plot today = targetCloseEnd;
plot yesterday = targetCloseStart;
def range = if !targetHours then today – yesterday else Double.NaN;
plot fibLevelOne = if range > 0 then (range * (fibOne * 0.01)) + yesterday else Double.NaN;
plot fibLevelTwo = if range > 0 then (range * (fibTwo * 0.01)) + yesterday else Double.NaN;
plot fibLevelThree = if range > 0 then (range * (fibThree * 0.01)) + yesterday else Double.NaN;
plot fibLevelFour = if range > 0 then (range * (fibFour * 0.01)) + yesterday else Double.NaN;
plot fibLevelFive = if range > 0 then (range * (fibFive * 0.01)) + yesterday else Double.NaN;
plot fibLevelSix = if range > 0 then (range * (fibSix * 0.01)) + yesterday else Double.NaN;
help with my autofib direction
August 22, 2019 10:27PM
I have TOS code that automatically plots fibonacci lines from the previos day close and the close of the first 5 min bar of the next day. It works great with gap ups but I cant figure out how get it to work with gap downs? Any help? Also, help adding chart bubbles to the lines. Thanks in advance.

input targetTime = 1555;
input fibOne = 127.2;
input fibTwo = 161.8;
Input fibThree = 261.8;
Input fibFour = 88.7;
Input fibFive = 78.6;
Input fibSix = 61.8;
input marketOpen = 1555;
input marketClose = 930;
def targetBarStart = SecondsFromTime(targetTime) == 0;
def targetBarEnd = SecondsFromTime(marketClose) == 0;
rec targetCloseStart = if targetBarStart then close else targetCloseStart[1];
rec targetCloseEnd = if targetBarEnd then close else targetCloseEnd[1];
def startCounter = SecondsFromTime(marketOpen);
def endCounter = SecondsTillTime(marketClose);
def targetHours = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
plot today = targetCloseEnd;
plot yesterday = targetCloseStart;
def range = if !targetHours then today – yesterday else Double.NaN;
plot fibLevelOne = if range > 0 then (range * (fibOne * 0.01)) + yesterday else Double.NaN;
plot fibLevelTwo = if range > 0 then (range * (fibTwo * 0.01)) + yesterday else Double.NaN;
plot fibLevelThree = if range > 0 then (range * (fibThree * 0.01)) + yesterday else Double.NaN;
plot fibLevelFour = if range > 0 then (range * (fibFour * 0.01)) + yesterday else Double.NaN;
plot fibLevelFive = if range > 0 then (range * (fibFive * 0.01)) + yesterday else Double.NaN;
plot fibLevelSix = if range > 0 then (range * (fibSix * 0.01)) + yesterday else Double.NaN;
Sorry, only registered users may post in this forum.

Click here to login