NexusFi: Find Your Edge


Home Menu

 





Thinkscripts


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one RedK with 20 posts (15 thanks)
    2. looks_two pbenson68 with 15 posts (1 thanks)
    3. looks_3 RemoWilliams with 5 posts (1 thanks)
    4. looks_4 courier12 with 5 posts (0 thanks)
      Best Posters
    1. looks_one optntdr13 with 8.3 thanks per post
    2. looks_two Silvester17 with 8 thanks per post
    3. looks_3 Massive l with 3 thanks per post
    4. looks_4 RedK with 0.8 thanks per post
    1. trending_up 77,672 views
    2. thumb_up 73 thanks given
    3. group 52 followers
    1. forum 111 posts
    2. attach_file 32 attachments




 
Search this Thread

Thinkscripts

  #41 (permalink)
 pbenson68 
San Diego CA
 
Experience: Beginner
Platform: TOS
Trading: StocKs
Posts: 26 since May 2012
Thanks Given: 14
Thanks Received: 5

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

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
23 thanks
My NQ Trading Journal
16 thanks
HumbleTraders next chapter
9 thanks
  #42 (permalink)
 
RedK's Avatar
 RedK 
Dubai, UAE
 
Experience: Intermediate
Platform: TOS, TradeStation
Broker: OX, TradeStation
Trading: Stocks & Basic Options
Posts: 171 since May 2012
Thanks Given: 44
Thanks Received: 145


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.


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

Visit my NexusFi Trade Journal Reply With Quote
  #43 (permalink)
 
RedK's Avatar
 RedK 
Dubai, UAE
 
Experience: Intermediate
Platform: TOS, TradeStation
Broker: OX, TradeStation
Trading: Stocks & Basic Options
Posts: 171 since May 2012
Thanks Given: 44
Thanks Received: 145


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

Visit my NexusFi Trade Journal Reply With Quote
  #44 (permalink)
 pbenson68 
San Diego CA
 
Experience: Beginner
Platform: TOS
Trading: StocKs
Posts: 26 since May 2012
Thanks Given: 14
Thanks Received: 5


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.



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.


Reply With Quote
  #45 (permalink)
 pbenson68 
San Diego CA
 
Experience: Beginner
Platform: TOS
Trading: StocKs
Posts: 26 since May 2012
Thanks Given: 14
Thanks Received: 5

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



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)
 
RedK's Avatar
 RedK 
Dubai, UAE
 
Experience: Intermediate
Platform: TOS, TradeStation
Broker: OX, TradeStation
Trading: Stocks & Basic Options
Posts: 171 since May 2012
Thanks Given: 44
Thanks Received: 145

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

Visit my NexusFi Trade Journal Reply With Quote
  #47 (permalink)
 pbenson68 
San Diego CA
 
Experience: Beginner
Platform: TOS
Trading: StocKs
Posts: 26 since May 2012
Thanks Given: 14
Thanks Received: 5


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)
 pbenson68 
San Diego CA
 
Experience: Beginner
Platform: TOS
Trading: StocKs
Posts: 26 since May 2012
Thanks Given: 14
Thanks Received: 5

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



Reply With Quote
  #49 (permalink)
 pbenson68 
San Diego CA
 
Experience: Beginner
Platform: TOS
Trading: StocKs
Posts: 26 since May 2012
Thanks Given: 14
Thanks Received: 5


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


Attachment 90122

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

Reply With Quote
  #50 (permalink)
 pbenson68 
San Diego CA
 
Experience: Beginner
Platform: TOS
Trading: StocKs
Posts: 26 since May 2012
Thanks Given: 14
Thanks Received: 5


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




Last Updated on March 25, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts