Thinkscripts - ThinkOrSwim Programming | futures io social day trading
futures io futures trading


Thinkscripts
Updated: Views / Replies:39,384 / 105
Created: by optntdr13 Attachments:31

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
 31  
 
Thread Tools Search this Thread
 

Thinkscripts

  #41 (permalink)
Elite Member
San Diego CA
 
Futures Experience: Beginner
Platform: TOS
Favorite Futures: StocKs
 
Posts: 26 since May 2012
Thanks: 14 given, 5 received

CCI counter using fold attempt

Here is my attempt just to see if I could get something to function. It does work for the first wave but if a new high CCI the count get's screwy. My logic is faulty.
declare lower;

input length = 14;
input over_sold = -45;
input over_bought = 45;

def price = close + low + high;
def linDev = LinDev(price, length);
plot CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;

CCI.SetDefaultColor(GetColor(9));
OverBought.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(5));
OverSold.SetDefaultColor(GetColor(5));


#Countback from present bar to find how many bars from positive zero crossover stop if CCI<0 can't be used as constant for the highest function.
def bar_to_neg = fold j = 1 to 30 with bar_to_neg_ID = 0 while ( CCI > 0) do if CCI[j] > 0 then bar_to_neg_ID + 1 else bar_to_neg_ID;
# define k to try to use as fold constant
def k = getvalue(bar_to_neg,0);
#AddVerticalLine(CCI > 0, concat(k,""), Color.BLUE);

# find High CCI
def High_CCI = fold m = 1 to 7 with High_CCI_temp = 0 while (CCI > 0) do if getvalue(CCI,m,0) > getvalue(CCI,m-1,0) then getvalue(CCI,m,0) else High_CCI_temp;
#AddVerticalLine(CCI > 0, concat(High_CCI,""), Color.BLUE);

#def CCI_High = highest(CCI[1],k);

def CCInum = fold i = 1 to 7 with CCI_count = 0 while ( getvalue(CCI,i,0)<>High_CCI ) do if getvalue(CCI,i,0) > getvalue(CCI,i-1,0) then CCI_count+1 else CCI_count;

AddVerticalLine(CCI > 0, concat(CCInum,""), Color.BLUE);

# find High CCI
def Low_CCI = fold n = 1 to 7 with Low_CCI_temp = 0 while (CCI < 0) do if getvalue(CCI,n,0) < getvalue(CCI,n-1,0) then getvalue(CCI,n,0) else Low_CCI_temp;

#AddVerticalLine(CCI < 0, concat(Low_CCI,""), Color.red);

def CCInum2 = fold p = 1 to 7 with CCI_count2 = 0 while ( getvalue(CCI,p,0)<>Low_CCI ) do if getvalue(CCI,p,0) > getvalue(CCI,p-1,0) then CCI_count2+1 else CCI_count2;

AddVerticalLine(visible = CCI < 0, text = Concat(CCInum2, ""));

Reply With Quote
 
  #42 (permalink)
Knowledge Seeker
Dubai, UAE
 
Futures Experience: Intermediate
Platform: TOS, TradeStation
Broker/Data: OX, TradeStation
Favorite Futures: Stocks & Basic Options
 
RedK's Avatar
 
Posts: 171 since May 2012
Thanks: 44 given, 138 received


pbenson68 View Post
I was playing with this tonight. I noticed 2 issues. The first was a counter issue. Let's say you have CCI values of 54 45 35 37 the counter would from 54 would go like this 45:1 35:2 then 37 is above 35 it becomes the new 2. 35 is now not included in the count.
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Second when the CCI breaks the +- 45 the counter should still count. I modified the counter section to read.
# Pb68 modified countup and countdown condition to zero instead, it can go below 45 line
def Count_up = CCIv > 0 and CCIv < CCIv[1];
def Count_Dn = CCIv < 0 and CCIv > CCIv[1];
#original
#def Count_up = CCIv > over_bought and CCIv < CCIv[1] ;
#def Count_Dn = CCIv < over_sold and CCIv > CCIv[1];
#original end

Here is the latest rev
Attachment 89557

The delimma still exists on the counter. I can't see how it can be done in the code without a fold. It's looking for a true false condition and then ploting the signalflag.

bpenson, one of the best features about ToS script is that it's recursive in nature. i was so happy to learn that this is the way it works.. you can write one line of code with one forumla and it will automatially apply to the whole chart (starting from first point on the left to the rigyt-most point/bar/candle).. this is different from my previous experinces in coding where the coder has to cater for and code for each and every point in any direction..
so knowing that, we don't need fold as long as the function/formula starts from left to the right. the condition we have (which if simple can be done with an if statement), is that once current CCI is lower than previous CCI AND we're above 45, then flag value is true (we get the green square). if that condition is false, the square is false. until the condition is met again and we get a true flag and so on.. if we can give the flag a real value (1, 2, 3) we can check what the previous flag value is, and increment by one.. all without still needing a fold (For..Next loop equivalent)

we can only plot the count in numbers if we're in the top chart/price chart space (not a lower study .. in lower study we can but it will be placed at the price value but in the lower graph irrelevant to it's scale - ugly!!)- even then the scripting language is limited in where to place that number (unless you get into more complex codes that won't add real value) .. you can place it above or below the price bar.

sorry for the long chat .. but when i saw fold.. and what can be done without it given the recursive nature of ToS script i was so happy. i still use fold carefully in certain pieces of my custom studies(carefully due to some old time worries of loops and their CPU consumption or code getting stuck in'em forever if i miss an unseen numeric possibility - which i think is why variables are not allowed in ToS as loop counters) ..

so far didn't meet the need to "go back and count something on the study plot and take action based on that" .. i don't see what is wrong with your/my code with the squares .. it resets the count if it sees higher CCI values and starts over from 1 when it starts decreasing.. that's what we need.... sorry if i'm confused? let me know..

PS, happy to find someone to speak "in code" to .. glad you joined,
cheers,
RedK

Reply With Quote
 
  #43 (permalink)
Knowledge Seeker
Dubai, UAE
 
Futures Experience: Intermediate
Platform: TOS, TradeStation
Broker/Data: OX, TradeStation
Favorite Futures: Stocks & Basic Options
 
RedK's Avatar
 
Posts: 171 since May 2012
Thanks: 44 given, 138 received


bpenson, one of the best features about ToS script is that it's recursive in nature. i was so happy to learn that this is the way it works.. you can write one line of code with one forumla and it will automatially apply to the whole chart (starting from first point on the left to the right-most point/bar/candle).. this is different from my previous experinces in coding where the coder has to cater for and code for each and every point you need to plot on the screen in any direction..

so knowing that, we don't need fold as long as the function/formula starts from left to the right. the condition we have (which if simple enough can be done with an if statement), is that once current CCI is lower than previous CCI AND we're above 45, then flag value is true (we get the green square). if that condition is false, the square is false. until the condition is met again and we get a true flag and so on.. if we can give the flag a real value (1, 2, 3) we can check what the previous flag value is, and increment by one.. all without still needing a fold (For..Next loop equivalent)

we can only plot the count in numbers if we're in the top chart/price chart space (not a lower study .. in lower study we can but it will be placed at the price value but in the lower graph irrelevant to it's scale - ugly!!)- even then the scripting language is limited in where to place that number (unless you get into more complex codes that won't add real value) .. you can place it above or below the price bar.

sorry for the long chat .. but when i saw fold.. and what can be done without it given the recursive nature of ToS script i was so happy. i still use fold carefully in certain pieces of my custom studies(carefully due to some old time worries of loops and their CPU consumption or code getting stuck in'em forever if i miss an unseen numeric possibility - which i think is why variables are not allowed in ToS as loop counters) ..

so far didn't face the need to "go back and count something on the study plot and take action based on that" .. i don't see what is wrong with your/my code with the squares .. it resets the count if it sees higher CCI values and starts over from 1 when it starts decreasing.. that's what we need.... sorry if i'm confused? let me know..

PS, happy to find someone to speak "in code" to .. glad you are here,
cheers,
RedK

Reply With Quote
 
  #44 (permalink)
Elite Member
San Diego CA
 
Futures Experience: Beginner
Platform: TOS
Favorite Futures: StocKs
 
Posts: 26 since May 2012
Thanks: 14 given, 5 received


RedK View Post
bpenson, one of the best features about ToS script is that it's recursive in nature. i was so happy to learn that this is the way it works.. you can write one line of code with one forumla and it will automatially apply to the whole chart (starting from first point on the left to the right-most point/bar/candle).. this is different from my previous experinces in coding where the coder has to cater for and code for each and every point you need to plot on the screen in any direction..

so knowing that, we don't need fold as long as the function/formula starts from left to the right. the condition we have (which if simple enough can be done with an if statement), is that once current CCI is lower than previous CCI AND we're above 45, then flag value is true (we get the green square). if that condition is false, the square is false. until the condition is met again and we get a true flag and so on.. if we can give the flag a real value (1, 2, 3) we can check what the previous flag value is, and increment by one.. all without still needing a fold (For..Next loop equivalent)

we can only plot the count in numbers if we're in the top chart/price chart space (not a lower study .. in lower study we can but it will be placed at the price value but in the lower graph irrelevant to it's scale - ugly!!)- even then the scripting language is limited in where to place that number (unless you get into more complex codes that won't add real value) .. you can place it above or below the price bar.

sorry for the long chat .. but when i saw fold.. and what can be done without it given the recursive nature of ToS script i was so happy. i still use fold carefully in certain pieces of my custom studies(carefully due to some old time worries of loops and their CPU consumption or code getting stuck in'em forever if i miss an unseen numeric possibility - which i think is why variables are not allowed in ToS as loop counters) ..

so far didn't face the need to "go back and count something on the study plot and take action based on that" .. i don't see what is wrong with your/my code with the squares .. it resets the count if it sees higher CCI values and starts over from 1 when it starts decreasing.. that's what we need.... sorry if i'm confused? let me know..

PS, happy to find someone to speak "in code" to .. glad you are here,
cheers,
RedK

RedK I know we can make this work but it seems to be harder then it should be. I am still getting used to the script, but I do have some complaints for instance the the editor drives me freaking nuts. I am used to get pissed at Microsoft for their VBA editor but TOS is ridiculous.

The fold could useful if it is limited.
My logic was to look back only until it until CCI is negative or positive and just work from there.

Going back to the logic.

My first picture may have mislead you, my apologies. Here it is with more explanation.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Here is another with a more complex scheme. It shows the higher bars taking out the previous bars until it begins descending again. Let me know if this clears this up.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
 
  #45 (permalink)
Elite Member
San Diego CA
 
Futures Experience: Beginner
Platform: TOS
Favorite Futures: StocKs
 
Posts: 26 since May 2012
Thanks: 14 given, 5 received

Got it counting with the fold function

REDK I got it to count in the lower study with the fold. Now for making it right.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


declare lower;

input length = 14;
input over_sold = -45;
input over_bought = 45;

def price = close + low + high;
def linDev = LinDev(price, length);
plot CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;

CCI.SetDefaultColor(GetColor(9));
OverBought.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(5));
OverSold.SetDefaultColor(GetColor(5));

rec CCI_last_is_greater= CCI[1]> CCI;
rec CCI_last_is_less= CCI[1]< CCI;
#Countback from present bar to find how many bars from positive zero crossover stop if CCI<0 can't be used as constant for the highest function.
#def bar_to_neg = fold j = 1 to 100 with bar_to_neg_ID = 0 while ( CCI[j] > 0) do if CCI[j] > 0 then bar_to_neg_ID + 1 else bar_to_neg_ID;
# define k to try to use as fold constant
#def k = getvalue(bar_to_neg,0);
#AddVerticalLine(CCI > 0, concat(k,""), Color.BLUE);
def CCInum = fold i = 1 to 100 with CCI_count = 0 while ( CCI[i]>0 ) do if CCI_last_is_greater[i] then CCI_count+1 else CCI_count;

AddVerticalLine(CCI > 0 and CCInum<>0, concat(" ",concat(CCInum,"")), Color.BLUE);

def CCInum_low = fold l = 1 to 100 with CCI_count_lower = 0 while ( CCI[l]<0 ) do if CCI_last_is_less[l] then CCI_count_lower+1 else CCI_count_lower;

AddVerticalLine(visible = CCI < 0 and CCInum_low <>0, text = Concat(CCInum_low, ""));

Reply With Quote
 
  #46 (permalink)
Knowledge Seeker
Dubai, UAE
 
Futures Experience: Intermediate
Platform: TOS, TradeStation
Broker/Data: OX, TradeStation
Favorite Futures: Stocks & Basic Options
 
RedK's Avatar
 
Posts: 171 since May 2012
Thanks: 44 given, 138 received

But you're not "resetting" the count now ... You are "resuming" the count from where you stopped. That's a different approach to what I thought we wanted to do...

And hey, there would be many ways to Rome.. You can do it using fold, someone else would like the green squares with no count and rely on the visual clue.. A 3rd guy would use up/dn arrow at OB/Os level crossing ... So whatever works..

Loved the trick of using the vertical lines for numbering.. Nice one.

Cheers, RedK

Reply With Quote
 
  #47 (permalink)
Elite Member
San Diego CA
 
Futures Experience: Beginner
Platform: TOS
Favorite Futures: StocKs
 
Posts: 26 since May 2012
Thanks: 14 given, 5 received


RedK View Post
But you're not "resetting" the count now ... You are "resuming" the count from where you stopped. That's a different approach to what I thought we wanted to do...

And hey, there would be many ways to Rome.. You can do it using fold, someone else would like the green squares with no count and rely on the visual clue.. A 3rd guy would use up/dn arrow at OB/Os level crossing ... So whatever works..

Loved the trick of using the vertical lines for numbering.. Nice one.

Cheers, RedK

I want to reset the count/step back the counts, but not sure how yet. I may need your help. I was investigating the why the fold was not working and found that while condition was the problem. I change it to CCI>0 to CCI[i] and it worked like it should and then I went to sleep.

The good thing is now it the fold only runs back to the CCI zero crossover. It should not be a processing drag

Any way that works is fine by me.

Thanks on the trick.

Reply With Quote
 
  #48 (permalink)
Elite Member
San Diego CA
 
Futures Experience: Beginner
Platform: TOS
Favorite Futures: StocKs
 
Posts: 26 since May 2012
Thanks: 14 given, 5 received

CCI Counter for TOS

Here is what I have for the CCI counter.
The fold attempt was driving insane, it should have work the way I had it coded, but whatever....

This one starts counting with a zero crossover and I have it look back 10 CCI bars to manage the counting when bars take out previous bars.

ccicountv1.txt

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
 
  #49 (permalink)
Elite Member
San Diego CA
 
Futures Experience: Beginner
Platform: TOS
Favorite Futures: StocKs
 
Posts: 26 since May 2012
Thanks: 14 given, 5 received


pbenson68 View Post
Here is what I have for the CCI counter.
The fold attempt was driving insane, it should have work the way I had it coded, but whatever....

This one starts counting with a zero crossover and I have it look back 10 CCI bars to manage the counting when bars take out previous bars.

Attachment 90119

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Attachment 90122

I am modifying it for to meet the original intent for the next iteration.

Reply With Quote
 
  #50 (permalink)
Elite Member
San Diego CA
 
Futures Experience: Beginner
Platform: TOS
Favorite Futures: StocKs
 
Posts: 26 since May 2012
Thanks: 14 given, 5 received

Tick counter


RedK do you have a tick counter? I tried to make one when I first started working with TOS. I coud not figure it out.

Reply With Quote

Reply



futures io > > > > > Thinkscripts

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     


All times are GMT -4. The time now is 11:43 PM.

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-15 in 0.24 seconds with 19 queries on phoenix via your IP 54.163.210.170