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
August 21, 2014 10:37PM
Hey Robert -

I've been messing around with the code you rewrote for Wes on page 11 the # 30 min opening range with fib retracements but the only thing I can't figure out is how to prevent it from showing up in pre-market. It's only annoying because the drawing pre-market is from the previous day, not the current day.





Edited 2 time(s). Last edit at 08/21/2014 10:39PM by Exgamer.
Re: Fun with ThinkScript
August 22, 2014 12:38AM
Quote
exgamer
I've been messing around with the code you rewrote for Wes on page 11 the # 30 min opening range with fib retracements but the only thing I can't figure out is how to prevent it from showing up in pre-market. It's only annoying because the drawing pre-market is from the previous day, not the current day.

I have extended hours turned off on all of my charts so I never think to incorporate that time of day into my codes. It's an easy enough fix, though. For example:

change

plot h30 = if !today then Double.NaN else OR30high;


to

plot h30 = if !today or secondstilltime(0930) > 0 then Double.NaN else OR30high;


Changing the rest of the plot functions in similar fashion should resolve your issue.

edited to clean up formatting errors.



Edited 2 time(s). Last edit at 08/22/2014 06:01AM by robert.
Re: Fun with ThinkScript
August 22, 2014 07:56AM
Robert,
I compared the charts to others that were done manually on excel and they look very close.
Thank you again for your help.
I will hit you next week with something else smiling smiley

Adrian
Re: Fun with ThinkScript
August 22, 2014 11:55AM
Great, thanks Robert. I knew it was secondstilltime, but I was changing it at bar10am instead of adding it to the plot. Thanks again.

-Marcus
Re: Fun with ThinkScript
September 04, 2014 09:26AM
Robert,

I want to express my thanks again for the work that you've done with TOS. I love what you've put together!
Re: Fun with ThinkScript
September 04, 2014 05:55PM
Quote
funkho
Robert,

I want to express my thanks again for the work that you've done with TOS. I love what you've put together!

Thanks. Glad the scripts are working out for you. By the way, I saw your screenshot on Darcy's thread (wow, super-wide monitor; very nice) and thought you might find this bit of code useful. It just adds a label for the charting timeframe, but I find it useful to keep things straight.



If you want it in front of your edge indicators, just move it to the top of the stack when you are setting up your upper-chart scripts.



DefineGlobalColor("time", CreateColor(148, 214, 232));

def nMinutes = GetAggregationPeriod() / 60000;
def Weekly = if nMinutes == 10080 then 1 else Double.NaN;
def Daily = if nMinutes == 1440 then 1 else Double.NaN;
def Intraday = if nMinutes < 1440 then 1 else Double.NaN;

AddLabel(Weekly, "Weekly", GlobalColor("time" ));
AddLabel(Daily, "Daily", GlobalColor("time" ));
AddLabel(Intraday, nMinutes + " min", GlobalColor("time" ));
Re: Fun with ThinkScript
September 05, 2014 04:01PM
I woke up at around 2:30 this morning because I just couldn't sleep, so I did what I normally do in that situation---I tinkered with some Thinkscript. I decided to add a strength meter to my e-chart signals. The strength meter takes into account such things as: are the moving average lines sloping up or down, is the candle up or down, is the current close higher or lower than the previous close, and is the current close above or below the moving averages.

Since I just wrote this this morning, I haven't really messed with it much. What I'm thinking, though, is to use it as a means of weeding out false signals. Maybe waiting until I have at least two or three bars on the strength meter before entering an E trade.

I know that several of you use these scripts and are better traders than I am so I would welcome feedback regarding whether or not this seems beneficial to you and how you decide to use it.

At any rate, here's rev 3 of my e-signal script if anyone wants it.



# E-Charts v3

declare upper;
input short_average = 5;
input medium_average = 10;
input long_average = 20;
input average_type = {default "SMA", "EMA"};
input showArrows = yes;

def MA1;
def MA2;
def MA3;
switch (average_type) {
case "SMA":
    MA1 = Average(close, short_average);
    MA2 = Average(close, medium_average);
    MA3 = Average(close, long_average);
case "EMA":
    MA1 = ExpAverage(close, short_average);
    MA2 = ExpAverage(close, medium_average);
    MA3 = ExpAverage(close, long_average);
}

# define e-signal and crossover point
def Eup = MA1 > MA2 && MA2 > MA3;
def Edn = MA1 < MA2 && MA2 < MA3;

def CrossUp = close > MA1 && Eup && !Eup[1];
def CrossDn = close < MA1 && Edn && !Edn[1];

# Define up and down signals
def higherHigh = close > Highest(Max(open, close), 3)[1];
def lowerLow = close < Lowest(Min(open, close), 3)[1];
def SignalUp = if (CrossUp && higherHigh)
    then 1
        else if    (CrossUp[1] && higherHigh && !higherHigh[1])
    then 1
        else if    (CrossUp[2] && higherHigh && !higherHigh[1] && !higherHigh[2])
    then 1
        else Double.NaN;
def SignalDn = if (CrossDn && lowerLow)
    then 1
        else if (CrossDn[1] && lowerLow && !lowerLow[1])
    then 1
        else if (CrossDn[2] && lowerLow && !lowerLow[1] && !lowerLow[2])
    then 1
        else Double.NaN;

# Plot the moving average lines
plot ln1 = MA1;
     ln1.SetDefaultColor(CreateColor(145, 210, 144));
     ln1.SetLineWeight(2);
plot ln2 = MA2;
     ln2.SetDefaultColor(CreateColor(111, 183, 214));
     ln2.SetLineWeight(2);
plot ln3 = MA3;
     ln3.SetDefaultColor(CreateColor(249, 140, 182));
     ln3.SetLineWeight(2);
    
# Show an arrow
plot ArrowUp = if SignalUp and showArrows then low * 0.997 else Double.NaN;
     ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
     ArrowUp.SetLineWeight(4);
     ArrowUp.SetDefaultColor(Color.YELLOW);
plot ArrowDn = if SignalDn and showArrows then high * 1.003 else Double.NaN;
     ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
     ArrowDn.SetLineWeight(4);
     ArrowDn.SetDefaultColor(Color.CYAN);

# Add label for Eup or Edn
AddLabel(Eup, "E Up", CreateColor(134, 202, 93));
AddLabel(Edn, "E Dn", CreateColor(232, 148, 157));

# Calculate Meter Values
def sl1 = ma1 > ma1[1];
def sl2 = ma2 > ma2[1];
def sl3 = ma3 > ma3[1];
def p1 = close > ma1;
def p2 = close > ma2;
def p3 = close > ma3;
def u1 = 2 * (close > open);
def u2 = 2 * (close > high[1]);
def d1 = 2 * (close < open);
def d2 = 2 * (close < low[1]);

def UPstr = sl1 + sl2 + sl3 + p1 + p2 + p3 + u1 + u2;
def DNstr = !sl1 + !sl2 + !sl3 + !p1 +!p2 + !p3 + d1 + d2;

# Add Strength Meter
AddLabel(Eup or Edn, " ", if Eup and UPstr >= 3 then CreateColor(128, 199, 94) else if Edn and DNstr >= 3 then CreateColor(232, 143, 153) else CreateColor(177,177,166));
AddLabel(Eup or Edn, " ", if Eup and UPstr >= 6 then CreateColor(99, 197, 72) else if Edn and DNstr >= 6 then CreateColor(238, 123, 136) else CreateColor(177,177,166));
AddLabel(Eup or Edn, " ", if Eup and UPstr >= 8 then CreateColor(65, 195, 50) else if Edn and DNstr >= 8 then CreateColor(245, 101, 117) else CreateColor(177,177,166));
AddLabel(Eup or Edn, " ", if Eup and UPstr == 10 then CreateColor(41, 192, 36) else if Edn and DNstr == 10 then CreateColor(249, 81, 101) else CreateColor(177,177,166));

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
September 06, 2014 12:04PM
robert Wrote:
-------------------------------------------------------
> > I tried to add " RelativeMomentumIndex"
> indicator to that script instead of FISHER
> indicator with this value but I couldn't confused smiley
>
>
>
> # macd
> def Value = MACD(2, 5, 2, "EMA" ).Value;
> def Avg = MACD(2, 5, 2, "EMA" ).Avg;
> def MACDup = Value > Avg;
> def MACDdn = Value <= Avg;
>
> # stochslow
> def SlowD = StochasticFull(80, 30, 2, 2, hlc3,
> hlc3, hlc3, 3, "EMA" ).FullD;
> def SlowDup = SlowD crosses above 30;
> def SlowDdn = SlowD crosses below 80;
>
> # CCI
> def CCI = CCI(7);
> def CCIup = CCI crosses above -100;
> def CCIdn = CCI crosses below 100;
>
> # MFI
> def MFIup = MoneyFlowIndex(length =
> 1).MoneyFlowIndex crosses above 20;
> def MFIdn = MoneyFlowIndex(length =
> 1).MoneyFlowIndex crosses below 80;
>
> # RMI
> def emaInc = ExpAverage(Max(close - close[5], 0),
> 5);
> def emaDec = ExpAverage(Max(close[5] - close, 0),
> 5);
> def RMI = if emaDec == 0 then 0 else 100 - 100 /
> (1 + emaInc / emaDec);
> def RMIob = RMI >= 75;
> def RMIos = RMI <= 25;
>
> # Signals
> plot signalUP = MACDup and SlowDup and CCIup and
> MFIup and RMIos;
>
> signalUP.SetPaintingStrategy(PaintingStrategy.BOOL
> EAN_ARROW_UP);
> signalUP.SetLineWeight(3);
> signalUP.SetDefaultColor(Color.LIGHT_GREEN);
> plot signalDN = MACDdn and SlowDdn and CCIdn and
> MFIdn and RMIob;
>
> signalDN.SetPaintingStrategy(PaintingStrategy.BOOL
> EAN_ARROW_DOWN);
> signalDN.SetLineWeight(3);
> signalDN.SetDefaultColor(Color.PINK);
>
__________________________________________________________________

Can't be in a watch list signal ?
Re: Fun with ThinkScript
September 07, 2014 02:32AM
Quote
Sara
Can't be in a watch list signal ?

Here you are. Just be aware that while this works fine after-hours, it may not give the desired results real-time when the market it open.



# Complex UP Signal
def Value = MACD(2, 5, 2, "EMA" ).Value;
def Avg = MACD(2, 5, 2, "EMA" ).Avg;
def MACDup = Value > Avg;

def SlowD = StochasticFull(80, 30, 2, 2, hlc3, hlc3, hlc3, 3, "EMA" ).FullD;
def SlowDup = SlowD crosses above 30;

def CCI = CCI(7);
def CCIup = CCI crosses above -100;

def MFIup = MoneyFlowIndex(length = 1).MoneyFlowIndex crosses above 20;

def emaInc = ExpAverage(Max(close - close[5], 0), 5);
def emaDec = ExpAverage(Max(close[5] - close, 0), 5);
def RMI = if emaDec == 0 then 0 else 100 - 100 / (1 + emaInc / emaDec);
def RMIob = RMI >= 75;
def RMIos = RMI <= 25;

plot signalUP = MACDup and SlowDup and CCIup and MFIup and RMIos;
     signalUP.assignValueColor(if signalUP then color.green else color.light_gray);
     assignBackgroundColor(if signalup then color.green else color.light_gray);

# Complex Down Signal
def Value = MACD(2, 5, 2, "EMA" ).Value;
def Avg = MACD(2, 5, 2, "EMA" ).Avg;
def MACDdn = Value <= Avg;

def SlowD = StochasticFull(80, 30, 2, 2, hlc3, hlc3, hlc3, 3, "EMA" ).FullD;
def SlowDdn = SlowD crosses below 80;

def CCI = CCI(7);
def CCIdn = CCI crosses below 100;

def MFIdn = MoneyFlowIndex(length = 1).MoneyFlowIndex crosses below 80;

def emaInc = ExpAverage(Max(close - close[5], 0), 5);
def emaDec = ExpAverage(Max(close[5] - close, 0), 5);
def RMI = if emaDec == 0 then 0 else 100 - 100 / (1 + emaInc / emaDec);
def RMIob = RMI >= 75;

plot signalDN = MACDdn and SlowDdn and CCIdn and MFIdn and RMIob;
     signalDN.assignValueColor(if signalDN then color.red else color.light_gray);
     AssignBackgroundColor(if signalDN then color.red else color.light_gray);

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
September 07, 2014 07:43AM
Robert,
Can you make a watch list signal out of the code shown below, and have TOS send an email when there is a trigger?
Thank you,

Adrian

Based on TOS native Ichimoku indicator, daily bars:

Trigger for a long trade is when price (close) crosses above the Kijun
and the previous two closes are below the Kijun and the Chikou is above
the Kumo (cloud).

close > Kijun and close[1] < Kijun[1] and close[2] < Kijun[2] and Chikou[26] > SpanA[26] and Chikou[26] > SpanB[26];

Trigger for a short trade is when price (close) crosses below the Kijun
and the previous two closes are above the Kijun and the Chikou is below
the Kumo (cloud).

close < Kijun and close[1] > Kijun[1] and close[2] > Kijun[2] and Chikou[26] < SpanA[26] and Chikou[26] < SpanB[26];
Re: Fun with ThinkScript
September 07, 2014 09:09AM
Quote
meyer99
Trigger for a long trade is when price (close) crosses above the Kijun
and the previous two closes are below the Kijun and the Chikou is above
the Kumo (cloud).

close > Kijun and close[1] < Kijun[1] and close[2] < Kijun[2] and Chikou[26] > SpanA[26] and Chikou[26] > SpanB[26];

I'm not even the least bit familiar with Ichimoku charting. So take what I'm about to ask with a grain of salt. Are you sure you've given me the correct formula that you want to use? Based on your description, it doesn't make sense to me.

You say a long trigger is when the following conditions are met:
    1. price (close) crosses above the Kijun
      close > Kijun
      that translates to, "today's close is above today's Kijun" which makes sense
    2. the previous two closes are below the Kijun
       close[1] < Kijun[1] and close[2] < Kijun[2]
      that translates to, "yesterday's close was below yesterday's Kijun AND the day before yesterday's close was below the day before yesterday's Kijun" and that makes sense.
    3. the Chikou is above the Kumo (cloud)
      Chikou[26] > SpanA[26] and Chikou[26] > SpanB[26]
      * Ok...this one doesn't make sense to me because it translates to, "the Chikou from 26 days ago is above the SpanA from 26 days ago AND the Chikou from 26 days ago is above the SpanB from 26 days ago.
      * Are you sure you don't want today's Chikou is above today's SpanA like this:
      Chikou > SpanA and Chikou > SpanB
Re: Fun with ThinkScript
September 07, 2014 12:32PM
Robert,
Yes that is exactly what I want.
Thank you.
Re: Fun with ThinkScript
September 07, 2014 12:34PM
I mean 26 days ago is what I want.
Re: Fun with ThinkScript
September 07, 2014 12:50PM
Quote
meyer99
I mean 26 days ago is what I want.

Ok...give this a whirl.

# Ichimoku UP Alert
def Tenkan = (Highest(high, 9) + Lowest(low, 9)) / 2;
def Kijun = (Highest(high, 26) + Lowest(low, 26)) / 2;
def SpanA = (Tenkan[26] + Kijun[26]) / 2;
def SpanB = (Highest(high[26], 2 * 26) + Lowest(low[26], 2 * 26)) / 2;
def Chikou = close[-26];

plot SignalUP = close > Kijun and close[1] < Kijun[1] and close[2] < Kijun[2] and Chikou[26] > SpanA[26] and Chikou[26] > SpanB[26]; 
     SignalUP.assignValueColor(if SignalUP then color.green else color.gray);
     AssignBackgroundColor(if SignalUP then color.green else color.gray);
     
