Skip to content

Commit

Permalink
v1 for BTFG_STFG strategy and studies
Browse files Browse the repository at this point in the history
  • Loading branch information
korygill committed Mar 20, 2019
1 parent 606c656 commit a206a37
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 2 deletions.
74 changes: 73 additions & 1 deletion BTFG_STFG/BTFG_STFG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,78 @@
# BTFG_STFG #

This is a long/short study is based on the work of [@kerberos007](https://twitter.com/kerberos007). If you look at their feed, you will see lots of work regarding this strategy using Bollinger Bands, Percent B (%B), and some initial parameters that give good back testing results.
This is a long/short study based on the work of [@kerberos007](https://twitter.com/kerberos007). If you look at their feed, you will see lots of work regarding this strategy using Bollinger Bands, Percent B (%B), and some initial parameters that give good back testing results.

As with any strategy, you should understand it, tweak it to your own risk profile, and extend it to incorporate other indicators and strategies.

Alternatively, just buy or sell the glitch!

## A picture is worth a thousand words, BTFG_STFG on SPX ##

![spx-strategy-and-study](spx-strategy-and-study.png "spx-strategy-and-study")

### Legend ###

1 SPX 1D chart with BTFG_STFG Strategy
2 BTFG_STFG Study
3 VIX_BTFG_STFG Study for Calls
4 VIX_BTFG_STFG Study for Puts
5 Floating P&L for the strategy

Green, go long, buy calls
Red, cover long, cover calls
Yellow, go short, buy puts
Magenta, cover short, cover calls


What is the #2 study doing? Per the aformentioned work from [@kerberos007](https://twitter.com/kerberos007)

go long when %B(20,1) crosses > 0
cover long when %B(20,2) crosses > 100
go short when %B(20,2) crosses < 100
cover short when %B(20,1) crosses < 0

A *Study* will fire many times more than its corresponding *Strategy*. This is also good for developing a new strategy, so you can eyeball when various conditions happen and you get your aha moment.

The #1 strategy is the strategy version of the #2 study.

The #3 and #4 studies are a variant of the %B indicators used in BTFG_STFG. These are not incorporated into the strategy (at least yet). You can use the VIX_BTFG_STFG Study for trading the VIX. Check out [VIX_BTFG_STFG](/VIX_BTFG_STFG/VIX_BTFG_STFG.md) for details.

When #3 shows VIX %B overbought and SPX %B is oversold, there's a good chance for bottom in the SPX.

Similarly, when #4 shows VIX %B oversold and SPX %B is overbought, there's a good chance for top in the SPX.

## Strategy and Study Development ##

The thinkscript code for the strategies and studies are below. They are saved as txt files so they can be opened easily. You will need to create a new study or strategy in thinkorswim and copy/paste them in.

[BTFG_STFG_Strat](/BTFG_STFG/BTFG_STFG_Strat.txt)

[BTFG_STFG](/BTFG_STFG/BTFG_STFG.txt)

[VIX_BTFG_STFG](/VIX_BTFG_STFG/VIX_BTFG_STFG.txt)


From the Studies menu on your chart, choose "Edit studies..." and get the following dialog. Configure as shown, and you should have a screen that matches the screen at the top of this page.

![edit-studies-and-strategies-dialog](edit-studies-and-strategies-dialog.png "edit-studies-and-strategies-dialog")

I name my studies with my initials to make them easy to find. The arrow shows you where the find the "Global strategy settings...". Using a default trade size of 50 in your "Global strategy settings..." will make the strategy correspond to the dollar value of 1 ES contract.

## Results: Show Report ##

I loaded a 10 year, 1 day chart of SPX, and generated the following report. You can export to csv file for further analysis. You can use excel, python, or PowerShell to further process the data for import stats. To get the report, right-click any trade in the Strategy screen, and choose "Show report".

![strategy-report](strategy-report.png "strategy-report")

Check out [Trading System Special: Testing Your Strategy](https://tickertape.tdameritrade.com/trading/trading-system-special-testing-your-strategy-15192) for some starting ideas.

## post script ##

These studies may or may not work on other synbols. With modifications to the parameters, maybe they work better for Gold than the Euro. Welcome to technical analysis and your journey down the rabbit hole.

## feedback welcome ##

Have a suggestion? Found an issue? Reach out to me on twitter, my DM is open to all. If you are a github user, file an issue or make a suggested change and PR to this repo.


---
Expand Down
105 changes: 105 additions & 0 deletions BTFG_STFG/BTFG_STFG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#
# BTFG_STFG
#
# This script adapted from posts from @kerberos007
# https://twitter.com/kerberos007
#
# Want the latest version of this script?
# https://github.com/korygill/technical-analysis #
# Use on thinkorswim and thinkscript
# author @korygill
#

script GetBollingerBandPercent
{
input price = close;
input upper = 2;
input lower = 2;
input averageType = AverageType.SIMPLE;
input displace = 0;
input length = 20;

def upperBand = BollingerBands(price, displace, length, lower, upper, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, lower, upper, averageType).LowerBand;

plot BBPercent = (price - lowerBand) / (upperBand - lowerBand) * 100;
}

declare lower;

input averageType = AverageType.Simple;
input price = close;
input displace = 0;
input length = 20;
input StdDev_DnBuy = -2.0;
input StdDev_UpBuy = 2.0;
input StdDev_DnSell = -1.0;
input StdDev_UpSell = 1.0;

plot PercentBBuy = GetBollingerBandPercent(price, StdDev_UpBuy, StdDev_DnBuy);
plot PercentBSell = GetBollingerBandPercent(price, StdDev_UpSell, StdDev_DnSell);

plot ZeroLine = 0;
plot HalfLine = 50;
plot UnitLine = 100;

def vixPrice = close("VIX");
def vixPercentBBuy = GetBollingerBandPercent(vixPrice, StdDev_UpBuy, StdDev_DnBuy);
def vixPercentBSell = GetBollingerBandPercent(vixPrice, StdDev_UpSell, StdDev_DnSell);



def opacity = 25;
def linewidth = 1;

PercentBBuy.SetDefaultColor(Color.GREEN);#(GetColor(3));
PercentBBuy.AssignValueColor(CreateColor(
0,
255, #255-Max(0,Min(100-opacity,PercentBBuy))*2.55,
0));
PercentBBuy.SetPaintingStrategy(PaintingStrategy.LINE);
PercentBBuy.SetLineWeight(linewidth);

PercentBSell.SetDefaultColor(Color.RED);#(GetColor(7));
PercentBSell.AssignValueColor(CreateColor(
255, #Max(opacity,Min(100,PercentBSell))*2.55,
0,
0));
PercentBSell.SetPaintingStrategy(PaintingStrategy.LINE);
PercentBSell.SetLineWeight(linewidth);

ZeroLine.SetDefaultColor(Color.GREEN);
HalfLine.SetDefaultColor(GetColor(8));
UnitLine.SetDefaultColor(Color.RED);

# LONG
AddVerticalLine(
Crosses(PercentBBuy, ZeroLine, CrossingDirection.ABOVE),
"+++ Go Long +++", Color.GREEN, curve.SHORT_DASH
);

AddVerticalLine(
Crosses(PercentBSell, UnitLine, CrossingDirection.ABOVE),
"+++ Cover Long +++", Color.RED, curve.SHORT_DASH
);

# SHORT
AddVerticalLine(
Crosses(PercentBBuy, UnitLine, CrossingDirection.BELOW),
"--- (Go Short) ---", Color.YELLOW, curve.SHORT_DASH
);

AddVerticalLine(
Crosses(PercentBSell, ZeroLine, CrossingDirection.BELOW),
"--- (Cover Short) ---", Color.MAGENTA, curve.SHORT_DASH
);


#AddVerticalLine(
# GetDayofWeek(GetYYYYMMDD()) == 5,
# "Friday", Color.LIGHT_GRAY, curve.MEDIUM_DASH
#);

AddLabel(yes, GetSymbol(), COLOR.CYAN);
AddLabel(yes, "Long=Green cross > 0, Cover=Red cross > 100", COLOR.GREEN);
AddLabel(yes, "Short=Red cross < 100, Cover=Green cross < 0", COLOR.RED);
79 changes: 79 additions & 0 deletions BTFG_STFG/BTFG_STFG_Strat.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#
# BTFG_STFG_Strat
#
# This script adapted from posts from @kerberos007
# https://twitter.com/kerberos007
#
# Want the latest version of this script?
# https://github.com/korygill/technical-analysis #
# Use on thinkorswim and thinkscript
# author @korygill
#

script GetBollingerBandPercent
{
input price = close;
input upper = 2;
input lower = 2;
input averageType = AverageType.SIMPLE;
input displace = 0;
input length = 20;

def upperBand = BollingerBands(price, displace, length, lower, upper, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, lower, upper, averageType).LowerBand;

plot BBPercent = (price - lowerBand) / (upperBand - lowerBand) * 100;
}

input averageType = AverageType.SIMPLE;
input price = close;
input displace = 0;
input length = 20;
input StdDev_DnBuy = -2.0;
input StdDev_UpBuy = 2.0;
input StdDev_DnSell = -1.0;
input StdDev_UpSell = 1.0;
input LongShortBoth = {Long, Short, default Both};

def PercentBBuy = GetBollingerBandPercent(price, StdDev_UpBuy, StdDev_DnBuy);

def PercentBSell = GetBollingerBandPercent(price, StdDev_UpSell, StdDev_DnSell);

def ZeroLine = 0;
def HalfLine = 50;
def UnitLine = 100;

def lsb;
switch (LongShortBoth)
{
case Long: lsb = 0;
case Short: lsb = 1;
default: lsb = 2;
}

# LONG
AddOrder(OrderType.BUY_TO_OPEN,
Crosses(PercentBBuy, ZeroLine, CrossingDirection.ABOVE) and lsb != 1,
tickColor = COLOR.WHITE, arrowColor = COLOR.GREEN
);

AddOrder(OrderType.SELL_TO_CLOSE,
Crosses(PercentBSell, UnitLine, CrossingDirection.ABOVE) and lsb != 1,
tickColor = COLOR.WHITE, arrowColor = COLOR.RED
);

# SHORT
AddOrder(OrderType.SELL_TO_OPEN,
Crosses(PercentBBuy, UnitLine, CrossingDirection.BELOW) and lsb != 0,
tickColor = COLOR.WHITE, arrowColor = COLOR.YELLOW
);

AddOrder(OrderType.BUY_TO_CLOSE,
Crosses(PercentBSell, ZeroLine, CrossingDirection.BELOW) and lsb != 0,
tickColor = COLOR.WHITE, arrowColor = COLOR.MAGENTA
);

AddLabel(yes, "Go Long", COLOR.GREEN);
AddLabel(yes, "Cover Long", COLOR.RED);
AddLabel(yes, "Go Short", COLOR.YELLOW);
AddLabel(yes, "Cover Short", COLOR.MAGENTA);
Binary file added BTFG_STFG/edit-studies-and-strategies-dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BTFG_STFG/spx-strategy-and-study.pdn
Binary file not shown.
Binary file added BTFG_STFG/spx-strategy-and-study.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BTFG_STFG/strategy-report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ Bookmark this page. It contains links to all other content, which may be reorgan

[BTFG_STFG](/BTFG_STFG/BTFG_STFG.md)

This is a long/short study is based on the work of [@kerberos007](https://twitter.com/kerberos007). If you look at their feed, you will see lots of work regarding this strategy using Bollinger Bands, Percent B (%B), and some initial parameters that give good back testing results.
This is a long/short study based on the work of [@kerberos007](https://twitter.com/kerberos007). If you look at their feed, you will see lots of work regarding this strategy using Bollinger Bands, Percent B (%B), and some initial parameters that give good back testing results.

[VIX_BTFG_STFG](/VIX_BTFG_STFG/VIX_BTFG_STFG.md)

This is a long/short study based on the work of [@kerberos007](https://twitter.com/kerberos007). If you look at their feed, you will see lots of work regarding this strategy using Bollinger Bands, Percent B (%B), and some initial parameters that give good back testing results.
37 changes: 37 additions & 0 deletions VIX_BTFG_STFG/VIX_BTFG_STFG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# VIX_BTFG_STFG #

This is a long/short study based on the work of [@kerberos007](https://twitter.com/kerberos007). If you look at their feed, you will see lots of work regarding this strategy using Bollinger Bands, Percent B (%B), and some initial parameters that give good back testing results.

As with any strategy, you should understand it, tweak it to your own risk profile, and extend it to incorporate other indicators and strategies.

Alternatively, just buy or sell the glitch!

## Strategy and Study Development ##

This strategy/study is for the VIX.

A *strategy* for this study is still under development... This study can be used independently, or you can find this study in use on the [BTFG_STFG](/BTFG_STFG/BTFG_STFG.md) page. See that page for a lot of info on how to configure studies in thinkorswim.

Per the aformentioned work from [@kerberos007](https://twitter.com/kerberos007)

Calls
go long VIX calls when %B(20,1.5) crosses > 0
cover VIX calls when %B(20,1.5) crosses > 100

Puts
go long VIX puts when %B(20,1.2) crosses < 100
cover VIX puts when %B(20,2) crosses < 0

A *Study* will fire many times more than its corresponding *Strategy*. This is also good for developing a new strategy, so you can eyeball when various conditions happen and you get your aha moment.

## post script ##

These studies may or may not work on other synbols. With modifications to the parameters, maybe they work better for Gold than the Euro. Welcome to technical analysis and your journey down the rabbit hole.

## feedback welcome ##

Have a suggestion? Found an issue? Reach out to me on twitter, my DM is open to all. If you are a github user, file an issue or make a suggested change and PR to this repo.


---
back to [README.md](/README.md)
Loading

0 comments on commit a206a37

Please sign in to comment.