Thinkscript - Code/Logic Question... - ThinkOrSwim | futures io social day trading
futures io futures trading


Thinkscript - Code/Logic Question...
Updated: Views / Replies:843 / 4
Created: by netarchitech Attachments:0

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

Thinkscript - Code/Logic Question...

  #1 (permalink)
Trading Apprentice
NY, NY
 
Futures Experience: Intermediate
Platform: TOS
Favorite Futures: Stocks, ETFs
 
Posts: 30 since Dec 2011
Thanks: 19 given, 5 received

Thinkscript - Code/Logic Question...

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
 
  #2 (permalink)
1.Fibs 2.??? 3.Profit
Puerto Rico
 
Futures Experience: Intermediate
Platform: thinkorswim
Broker/Data: TD Ameritrade
Favorite Futures: ES
 
rmejia's Avatar
 
Posts: 384 since Oct 2010
Thanks: 3,597 given, 421 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:
 
  #3 (permalink)
Trading Apprentice
NY, NY
 
Futures Experience: Intermediate
Platform: TOS
Favorite Futures: Stocks, ETFs
 
Posts: 30 since Dec 2011
Thanks: 19 given, 5 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
 
  #4 (permalink)
1.Fibs 2.??? 3.Profit
Puerto Rico
 
Futures Experience: Intermediate
Platform: thinkorswim
Broker/Data: TD Ameritrade
Favorite Futures: ES
 
rmejia's Avatar
 
Posts: 384 since Oct 2010
Thanks: 3,597 given, 421 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:
 
  #5 (permalink)
Trading Apprentice
NY, NY
 
Futures Experience: Intermediate
Platform: TOS
Favorite Futures: Stocks, ETFs
 
Posts: 30 since Dec 2011
Thanks: 19 given, 5 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

Reply



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

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking to hire someone to write thinkscript code aehartle ThinkOrSwim Programming 2 August 26th, 2015 06:31 PM
Thinkscript to MT4 question spectra9 ThinkOrSwim Programming 3 January 19th, 2015 08:05 AM
Thinkscript logic question strategynode ThinkOrSwim Programming 0 January 5th, 2015 01:28 PM
Indicator - Thinkscript question... netarchitech ThinkOrSwim 2 December 26th, 2014 11:29 PM


All times are GMT -4. The time now is 02:51 AM.

Copyright © 2017 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
Page generated 2017-12-12 in 0.09 seconds with 19 queries on phoenix via your IP 54.90.207.75