Thinkscript - Code/Logic Question... - futures io
futures io futures trading



Thinkscript - Code/Logic Question...


Discussion in ThinkOrSwim

Updated
    1. trending_up 2,313 views
    2. thumb_up 2 thanks given
    3. group 1 followers
    1. forum 4 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Thinkscript - Code/Logic Question...

(login for full post details)
  #1 (permalink)
NY, NY
 
 
Posts: 67 since Dec 2011
Thanks: 27 given, 19 received

I've been trying to work with the following scan code. Unfortunately, there appears to be a 3 bar/candle delay built into the logic (see "hlc3[-3]" references)...

Given my limited thinkscripting abilities, I am able to grasp and understand certain basic aspects of the code. However, I am currently unable to make the necessary changes in order to draw the signal on the current or just completed bar/candle. Is it possible?

 
Code
input signalOffsetFactor = 0.20;

def signalOffset = Average(TrueRange(high, close, low), 9) * signalOffsetFactor;

def triggerSell = If(If(close[-1] < high, 1, 0) and (hlc3[-2] < close[-1] or hlc3[-3] < close[-1]), 1, 0);

def triggerBuy = If(If(close[-1] > low, 1, 0) and (hlc3[-2] > close[-1] or hlc3[-3] > close[-1]), 1, 0);

rec buySellSwitch = If(triggerSell, 1, If(triggerBuy, 0, buySellSwitch[1]));

def thirdBarClosed = If(IsNaN(hlc3[-3]), 0, 1);

plot BS_Long = If(triggerBuy and thirdBarClosed and buySellSwitch[1], low - signalOffset, Double.NaN);
     BS_Long.SetStyle(Curve.FIRM);
     BS_Long.SetPaintingStrategy(PaintingStrategy.POINTS);
     BS_Long.SetLineWeight(5);
     BS_Long.AssignValueColor(CreateColor(153, 255, 153));

Thanks in advance for any assistance/guidance in this endeavor. It is certainly appreciated

Reply With Quote

 
Best Threads (Most Thanked)
in the last 7 days on futures io
Battlestations: Show us your trading desks!
111 thanks
Selling Options on Futures?
109 thanks
Rank your Futures vs Stocks trading priority
37 thanks
Want your NinjaTrader indicator created, free?
26 thanks
Bitcoin storage wallet recommendations
18 thanks
 
(login for full post details)
  #2 (permalink)
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: ES
 
rmejia's Avatar
 
Posts: 377 since Oct 2010
Thanks: 3,600 given, 432 received

The 3 candle plot delay comes from the text with the strikethrough, you can delete it or put a pound sign in front if you want to convert it to text to save it.
 
Code
input signalOffsetFactor = 0.20;

def signalOffset = Average(TrueRange(high, close, low), 9) * signalOffsetFactor;

def triggerSell = If(If(close[-1] < high, 1, 0) and (hlc3[-2] < close[-1] or hlc3[-3] < close[-1]), 1, 0);

def triggerBuy = If(If(close[-1] > low, 1, 0) and (hlc3[-2] > close[-1] or hlc3[-3] > close[-1]), 1, 0);

rec buySellSwitch = If(triggerSell, 1, If(triggerBuy, 0, buySellSwitch[1]));

def thirdBarClosed = If(IsNaN(hlc3[-3]), 0, 1);

plot BS_Long = If(triggerBuy and thirdBarClosed and buySellSwitch[1], low - signalOffset, Double.NaN);
     BS_Long.SetStyle(Curve.FIRM);
     BS_Long.SetPaintingStrategy(PaintingStrategy.POINTS);
     BS_Long.SetLineWeight(5);
     BS_Long.AssignValueColor(CreateColor(153, 255, 153));
 
Code
input signalOffsetFactor = 0.20;

def signalOffset = Average(TrueRange(high, close, low), 9) * signalOffsetFactor;

def triggerSell = If(If(close[-1] < high, 1, 0) and (hlc3[-2] < close[-1] or hlc3[-3] < close[-1]), 1, 0);

def triggerBuy = If(If(close[-1] > low, 1, 0) and (hlc3[-2] > close[-1] or hlc3[-3] > close[-1]), 1, 0);

rec buySellSwitch = If(triggerSell, 1, If(triggerBuy, 0, buySellSwitch[1]));

#def thirdBarClosed = If(IsNaN(hlc3[-3]), 0, 1);

#plot BS_Long = If(triggerBuy and thirdBarClosed and buySellSwitch[1], low - signalOffset, Double.NaN);
plot BS_Long = If(triggerBuy and buySellSwitch[1], low - signalOffset, Double.NaN);
     BS_Long.SetStyle(Curve.FIRM);
     BS_Long.SetPaintingStrategy(PaintingStrategy.POINTS);
     BS_Long.SetLineWeight(5);
     BS_Long.AssignValueColor(CreateColor(153, 255, 153));

Reply With Quote
The following user says Thank You to rmejia for this post:
 
(login for full post details)
  #3 (permalink)
NY, NY
 
 
Posts: 67 since Dec 2011
Thanks: 27 given, 19 received


Unfortunately, the commenting out/removing of the "thirdBarClosed" variable and associated references did not affect the 3 bar/candle delay. I think the remaining bold/underlined hlc3[-3] code is also affecting the delay, not to mention the bold/underlined hlc3[-2] code that I think would create a 2 bar/candle delay if the hlc3[-3] code was removed...
 
Code
def triggerSell = If(If(close[-1] < high, 1, 0) and (hlc3[-2] < close[-1] or hlc3[-3] < close[-1]), 1, 0);

def triggerBuy = If(If(close[-1] > low, 1, 0) and (hlc3[-2] > close[-1] or hlc3[-3] > close[-1]), 1, 0);

Now that I'm looking more closely, it looks like the script is written to yield attractive historical results. Worthwhile signals 3 or 2 bars/candles ago are not very helpful now in a scan

Thank you for the swift response, rmejia Your assistance is certainly appreciated...

Reply With Quote
 
(login for full post details)
  #4 (permalink)
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: ES
 
rmejia's Avatar
 
Posts: 377 since Oct 2010
Thanks: 3,600 given, 432 received

I tried the study as a regular study and it plots a dot (point) when triggered. With the "thirdbarClosed" it waits 2 candles after the signal is activated to draw the dot, without that it draws it after the signal is activated and the candle closes.

The trigger part of the script compares the previous candle [-1] to the 2 previous ones before it [-2] & [-3] and if it is higher or lower than either of those it triggers the signal.

Some studies like the TTM Scalper Alert plot signals with a couple of candle delays; don't know how to make use of that for real time trading.

Reply With Quote
The following user says Thank You to rmejia for this post:
 
(login for full post details)
  #5 (permalink)
NY, NY
 
 
Posts: 67 since Dec 2011
Thanks: 27 given, 19 received

Thanks for the follow-up and additional debugging, as well as providing a clear and concise explanation of the internal mechanics of the script, rmejia I really appreciate it...

I've gone back and tried the script as a regular study, with the "thirdBarClosed" variable and references removed, in order to visualize what you relayed in your last post. Unfortunately, I'm not seeing any signals being placed any earlier than the 3 bar/candle delay

I find it ironic that a script named "TTM Scalper Alert" incorporates delays. I would have thought a "Scalper" tool would be much more fast acting...

Reply With Quote


futures io Trading Community Platforms and Indicators ThinkOrSwim > Thinkscript - Code/Logic Question...


Last Updated on August 31, 2015


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts