NexusFi: Find Your Edge


Home Menu

 





Point and Figure for ToS


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,678 views
    2. thumb_up 3 thanks given
    3. group 8 followers
    1. forum 11 posts
    2. attach_file 5 attachments




 
Search this Thread

Point and Figure for ToS

  #1 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256

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}
 
ReverseSize3), {Reverse Size}
 
lookBack(-1) ; {look back period}

Var: 
 
bs(BlockSize) ,
 
rs(ReverseSize) ,
 
lb(LookBack) ;

 {
daily block high/low calculations}
If 
Round(high/bs0)*bs High
 then dbh 
= (Round(highbs,0)*bs) -bs
 
else dbh Round(high/bs0)*bs;

If 
Round(Low/bs0)*bs Low
then dbl 
= (Round(Low/bs0)*bs)+bs
else dbl Round(Low/bs0)*bs;

If 
currentbar <= {check for first 2 bars of the chartthen begin
    dir 
1;
    
abh dbh;
    
abl dbl;
end else begin

If dir[1] = {direction up calculationsthen begin
    
if dbh abh[1then
        abh 
dbh {new high}
    else 
begin
        
If dbl <= abh-(bs*rs) {reversethen begin
            dir 
= -1;
            
abh abh[1];
            
abl dbl;
        
end else
            
abh abh[1];
    
end;
end else begin {direction down calculations}
    If 
dbl abl[1then
       abl 
dbl {new low}
    else if 
dbh >= abl+(bs*rs) {reversethen begin
        dir 
1;
        
abl abl[1];
        
abh dbh;
    
end else
        
abl abl[1];
end;
end;
        
If 
dir {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 calculations

rec dbh = if round(high/blockSize0)*blockSize high then (round(high/blockSize,0)*blockSize) - blockSize else round(high/blockSize,0)*blockSize;

rec dbl = if round(low/blockSize0)*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*reverseSizethen -else if dir[1] != and dbh >= dbl+(blockSize*reverseSizethen 1 else dir[1],1);

rec abh compoundValue(1, if dir[1] == and dbh abh[1then dbh else if dir[1] == and dbh <= abh[1then abh[1] else if dir[1] != and dbh >= dbl+(blockSize*reverseSizethen dbh else abh[1], dbh);

rec abl compoundValue(1, if dir[1] == and dbh <= abh[1] and dbl <= abh-(blockSize*reverseSizethen dbl else if dir[1] != and dbl abl[1then dbl else if dir[1] != and dbh dbl+(blockSize*reverseSizethen abl[1] else abl[1], 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
Click image for larger version

Name:	pf1.PNG
Views:	2152
Size:	34.2 KB
ID:	18794  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
NexusFi Journal Challenge - April 2024
Feedback and Announcements
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #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)

Reply With Quote
  #4 (permalink)
StockJock
Chicago + Illinois/USA
 
Posts: 256 since Aug 2010
Thanks Given: 15
Thanks Received: 154

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[1] ) then 0 else BarIndex[1] + 1;
AddChartBubble(Bar_Xaxis, Bar_Yaxis, concat("", BarIndex), color.Gray, No); 
AddChartBubble(Bar_Xaxis, Bar_Yaxis, concat("", close[0]), color.Cyan, Yes);

Reply With Quote
Thanked by:
  #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[1] ) then 0 else FBarIndex[1] + 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);
========================= ========================

Reply With Quote
  #6 (permalink)
StockJock
Chicago + Illinois/USA
 
Posts: 256 since Aug 2010
Thanks Given: 15
Thanks Received: 154

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

Reply With Quote
  #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.

Reply With Quote
  #8 (permalink)
StockJock
Chicago + Illinois/USA
 
Posts: 256 since Aug 2010
Thanks Given: 15
Thanks Received: 154

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
Point and Figure for ToS-usersguide.pdf  
Attached Files
Elite Membership required to download: PnF & Values-SJ.txt
Reply With Quote
Thanked by:
  #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.

Reply With Quote
  #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.

Reply With Quote




Last Updated on May 3, 2020


© 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