Alert(SignalUP, "Ichimoku alert for " + getsymbol(), Alert.bar, Sound.ding);

# Ichimoku DOWN Alert
def Tenkan = (Highest(high, 9) + Lowest(low, 9)) / 2;
def Kijun = (Highest(high, 26) + Lowest(low, 26)) / 2;
def SpanA = (Tenkan[26] + Kijun[26]) / 2;
def SpanB = (Highest(high[26], 2 * 26) + Lowest(low[26], 2 * 26)) / 2;
def Chikou = close[-26];

plot SignalDN = close < Kijun and close[1] > Kijun[1] and close[2] > Kijun[2] and Chikou[26] < SpanA[26] and Chikou[26] < SpanB[26];
     SignalDN.assignValueColor(if SignalDN then color.red else color.gray);
     AssignBackgroundColor(if signalDN then color.red else color.gray);
     
Alert(SignalDN, "Ichimoku alert for " + getsymbol(), Alert.bar, Sound.ding);

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
September 07, 2014 01:09PM
Robert,
Thank you. I will try it and let you know. The email notification is not part of the code?
Re: Fun with ThinkScript
September 07, 2014 01:14PM
Quote
meyer99
Thank you. I will try it and let you know. The email notification is not part of the code?

No. Email settings are accessed from the Notifications tab of the Application Settings menu.

Re: Fun with ThinkScript
September 07, 2014 04:17PM
Robert,
Please see
[screencast.com]

It appears to be working OK, but not sure about the different colors. Solid grey and 0.00 in black background are no signals. Why different?
Solid green and 1 in green are signals, why the difference?
Not a big deal, just making sure I understand what I am getting.
Thank you again.
Re: Fun with ThinkScript
September 07, 2014 04:43PM
meyer99,

You can change the colors to whatever works best for you. Just pick from the chart below and substitute the desired color in the script.





Edited 1 time(s). Last edit at 09/07/2014 04:43PM by robert.
Re: Fun with ThinkScript
September 07, 2014 05:46PM
Robert,
I am sorry I did not ask the right question. How come sometimes I get a solid color and sometimes I get a number (0.0 and/or 1)?
Re: Fun with ThinkScript
September 07, 2014 06:05PM
Quote
meyer99
Robert,
I am sorry I did not ask the right question. How come sometimes I get a solid color and sometimes I get a number (0.0 and/or 1)?

I really think it has to do with the way the script is written. I brought up my concerns this morning, then tried to do exactly what you asked. I still think it should be changed.

Take a look at this (by the way, all of the definitions in the script posted above are taken directly from the official Thinkorswim Ichimokou calculations)

def Chikou = close[-26];

plot SignalUP = close > Kijun and close[1] < Kijun[1] and close[2] < Kijun[2] and Chikou[26] > SpanA[26] and Chikou[26] > SpanB[26];

def Chikou = close[-26] defines Chikou as the close 26 days in the future (that's what the [-26] means).

Then the actual SignalUP logic uses this bit of code Chikou[26] > SpanA[26] which is looking for Chikou from 26 days before (the [26]).

So let's think about this... if you define Chikou as the close 26 days in the future then want to check the value of Chikou 26 days before that, that would be today's close.

I think that asking the watch list screener to attempt to look into the future is causing it to function erratically. I think it would be better to change the code to reflect what it's really asking for (which is today's close not some future closing price).

I would remove def Chikou = close[-26] completely then redefine the SignalUP as:

plot SignalUP = close > Kijun and close[1] < Kijun[1] and close[2] < Kijun[2] and close > SpanA[26] and close > SpanB[26];

I believe you'll get better results with that bit of code.

Make similar changes to the SignalDN code then compare both results to what you already know of your Ichimokou signals and see if that doesn't work better for you.
Re: Fun with ThinkScript
September 07, 2014 06:25PM
Robert,
It works great. Thank you.
One more Q: how do I save this scan? In case I want to open a different watch list and apply same scan.
Re: Fun with ThinkScript
September 08, 2014 10:23AM
Hi,
I found this code on thinkscript (free) its called the 3X Oscillator code. I wanted to see if there is any way to add an option of using RSI Wilder (I choose the length, the overbought oversold, and if I want to use it in the calculation). Also the alert won't trigger in the original code.

