Stacked Momentum For ThinkOrSwim

Buck

New member
I could use a bit if help with trying to convert the Easystation Stacked Momentum to Thinkscript, I struggle with even something that is most likely pretty simple, I would appreciate any help.
 
Last edited by a moderator:
I could use a bit if help with trying to convert this to Thinkscript, I struggle with even something that is most likely pretty simple, I would appreciate any help.


input length1(20), length2 (10);

if close < close[200] and close > close[length1] and close < close[length2] and close > open then buy next bar at market;

if close > close[200] and close < close[length1] and closee[length2] and close < open then sellshort next bar at market;

if barssinceentry > 10 then Begin sell next bar at market;

//SetStopLoss(StopL);
//SetProfitTarget(Proft);

end:

this might be close to what you want

Code:
#strat_convert_easyL_close_offsets_00c

#https://usethinkscript.com/threads/convert-easylanguage-stacked-momentum.14123/
#Convert EasyLanguage Stacked Momentum
#make strategy
#close trade after 10 bars

def bn = barnumber();
def na = double.nan;

input offset1 = 10;
input offset2 = 20;
input offset3 = 200;

input trade_length_bars = 10;
input tradeSize = 1;

def longenter = if (close < close[offset3] and close > close[offset2] and close < close[offset1] and close > open) then 1 else 0;
def shortenter = if (close > close[offset3] and close < close[offset2] and close[offset1] and close < open) then 1 else 0;

def longbn = if bn == 1 then 0
 else if longenter then bn
 else longbn[1];

def shortbn = if bn == 1 then 0
 else if shortenter then bn
 else shortbn[1];

# another enter signal will extend the trade duration
def longexit = if bn >= (longbn + trade_length_bars) then 1 else 0;
def shortexit = if bn >= (shortbn + trade_length_bars) then 1 else 0;

def longcancel = 0;
def shortcancel = 0;

def longtrade = if bn == 1 then 0
else if longexit then 0
else if longenter then 1
else longtrade[1];

def shorttrade = if bn == 1 then 0
else if shortexit then 0
else if shortenter then 1
else shorttrade[1];

def longstart = (!longtrade[1] and longtrade);
def longstop = (longtrade[1] and !longtrade);
def shortstart = (!shorttrade[1] and shorttrade);
def shortstop = (shorttrade[1] and !shorttrade);

input show_orders = yes;
#-------------------------
# long enter
addorder(
OrderType.BUY_TO_OPEN,
show_orders and longstart,
open[-1],
tradeSize,
color.green,
color.green,
"long");

# long exit
#SELL_TO_CLOSE
addorder(
OrderType.sell_TO_close,
show_orders and longstop,
open[-1],
tradeSize,
color.green,
color.green,
"-");

#-----------------------

# short enter
addorder(
OrderType.sell_to_open,
show_orders and shortstart,
open[-1],
tradeSize,
color.red,
color.red,
"short");

# short exit
addorder(
OrderType.buy_TO_close,
show_orders and shortstop,
open[-1],
tradeSize,
color.red,
color.red,
"-");

#-----------------------

input show_arrows = yes;

plot zlongenter = (show_arrows and longstart);
zlongenter.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
zlongenter.SetDefaultColor(Color.green);
zlongenter.setlineweight(3);
zlongenter.hidebubble();

plot zlongexit = (show_arrows and longstop);
zlongexit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
zlongexit.SetDefaultColor(Color.cyan);
zlongexit.setlineweight(3);
zlongexit.hidebubble();

plot zshortenter = (show_arrows and shortstart);
zshortenter.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
zshortenter.SetDefaultColor(Color.red);
zshortenter.setlineweight(3);
zshortenter.hidebubble();

plot zshortexit = (show_arrows and shortstop);
zshortexit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
zshortexit.SetDefaultColor(Color.yellow);
zshortexit.setlineweight(3);
zshortexit.hidebubble();


input show_enter_exits_verticals = no;
addverticalline(show_enter_exits_verticals and longstart, "long", color.green);
addverticalline(show_enter_exits_verticals and longstop, "long", color.cyan);
addverticalline(show_enter_exits_verticals and shortstart, "short", color.red);
addverticalline(show_enter_exits_verticals and shortstop, "short", color.yellow);

input show_all_buy_sell_signal_verticals = no;
addverticalline(show_all_buy_sell_signal_verticals and longenter, "long", color.green);
addverticalline(show_all_buy_sell_signal_verticals and longexit, "long", color.cyan);
addverticalline(show_all_buy_sell_signal_verticals and shortenter, "short", color.red);
addverticalline(show_all_buy_sell_signal_verticals and shortexit, "short", color.yellow);


input bubbles1 = no;
addchartbubble(bubbles1, low*0.99,
longtrade
, (if longtrade then color.green else color.gray), no);

addchartbubble(bubbles1, low*0.99,
shorttrade
, (if shorttrade then color.red else color.gray), no);

#AddOrder ( int type, IDataHolder condition, IDataHolder price, IDataHolder tradeSize, CustomColor tickColor, CustomColor arrowColor, String name);   

#https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AddOrder
#https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/OrderType
#
 
  • Love
Reactions: IPA

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
512 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top