 # Discussion in ThinkOrSwim

Updated
Top Posters
1. looks_one StockJock with 5 posts (2 thanks)
2. looks_two elof with 4 posts (0 thanks)
3. looks_3 TheArcher with 2 posts (0 thanks)
4. looks_4 cbritton with 1 posts (0 thanks)
1. trending_up 27,420 views
2. thumb_up 3 thanks given
3. group 8 followers
1. forum 11 posts
2. attach_file 5 attachments

# Point and Figure for ToS

cbritton
Atlanta, Georgia

Experience: Intermediate
Platform: NT
Broker: DDT
Posts: 230 since Mar 2010
Thanks Given: 152

This is a quick port of the point and figure indicator from easy language to ToS. This was done as a request. I'm not an expert on P&F charts and I don't use them.

Here's the EL code:

Code
 ``` ``` // PnF EasyLanguage code// This will simulate "Point & Figure" levels on a bar chart{Written by Adam Hefner version 01-07-02}Var: dbh(0), dbl(0), {Daily block high/low}abh(0), abl(0), {actual block high/low}dir(0), {direction}sv(0); {stop value}inputs:  BlockSize(1) , {Block Size} ReverseSize( 3), {Reverse Size} lookBack(-1) ; {look back period}Var:  bs(BlockSize) , rs(ReverseSize) , lb(LookBack) ; {daily block high/low calculations}If Round(high/bs, 0)*bs > High then dbh = (Round(high/ bs,0)*bs) -bs else dbh = Round(high/bs, 0)*bs;If Round(Low/bs, 0)*bs < Lowthen dbl = (Round(Low/bs, 0)*bs)+bselse dbl = Round(Low/bs, 0)*bs;If currentbar <= 1 {check for first 2 bars of the chart} then begin    dir = 1;    abh = dbh;    abl = dbl;end else beginIf dir = 1 {direction up calculations} then begin    if dbh > abh then        abh = dbh {new high}    else begin        If dbl <= abh-(bs*rs) {reverse} then begin            dir = -1;            abh = abh;            abl = dbl;        end else            abh = abh;    end;end else begin {direction down calculations}    If dbl < abl then       abl = dbl {new low}    else if dbh >= abl+(bs*rs) {reverse} then begin        dir = 1;        abl = abl;        abh = dbh;    end else        abl = abl;end;end;        If dir = 1 {reversal stop}then sv = abh-(bs*rs)else sv = abl+(bs*rs);    plot1(abh);plot2(abl);plot3[lb](sv) ;  ``` ```
Here's the ToS code:

Code
 ``` ``` input blockSize = 1;input reverseSize = 3;input lookBack = 1;# daily block high/low calculationsrec dbh = if round(high/blockSize, 0)*blockSize > high then (round(high/blockSize,0)*blockSize) - blockSize else round(high/blockSize,0)*blockSize;rec dbl = if round(low/blockSize, 0)*blockSize < low then (round(low/blockSize,0)*blockSize) + blockSize else round(low/blockSize,0)*blockSize;rec dir = compoundValue(1, if dir == 1 and dbh <=  dbh-(blockSize*reverseSize) then -1 else if dir != 1 and dbh >= dbl+(blockSize*reverseSize) then 1 else dir,1);rec abh = compoundValue(1, if dir == 1 and dbh > abh then dbh else if dir == 1 and dbh <= abh then abh else if dir != 1 and dbh >= dbl+(blockSize*reverseSize) then dbh else abh, dbh);rec abl = compoundValue(1, if dir == 1 and dbh <= abh and dbl <= abh-(blockSize*reverseSize) then dbl else if dir != 1 and dbl < abl then dbl else if dir != 1 and dbh > dbl+(blockSize*reverseSize) then abl else abl, dbl);rec sv = if dir == 1 then abh-(blockSize*reverseSize) else abl+(blockSize*reverseSize);plot a = abh;plot b = abl;plot s = sv[lookback];  ``` ```
Included is screenshot of a chart in ToS.

I think I got it to match the EL code. I will have to compare it to the TS version later when I have a minute, but anyone can take a stab at improving it.

Regards,
-C

 �Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.� - Sun Tzu