# RHouser created 3X Oscillator code 
# RHouser modified to include alerts: bubbles and audio
# RHouser updated 5/18/12 due to FullD not being calculated 
# correctly by TOS
# Stochastic calculated using Lane's formulas
# Updated 5/23/12 - ability to turn on/off alert bubbles
# Place # before or delete last line of code should OB/OS 
# colored candles not to show on chart - code provided by
# by Achilles Dent 5/21/12

declare lower;

 

input K_period        = 10;

input D_period        = 10;

input SlowTrendLength = 3;

input smoothing_type  = { default EMA, SMA };

input stochastic_type = { FAST, default SLOW };

input over_bought     = 85;

input over_sold       = 25;

input show_bubbles    = yes;

input show_sec_bbls   = no;

input show_alerts     = no;

 

def aggPer            = getAggregationPeriod();

def adjAggPer         = if aggPer == AggregationPeriod.MIN then

                          AggregationPeriod.THREE_MIN

                        else if aggPer == AggregationPeriod.TWO_MIN then

                          AggregationPeriod.FIVE_MIN

                        else if aggPer == AggregationPeriod.THREE_MIN then

                          AggregationPeriod.TEN_MIN

                        else if aggPer == AggregationPeriod.FOUR_MIN then

                          AggregationPeriod.TEN_MIN

                        else if aggPer == AggregationPeriod.FIVE_MIN then

                          AggregationPeriod.FIFTEEN_MIN

                        else if aggPer == AggregationPeriod.TEN_MIN then

                          AggregationPeriod.THIRTY_MIN

                        else if aggPer == AggregationPeriod.FIFTEEN_MIN then

                          AggregationPeriod.HOUR

                        else if aggPer == AggregationPeriod.TWENTY_MIN then

                          AggregationPeriod.HOUR

                        else if aggPer == AggregationPeriod.THIRTY_MIN then

                          AggregationPeriod.TWO_HOURS

                        else if aggPer == AggregationPeriod.HOUR then

                          AggregationPeriod.FOUR_HOURS

                        else if aggPer == AggregationPeriod.TWO_HOURS then

                          AggregationPeriod.DAY

                        else if aggPer == AggregationPeriod.FOUR_HOURS then

                          AggregationPeriod.DAY

                        else if aggPer == AggregationPeriod.DAY then

                          AggregationPeriod.THREE_DAYS

                        else if aggPer == AggregationPeriod.TWO_DAYS then

                          AggregationPeriod.WEEK

                        else if aggPer == AggregationPeriod.THREE_DAYS then

                          AggregationPeriod.WEEK

                        else if aggPer == AggregationPeriod.FOUR_DAYS then

                          AggregationPeriod.MONTH

                        else if aggPer == AggregationPeriod.WEEK then

                          AggregationPeriod.MONTH

                        else if aggPer == AggregationPeriod.MONTH then

                          AggregationPeriod.MONTH

                        else

                          Double.NaN;

 

def _kPeriod;

def _dPeriod;

def _slowTrendLength;

if aggPer == AggregationPeriod.MONTH then {

  _kPeriod          = K_period * 3;

  _dPeriod          = D_period * 3;

  _slowTrendLength  = SlowTrendLength * 3;

} else {

  _kPeriod          = K_period;

  _dPeriod          = D_period;

  _slowTrendLength  = SlowTrendLength;

}

 

def priceH            = high( period = adjAggPer );

def priceL            = low( period = adjAggPer );

def priceC            = close( period = adjAggPer );

 

def lowest_low        = lowest( low, _kPeriod );

def highest_high      = highest( high, _kPeriod );

def fastK             = if ( highest_high - lowest_low ) <= 0 then 0 else 100 * ( close - lowest_low ) / ( highest_high - lowest_low );