Attached Thumbnails  Can you help answer these questions
from other members on NexusFi?
 Optimal Futures Trading WorkflowPlatforms and Indicators Any experience with Affordable Indicators - Duplicate Ac …Trading Reviews and Vendors Your experience with VPS Ninjamobiletrader ?Trading Reviews and Vendors Do 5-days or 7-days constitute a Multiweek Channel?Currencies TPO letter distribution for E-mini?Emini and Emicro Index

in the last 7 days on NexusFi
 GFIs1 1 DAX trade per day journal26 thanks Big Mike in Ecuador18 thanks Vinny E-Mini & Algobox Review TRADE ROOM11 thanks King Of The Nasdaq10 thanks Sam fired from OpenAI!9 thanks

 (login for full post details) #3 (permalink) StockJock Chicago + Illinois/USA   Posts: 256 since Aug 2010 Thanks Given: 15 Thanks Received: 154 It appears that the translation only plots the upper and lower limits. I've been think that it might be possible to improvise with the plotting of Xs and Os by using the addChartBubble command, because its syntax is addChartBubble(x-axis location,y-axis location, text, color,up). If it were possible to identify the x & y coordinates to place the bubbles then a PnF chart in TOS might be possible. The X-Axis consists of either bars or time; whereas the Y-Axis consists of prices. The horizontal limit is the aggregated time period and the vertical limit is the highesthigh and lowestlow prices. I'm working on it. If you have any suggestions, please let me know. The bubbles could be like this: addChartBubble(x-axis location, y-axis location, "X", color.green, up) addChartBubble(x-axis location, y-axis location, "O", color.red, down) StockJock
Chicago + Illinois/USA

Posts: 256 since Aug 2010
Thanks Given: 15

I've developed some starter code for a Point & Figure indicator (PnF), but I need some help. The code shows the closing prices of each bar on the chart and an index number for each bar.

1. How can I start a calculation from the far left of the chart to progressively calculate the PnF value; since normally TOS counts from the right side of the chart?

2. Is there a way to total the bar count and use the bar index to use the fold command to do the iterations?

3. This code displays the number of each bar; but how can I use that number in the bar index (i.e. close[#])?

Code
 ```declare upper; # Clear Chart AssignPriceColor(CreateColor(10, 0, 78)); AssignBackgroundColor(CreateColor(10, 0, 78)); # Graph Boundaries plot HH = HighestAll(high); plot LL = LowestAll(low); plot ML = (HH + LL) / 2; # Plot Bubbles def Bar_Xaxis = barNumber(); def Bar_Yaxis = ML; rec BarIndex = if IsNaN( BarIndex ) then 0 else BarIndex + 1; AddChartBubble(Bar_Xaxis, Bar_Yaxis, concat("", BarIndex), color.Gray, No); AddChartBubble(Bar_Xaxis, Bar_Yaxis, concat("", close), color.Cyan, Yes);``` The following user says Thank You to StockJock for this post:
 (login for full post details) #5 (permalink) StockJock Chicago + Illinois/USA   Posts: 256 since Aug 2010 Thanks Given: 15 Thanks Received: 154 Plotting Prices & Indexes On Price Bars This code is to start the bar count from the first bar on the far left side of the chart and count down forward in time. I'm trying to use the fold statement to do a count down, but fold is so different from loops in other programming languages. I need help on this. Has anyone else used the fold statement? ================================================= declare upper; # Clear Chart AssignPriceColor(CreateColor(10, 0, 78)); AssignBackgroundColor(CreateColor(10, 0, 78)); # Graph Boundaries plot HH = HighestAll(high); plot LL = LowestAll(low); plot ML = (HH + LL) / 2; # Plot Bubbles def TotalBarsOnChart=24*60*60 *1000/getAggregationPeriod(); def Bar_Xaxis = barNumber(); def Bar_Yaxis = ML; rec FBarIndex = if IsNaN(FBarIndex ) then 0 else FBarIndex + 1; rec RBarIndex=fold index = 1 to TotalBarsOnChart with Bar = TotalBarsOnChart do Bar = Bar - 1); AddChartBubble(Bar_Xaxis, Bar_Yaxis, concat("", FBarIndex), color.Gray, No); AddChartBubble(Bar_Xaxis, Bar_Yaxis + 0.2, concat("", RBarIndex), color.Yellow, No); ========================= ======================== StockJock
Chicago + Illinois/USA

Posts: 256 since Aug 2010
Thanks Given: 15

I don't seem to have much luck developing a PnF indicator in ThinkScript, but I've found out that the Three Line Break chart does something similar. If its not too much trouble, could someone translate this EasyLanguage code into ThinkScript?

Here is the Easy Language version:

Code
 ``` Variables: FUBarHigh(0), FUBarLow(0), SUBarHigh(0), SUBarLow(0), TUBarHigh(0), TUBarLow(0), FLBarHigh(0), FLBarLow(0), SLBarHigh(0), SLBarLow(0), TLBarHigh(0), TLBarLow(0), UpCount(0), DownCount(0), UpNew(0), DnNew(0), UpRev(0), DnRev(0), PlotHigh(0), PlotLow(0), Color(0); If Close > UpNew Then Begin If DownCount < 3 Then Begin If UpCount = 0 Then Begin UpCount = UpCount + 1; DownCount = 0; FUBarHigh = Close; FUBarLow = UpNew; SUBarHigh = 0; SUBarLow = 0; TUBarHigh = 0; TUBarLow = 0; FLBarHigh = 0; FLBarLow = 0; SLBarHigh = 0; SLBarLow = 0; TLBarHigh = 0; TLBarLow = 0; UpNew = FUBarHigh; DnNew = FUBarLow; PlotHigh = FUBarHigh; PlotLow = FUBarLow; Color = 7; End; If UpCount = 1 Then If Close > UpNew Then Begin UpCount = UpCount + 1; SUBarHigh = Close; SUBarLow = FUBarHigh; UpNew = SUBarHigh; DnNew = SUBarLow; PlotHigh = SUBarHigh; PlotLow = SUBarLow; Color = 8; End; If UpCount = 2 Then If Close > UpNew Then Begin UpCount = UpCount + 1; TUBarHigh = Close; TUBarLow = SUBarHigh; UpNew = TUBarHigh; DnNew = TUBarLow; PlotHigh = TUBarHigh; PlotLow = TUBarLow; Color = 7; End; If UpCount = 3 Then If Close > UpNew Then Begin FUBarHigh = SUBarHigh; FUBarLow = SUBarLow; SUBarHigh = TUBarHigh; SUBarLow = TUBarLow; TUBarHigh = Close; TUBarLow = SUBarHigh; UpNew = TUBarHigh; DnNew = TUBarLow; PlotHigh = TUBarHigh; PlotLow = TUBarLow; If Color = 7 Then Color = 8 Else Color = 7; End; End; If DownCount = 3 Then Begin UpRev = FLBarHigh; If Close > UpRev Then Begin UpCount = UpCount + 1; DownCount = 0; FUBarHigh = Close; FUBarLow = TLBarHigh; SUBarHigh = 0; SUBarLow = 0; TUBarHigh = 0; TUBarLow = 0; FLBarHigh = 0; FLBarLow = 0; SLBarHigh = 0; SLBarLow = 0; TLBarHigh = 0; TLBarLow = 0; UpNew = FUBarHigh; DnNew = FUBarLow; PlotHigh = FUBarHigh; PlotLow = FUBarLow; Color = 7; End; End; End; If Close < DnNew Then Begin If UpCount < 3 Then Begin If DownCount = 0 Then Begin DownCount = DownCount + 1; UpCount = 0; FLBarHigh = DnNew; FLBarLow = Close; SLBarHigh = 0; SLBarLow = 0; TLBarHigh = 0; TLBarLow = 0; FUBarHigh = 0; FUBarLow = 0; SUBarHigh = 0; SUBarLow = 0; TUBarHigh = 0; TUBarLow = 0; UpNew = FLBarHigh; DnNew = FLBarLow; PlotHigh = FLBarHigh; PlotLow = FLBarLow; Color = 6; End; If DownCount = 1 Then If Close < DnNew Then Begin DownCount = DownCount + 1; SLBarHigh = FLBarLow; SLBarLow = Close; UpNew = SLBarHigh; DnNew = SLBarLow; PlotHigh = SLBarHigh; PlotLow = SLbarLow; Color = 5; End; If DownCount = 2 Then If Close < DnNew Then Begin DownCount = DownCount + 1; TLBarHigh = SLBarLow; TLBarLow = Close; UpNew = TLBarHigh; DnNew = TLBarLow; PlotHigh = TLBarHigh; PlotLow = TLBarLow; Color = 6; End; If DownCount = 3 Then If Close < DnNew Then Begin FLBarHigh = SLBarHigh; FLBarLow = SLBarLow; SLBarHigh = TLBarHigh; SLBarLow = TLBarLow; TLBarHigh = SLBarLow; TLBarLow = Close; UpNew = TLBarHigh; DnNew = TLBarLow; PlotHigh = TLBarHigh; PlotLow = TLBarLow; If Color = 6 Then Color = 5 Else Color = 6; End; End; If UpCount = 3 Then Begin DnRev = FUBarLow; If Close < DnRev Then Begin DownCount = DownCount + 1; UpCount = 0; FLBarHigh = TUBarLow; FLBarLow = Close; SLBarHigh = 0; SLBarLow = 0; TLBarHigh = 0; TLBarLow = 0; FUBarHigh = 0; FUBarLow = 0; SUBarHigh = 0; SUBarLow = 0; TUBarHigh = 0; TUBarLow = 0; UpNew = FLBarHigh; DnNew = FLBarLow; PlotHigh = FLBarHigh; PlotLow = FLBarLow; Color = 6; End; End; End; Plot1(PlotHigh,"High Bar",Color); Plot2(PlotLow,"Low Bar",Color);```
Also there's another EL code version for the Three Line Break at:
Part 1: Three Line Break | TradeStation EasyLanguage Part 2: Three Line Break | TradeStation EasyLanguage Part 3: Three Line Break | Tradestation EasyLanguage Part 4: Three Line Break | Tradestation EasyLanguage (login for full post details) #7 (permalink) optntdr13  Glyndon, Maryland, USA   Experience: Advanced Platform: TOS Trading: options Posts: 24 since Sep 2010 Thanks Given: 6 Thanks Received: 49 If you post a screenshot I will tell you how to fix it without any problem. StockJock
Chicago + Illinois/USA

Posts: 256 since Aug 2010
Thanks Given: 15

optntdr13,

What elof and I are trying to do is to develop code for a PnF chart for the ThinkOrSwim trading platform. The screenshot that you're referring to is in this thread in post #4 and it does work; so I don't know why elof is having a problem with it. It is only a starter code to attempt to build a PnF code. It is not a finished PnF code.

I see that your Trading Experience is Advanced and if your ThinkScript programming experienced is advanced also, I would appreciate your help. I've come across a very good working code that is coded for the Amibroker platform and if this could be translated into a working TOS code, we would greatly appreciate it. I've attached the Amibroker PnF chart code as a text file together with a screen shot showing its capability.

On issue with PnF chart code is that it should be able to display Xs and Os in the same column for the Wyckoff trading system only when the settings are a box size of 1 and a reversal size of 1. For all other settings, the Xs and Os should be in seperate columns. The attached code doesn't do that and I'm still looking for code that will do it so that it could be translated into TOS. Your help with this is appreciated.

I've also attached the Amibroker User's Guide that contains instructions for the Amibroker Formula Language (AFL).

Attached Thumbnails
Attached Files
 Register to download PnF & Values-SJ.txt (6.3 KB, 184 views) The following user says Thank You to StockJock for this post:
 (login for full post details) #9 (permalink) TheArcher chicago, il   Posts: 2 since Jun 2014 Thanks Given: 0 Thanks Received: 0 So, I take it that nobody was ever able to figure this out for ThinkOrSwim. I am just starting with ToS and really miss this wonderful charting technique. (login for full post details) #10 (permalink) TheArcher chicago, il   Posts: 2 since Jun 2014 Thanks Given: 0 Thanks Received: 0 The lookBack is coded wrong in this example. Instead of 1, it should be -1. Last Updated on May 3, 2020 © 2023 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. no new posts