def fastD             = if smoothing_type == smoothing_type.EMA then ExpAverage( fastK, _dPeriod ) else Average( fastK, _dPeriod );

def slowK             = fastD;

def slowD             = if smoothing_type == smoothing_type.EMA then ExpAverage( slowK, _dPeriod ) else Average( slowK, _dPeriod );

 

#---Stochastic

plot stochD            = if stochastic_type == stochastic_type.FAST then fastD else slowD;

stochD.SetPaintingStrategy( PaintingStrategy.POINTS );

stochD.AssignValueColor( if stochD >= stochD[1] then Color.CYAN else if stochD < stochD[1] then Color.BLUE else Color.GRAY );

 

#---Reference lines

plot OverBought       = over_bought;

OverBought.SetDefaultColor( Color.BLACK );

def Hundred           = 100;

AddCloud( OverBought, Hundred, Color.RED, Color.RED );

 

plot OverSold         = over_sold;

OverSold.SetDefaultColor( Color.BLACK );

def Zero              = 0;

AddCloud( OverSold, Zero, Color.YELLOW, Color.YELLOW );

 

#---Calculate primary buy/sell

def primaryBuy        = stochD >= OverSold   and stochD[1] < OverSold;

def primarySell       = stochD <= OverBought and stochD[1] > OverBought;

 

#---Calculate secondary buy/sell

def fastTrendUp       = stochD < stochD[-1];

def slowTrendUp       = stochD > stochD[_slowTrendLength];

def valley            =  fastTrendUp and !fastTrendUp[1] and stochD > OverSold;

def peak              = !fastTrendUp and  fastTrendUp[1] and stochD < OverBought;

def secondaryBuy      = valley and stochD < OverBought;

def secondarySell     = peak   and stochD > OverSold;

 

plot buy               = if primaryBuy or secondaryBuy then stochD else Double.NaN;

buy.DefineColor( "pBuy", Color.UPTICK );

buy.DefineColor( "sBuy", CreateColor( 0, 255, 0 ) );

buy.AssignValueColor( if primaryBuy then buy.color( "pBuy" ) else buy.color( "sBuy" ) );

buy.SetPaintingStrategy( PaintingStrategy.ARROW_UP );

buy.setHiding( show_bubbles );

 

plot sell              = if primarySell or secondarySell then stochD else Double.NaN;

sell.DefineColor( "pSell", Color.DOWNTICK );

sell.DefineColor( "sSell", Color.MAGENTA );

sell.AssignValueColor( if primarySell then sell.color( "pSell" ) else sell.color( "sSell" ) );

sell.SetPaintingStrategy( PaintingStrategy.ARROW_DOWN );

sell.setHiding( show_bubbles );

 

AddChartBubble( show_bubbles and primaryBuy, stochD, "pBUY", Color.UPTICK, no );

AddChartBubble( show_bubbles and show_sec_bbls and secondaryBuy, stochD, "sBUY", CreateColor( 0, 255, 0 ), no );

AddChartBubble( show_bubbles and primarySell, stochD, "pSELL", Color.DOWNTICK, yes );

AddChartBubble( show_bubbles and show_sec_bbls and secondarySell, stochD, "sSELL", Color.MAGENTA, yes );


alert( show_alerts and buy, if primaryBuy then concat( "Primary BUY @ ", close ) else concat( "Secondary BUY @ ", close ), Alert.BAR, Sound.Ring );

alert( show_alerts and sell, if primarySell then concat( "Primary SELL @ ", close ) else concat( "secondary SELL @ ", close ), Alert.BAR, Sound.Chimes );


AssignPriceColor(if slowk>80 then Color.cyan else if slowk<20 then color.pink else color.current);
Re: Fun with ThinkScript
September 08, 2014 06:37PM
Quote
strategynode
I found this code on thinkscript (free) its called the 3X Oscillator code. I wanted to see if there is any way to add an option of using RSI Wilder (I choose the length, the overbought oversold, and if I want to use it in the calculation). Also the alert won't trigger in the original code.

If you want the alerts to work, you need to ensure that you select "show alerts: yes" under settings and change the two alert lines to the following:

alert( show_alerts and (primaryBuy or secondaryBuy), if primaryBuy then concat( "Primary BUY @ ", close ) else concat( "Secondary BUY @ ", close ), Alert.BAR, Sound.Ring );

alert( show_alerts and (primarySell or secondarySell), if primarySell then concat( "Primary SELL @ ", close ) else concat( "secondary SELL @ ", close ), Alert.BAR, Sound.Chimes );
Re: Fun with ThinkScript
September 09, 2014 04:19PM
Robert,
The alert works great on the watch list. But what do you think about this:

17:01 meyer99: I have an alert that was set up on the watch list. It works ok but I do not get any SMS messages. Who can help me with that?
17:01 Gerry: Hello to setup SMS Alerts.
17:02 meyer99: yes?
17:02 Gerry: Go under Setup > Application Settings > Notifications > Click on setup SMS > Enter Number > Wait for a text confirmation number and confirm
17:02 meyer99: I did all that
17:03 Gerry: You can then check mark the Alerts Triggered Box to the left> Check mark Send SMS during Market Hours and Send SMS during after Market hours
17:03 meyer99: I did that
17:06 meyer99: but nothing happens
17:11 Gerry: Is the alert scripted on a chat?
17:12 meyer99: is a custom function
17:13 Gerry: The SMS alert tool is only available for alerts created under the Alerts in Marketwatch
17:13 meyer99: how about the email?
17:14 meyer99: will that work?
17:14 Gerry: It is the same for the email. Alerts integrated within a watchlist column are not compatible with SMS or EMAIL
17:14 meyer99: ok, thanks
17:15 Gerry: Anytime, if you have futher questions feel free to reach out to us. have a great day!
Re: Fun with ThinkScript
September 09, 2014 04:27PM
Perfect I am going to add this today and test it tomorrow.

Thanks you,
StrategyNode
Re: Fun with ThinkScript
September 09, 2014 04:33PM
Hi Robert,
I have another idea or question which I am not sure if it is possible to code or not.
In one of your previous posts you created a small code where the low of the bar moved with each bar.

Based on that Idea is there a way to have two lines one on top and one at the bottom but they will move together connecting the high (the top line) and low (the bottom line) for x number of previous bars. But they need to be straight (Like how you would draw a trendline by hand on a chart)

Thanks,
StrategyNode



Edited 1 time(s). Last edit at 09/09/2014 04:34PM by strategynode.
Re: Fun with ThinkScript
September 09, 2014 04:37PM
Quote
meyer99
Robert,
The alert works great on the watch list. But what do you think about this:

If tech support told you that's the way it works, then that must be how it works. I wouldn't know. I don't use alerts or watch list columns or scans or most of the things that I get requested to script in this thread.

Sorry, Adrian.
Re: Fun with ThinkScript
September 09, 2014 04:42PM
Quote
strategynode
Perfect I am going to add this today and test it tomorrow.

Thanks you,
StrategyNode

No problem. Hope it works out for you.

Quote
strategynode
Hi Robert,
I have another idea or question which I am not sure if it is possible to code or not.
In one of your previous posts you created a small code where the low of the bar moved with each bar.

Based on that Idea is there a way to have two lines one on top and one at the bottom but they will move together connecting the high (the top line) and low (the bottom line) for x number of previous bars. But they need to be straight (Like how you would draw a trendline by hand on a chart)

Thanks,
StrategyNode

I'm not sure I follow your meaning. Would you post a screenshot of what you are trying to describe?

I'll be honest with you, though, I'm about to start playing Destiny so I'll not be doing any coding this evening. smiling smiley
Re: Fun with ThinkScript
September 09, 2014 05:34PM
Sorry, Never mind dont worry about it I realized its not going to be not a very useful code. Also next time I will figure that out before I post. Thankfully I didn't wate your time.

StrategyNode.
Re: Fun with ThinkScript
September 10, 2014 06:30AM
Destiny has been released??? I didn't think it was due out for another week. I must have been living under a rock or something:-)
Sorry, only registered users may post in this forum.

Click here to login