Gann's Price & Time [Square The Range]

Picard

Member
Gann's Price & Time [Square The Range]

I'm scripting Gann's forecasting method to plot and display a calculated turning date, but I need help to capture the date and price that I've plotted in bubbles. Although I've found the high and low prices with their dates, I need help to capture those values into variables so that I can use them to continue to code in Gann's calculations. I'm including both the code below and the attached indicator file.

Code:
declare upper;

input numMonths1 = 5;
input VScale = 0.5;
input HScale = 5.0;
input GridSize = 50;

input Show1 = yes;
input lineWeight = 5;

def numdays = 21;

def numBars1 = numdays * numMonths1;
def barNum = if IsNaN( close ) then Double.NaN else BarNumber();
def lastBar = HighestAll( barNum );
def startBar1 = if lastBar <= numBars1 then 1 else lastBar - numBars1;
def bar = BarNumber();

def hData1 = If( barNum < startBar1, Double.NaN, high );
def lData1 = If( barNum < startBar1, Double.NaN, low );

def a_price = HighestAll(high);
def b_price = LowestAll(low);
def barnumber = BarNumber();
def c_price = if high == a_price then barnumber else Double.NaN;
def d_price = if low == b_price then barnumber else Double.NaN;
rec highnumber = CompoundValue(1, if IsNaN(c_price) then highnumber[1] else c_price, c_price);
def highnumberall = HighestAll(highnumber);
rec lownumber = CompoundValue(1, if IsNaN(d_price) then lownumber[1] else d_price, d_price);
def lownumberall = LowestAll(lownumber);

def months1 = Round( ( lastBar - startBar1 + 1 ) / 21, 0 );
plot HighestHigh1 = If( Show1, HighestAll( hData1 ), Double.NaN );
plot LowestLow1 = If( Show1, LowestAll( lData1 ), Double.NaN );

# ===============================================================
# Chart Bubbles
# ===============================================================
def BeginBarH = if barNum >= startBar1 and HighestAll(HighestHigh1) == high
then BarNumber() else BeginBarH[1];
def BeginBarL = if barNum >= startBar1 and HighestAll(LowestLow1) == low
then BarNumber() else BeginBarL[1];
def BeginBar = HighestAll(Min(BeginBarH, BeginBarL));

# ===============================================================
# Plotting Section
# ===============================================================

#===================[ Define Plot Appearences ]=====================
DefineGlobalColor( "H1", Color.VIOLET);
DefineGlobalColor( "L1", Color.PINK);

HighestHigh1.SetPaintingStrategy( PaintingStrategy.DASHES );
HighestHigh1.SetLineWeight( lineWeight );
HighestHigh1.AssignValueColor( GlobalColor( "H1" ) );
HighestHigh1.HideBubble();

LowestLow1.SetPaintingStrategy( PaintingStrategy.DASHES );
LowestLow1.SetLineWeight( lineWeight );
LowestLow1.AssignValueColor( GlobalColor( "L1" ) );
LowestLow1.HideBubble();

AddChartBubble( Show1 and barNum == BeginBarH, HighestHigh1, "$" + HighestHigh1 + " @ " + GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + GetYear(), GlobalColor( "H1" ), yes );

AddChartBubble( Show1 and barNum == BeginBarL, LowestLow1, "$" + LowestLow1 + " @ " + GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + GetYear(), GlobalColor( "L1" ), no );



# ===============================================================
# Calculate Price & Time Forecast
# ===============================================================
 

Attachments

  • Gann_PriceAndTimeSTUDY.txt
    2.9 KB · Views: 168
Solution
Gann's Price & Time [Square The Range]

I'm scripting Gann's forecasting method to plot and display a calculated turning date, but I need help to capture the date and price that I've plotted in bubbles. Although I've found the high and low prices with their dates, I need help to capture those values into variables so that I can use them to continue to code in Gann's calculations. I'm including both the code below and the attached indicator file.

Code:
declare upper;

input numMonths1 = 5;
input VScale = 0.5;
input HScale = 5.0;
input GridSize = 50;

input Show1 = yes;
input lineWeight = 5;

def numdays = 21;

def numBars1 = numdays * numMonths1;
def barNum = if IsNaN( close ) then Double.NaN else BarNumber();
def lastBar...
Gann's Price & Time [Square The Range]

I'm scripting Gann's forecasting method to plot and display a calculated turning date, but I need help to capture the date and price that I've plotted in bubbles. Although I've found the high and low prices with their dates, I need help to capture those values into variables so that I can use them to continue to code in Gann's calculations. I'm including both the code below and the attached indicator file.

Code:
declare upper;

input numMonths1 = 5;
input VScale = 0.5;
input HScale = 5.0;
input GridSize = 50;

input Show1 = yes;
input lineWeight = 5;

def numdays = 21;

def numBars1 = numdays * numMonths1;
def barNum = if IsNaN( close ) then Double.NaN else BarNumber();
def lastBar = HighestAll( barNum );
def startBar1 = if lastBar <= numBars1 then 1 else lastBar - numBars1;
def bar = BarNumber();

def hData1 = If( barNum < startBar1, Double.NaN, high );
def lData1 = If( barNum < startBar1, Double.NaN, low );

def a_price = HighestAll(high);
def b_price = LowestAll(low);
def barnumber = BarNumber();
def c_price = if high == a_price then barnumber else Double.NaN;
def d_price = if low == b_price then barnumber else Double.NaN;
rec highnumber = CompoundValue(1, if IsNaN(c_price) then highnumber[1] else c_price, c_price);
def highnumberall = HighestAll(highnumber);
rec lownumber = CompoundValue(1, if IsNaN(d_price) then lownumber[1] else d_price, d_price);
def lownumberall = LowestAll(lownumber);

def months1 = Round( ( lastBar - startBar1 + 1 ) / 21, 0 );
plot HighestHigh1 = If( Show1, HighestAll( hData1 ), Double.NaN );
plot LowestLow1 = If( Show1, LowestAll( lData1 ), Double.NaN );

# ===============================================================
# Chart Bubbles
# ===============================================================
def BeginBarH = if barNum >= startBar1 and HighestAll(HighestHigh1) == high
then BarNumber() else BeginBarH[1];
def BeginBarL = if barNum >= startBar1 and HighestAll(LowestLow1) == low
then BarNumber() else BeginBarL[1];
def BeginBar = HighestAll(Min(BeginBarH, BeginBarL));

# ===============================================================
# Plotting Section
# ===============================================================

#===================[ Define Plot Appearences ]=====================
DefineGlobalColor( "H1", Color.VIOLET);
DefineGlobalColor( "L1", Color.PINK);

HighestHigh1.SetPaintingStrategy( PaintingStrategy.DASHES );
HighestHigh1.SetLineWeight( lineWeight );
HighestHigh1.AssignValueColor( GlobalColor( "H1" ) );
HighestHigh1.HideBubble();

LowestLow1.SetPaintingStrategy( PaintingStrategy.DASHES );
LowestLow1.SetLineWeight( lineWeight );
LowestLow1.AssignValueColor( GlobalColor( "L1" ) );
LowestLow1.HideBubble();

AddChartBubble( Show1 and barNum == BeginBarH, HighestHigh1, "$" + HighestHigh1 + " @ " + GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + GetYear(), GlobalColor( "H1" ), yes );

AddChartBubble( Show1 and barNum == BeginBarL, LowestLow1, "$" + LowestLow1 + " @ " + GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + GetYear(), GlobalColor( "L1" ), no );



# ===============================================================
# Calculate Price & Time Forecast
# ===============================================================

this saves the highest and lowest data in variables, in all bars.
is this what you want?

Code:
#gann_price_time_0

#https://usethinkscript.com/threads/ganns-price-time-square-the-range.16323/
#Gann's Price & Time [Square The Range]
#Picard  8/22

#Gann's Price & Time [Square The Range]

# I'm scripting Gann's forecasting method to plot and display a calculated turning date, 
#  but I need help to capture the date and price that I've plotted in bubbles. 
#  Although I've found the high and low prices with their dates, I need help to capture those values into variables so that I can use them to continue to code in Gann's calculations. I'm including both the code below and the attached indicator file.


declare upper;

input numMonths1 = 5;
input VScale = 0.5;
input HScale = 5.0;
input GridSize = 50;

input Show1 = yes;
input lineWeight = 5;

def numdays = 21;

def numBars1 = numdays * numMonths1;
def barNum = if IsNaN( close ) then Double.NaN else BarNumber();
def lastBar = HighestAll( barNum );
def startBar1 = if lastBar <= numBars1 then 1 else lastBar - numBars1;
def bar = BarNumber();

def hData1 = If( barNum < startBar1, Double.NaN, high );
def lData1 = If( barNum < startBar1, Double.NaN, low );

def a_price = HighestAll(high);
def b_price = LowestAll(low);
def barnumber = BarNumber();
def c_price = if high == a_price then barnumber else Double.NaN;
def d_price = if low == b_price then barnumber else Double.NaN;
rec highnumber = CompoundValue(1, if IsNaN(c_price) then highnumber[1] else c_price, c_price);
def highnumberall = HighestAll(highnumber);
rec lownumber = CompoundValue(1, if IsNaN(d_price) then lownumber[1] else d_price, d_price);
def lownumberall = LowestAll(lownumber);

def months1 = Round( ( lastBar - startBar1 + 1 ) / 21, 0 );
plot HighestHigh1 = If( Show1, HighestAll( hData1 ), Double.NaN );
plot LowestLow1 = If( Show1, LowestAll( lData1 ), Double.NaN );

# ===============================================================
# Chart Bubbles
# ===============================================================
def BeginBarH = if barNum >= startBar1 and HighestAll(HighestHigh1) == high
then BarNumber() else BeginBarH[1];
def BeginBarL = if barNum >= startBar1 and HighestAll(LowestLow1) == low
then BarNumber() else BeginBarL[1];
def BeginBar = HighestAll(Min(BeginBarH, BeginBarL));

# ===============================================================
# Plotting Section
# ===============================================================

#===================[ Define Plot Appearences ]=====================
DefineGlobalColor( "H1", Color.VIOLET);
DefineGlobalColor( "L1", Color.PINK);

HighestHigh1.SetPaintingStrategy( PaintingStrategy.DASHES );
HighestHigh1.SetLineWeight( lineWeight );
HighestHigh1.AssignValueColor( GlobalColor( "H1" ) );
HighestHigh1.HideBubble();

LowestLow1.SetPaintingStrategy( PaintingStrategy.DASHES );
LowestLow1.SetLineWeight( lineWeight );
LowestLow1.AssignValueColor( GlobalColor( "L1" ) );
LowestLow1.HideBubble();

AddChartBubble( Show1 and barNum == BeginBarH, HighestHigh1, "$" + HighestHigh1 + " @ " + GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + GetYear(), GlobalColor( "H1" ), yes );

AddChartBubble( Show1 and barNum == BeginBarL, LowestLow1, "$" + LowestLow1 + " @ " + GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + GetYear(), GlobalColor( "L1" ), no );



# ===============================================================
# Calculate Price & Time Forecast
# ===============================================================


def na = double.nan;
def bn = barnumber();

# save stats of highest and lowest, in variables, on all bars
# ------------
# hi

def hi_bn = highestall(if barNum == BeginBarH then BeginBarH else 0);
def hi_price = highestall(if barNum == BeginBarH then HighestHigh1 else 0);
def hi_month = highestall(if barNum == BeginBarH then GetMonth() else 0);
def hi_day = highestall(if barNum == BeginBarH then GetDayOfMonth(GetYYYYMMDD()) else 0);
def hi_year = highestall(if barNum == BeginBarH then GetYear() else 0);

input test1_hi = yes;
addchartbubble(test1_hi, high,
hi_bn + "\n" +
hi_price + "\n" +
hi_month + "\n" +
hi_day + "\n" +
hi_year + "\n" 
, color.yellow, yes);

input test2_hi = no;
addchartbubble(test2_hi, low, 
 bn + "\n" +
 BeginBarH + " H"
, (if BeginBarH > 0 then color.yellow else color.gray), no);


#------------
# low

def lo_bn = highestall(if barNum == BeginBarH then BeginBarl else 0);
def lo_price = highestall(if barNum == BeginBarH then lowestlow1 else 0);
def lo_month = highestall(if barNum == BeginBarH then GetMonth() else 0);
def lo_day = highestall(if barNum == BeginBarH then GetDayOfMonth(GetYYYYMMDD()) else 0);
def lo_year = highestall(if barNum == BeginBarH then GetYear() else 0);

input test3_lo = yes;
addchartbubble(test3_lo, low,
lo_bn + "\n" +
lo_price + "\n" +
lo_month + "\n" +
lo_day + "\n" +
lo_year + "\n" 
, color.yellow, no);

input test4_lo = no;
addchartbubble(test4_lo, low, 
 bn + "\n" +
 BeginBarl + " L"
, (if BeginBarl > 0 then color.yellow else color.gray), no);
#, color.yellow, no);

#-----------------
#

test bubbles on
Ye1BiQZ.jpg
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I've been making some progress by getting dates and prices on vertical lines, but there still some things that I'm having trouble with. 1.) I made some chart labels that I intended to put in the forecasted dates for the next calculated high and low, but I can't figure out how to format dates in these labels. 2.) I also made some vertical lines for these forecasted dates, but they don't show up on the chart. Possibly they are too far into the future. I've also attached the new code as a text file.
Code:
declare upper;

input numMonths1 = 36;
input VScale = 0.5;
input HScale = 5.0;
input GridSize = 50;
input modifier = 10;
input Show1      = yes;
input lineWeight = 5;

def numdays  = 21;

def numBars1  = numdays * numMonths1;
def barNum    = if IsNaN( close ) then Double.NaN else BarNumber();
def lastBar   = HighestAll( barNum );
def startBar1 = if lastBar <= numBars1 then 1 else lastBar - numBars1;
def bar = BarNumber();

def hData1    = If( barNum < startBar1, Double.NaN, high );
def lData1    = If( barNum < startBar1, Double.NaN, low );

def a_price   = HighestAll(high);
def b_price   = LowestAll(low);
def barnumber = BarNumber();
def c_price   = if high == a_price then barnumber else Double.NaN;
def d_price   = if low == b_price then barnumber else Double.NaN;
rec highnumber    = CompoundValue(1, if IsNaN(c_price) then highnumber[1] else c_price, c_price);
def highnumberall = HighestAll(highnumber);
rec lownumber     = CompoundValue(1, if IsNaN(d_price) then lownumber[1] else d_price, d_price);
def lownumberall  = LowestAll(lownumber);

def months1   = Round( ( lastBar - startBar1 + 1 ) / 21, 0 );
plot HighestHigh1 = If( Show1, HighestAll( hData1 ), Double.NaN );
plot LowestLow1   = If( Show1, LowestAll( lData1 ),  Double.NaN );

# ===============================================================
#                Chart Bubbles
# ===============================================================
def BeginBarH = if barNum >= startBar1 and HighestAll(HighestHigh1) == high
                then  BarNumber() else BeginBarH[1];
def BeginBarL = if barNum >= startBar1 and HighestAll(LowestLow1) == low
                then  BarNumber() else  BeginBarL[1];
def BeginBar  = HighestAll(Min(BeginBarH, BeginBarL));

# ===============================================================
#                Plotting Section
# ===============================================================

#===================[ Define Plot Appearences ]=====================
DefineGlobalColor( "H1", Color.CYAN);
DefineGlobalColor( "L1", Color.PINK);

HighestHigh1.SetPaintingStrategy( PaintingStrategy.DASHES );
HighestHigh1.SetLineWeight( lineWeight );
HighestHigh1.AssignValueColor( GlobalColor( "H1" ) );
HighestHigh1.HideBubble();

LowestLow1.SetPaintingStrategy( PaintingStrategy.DASHES );
LowestLow1.SetLineWeight( lineWeight );
LowestLow1.AssignValueColor( GlobalColor( "L1" ) );
LowestLow1.HideBubble();

AddChartBubble( Show1 and barNum == BeginBarH, HighestHigh1, "$" + AsText(HighestHigh1) +  " @ " + GetMonth() +  "/" + GetDayOfMonth(GetYYYYMMDD()) +  "/" + AsPrice(GetYear()), GlobalColor( "H1" ), yes  );

AddChartBubble( Show1 and barNum == BeginBarL, LowestLow1, "$" + AsText(LowestLow1)+  " @ " + GetMonth() +  "/" + GetDayOfMonth(GetYYYYMMDD()) +  "/" + AsPrice(GetYear()), GlobalColor( "L1" ), no  );


def begindate  = if BarNumber() == BeginBar then GetYYYYMMDD() else begindate[1];
def beginclose = if BarNumber() == BeginBar then close else beginclose[1];
def enddate    = if BarNumber() == BeginBar + GridSize then GetYYYYMMDD() else enddate[1];

def BeginPrice  = HighestAll(Min(HighestHigh1, LowestLow1));


def HighDate = if BarNumber() == BeginBarH then GetYYYYMMDD() else HighDate[1];
def LowDate = if BarNumber() == BeginBarL then GetYYYYMMDD() else LowDate[1];

# ===============================================================
#                Calculate Price & Time Forecast
# ===============================================================

# CountTradingDays ( int fromDate, int toDate);
#  AddLabel ( boolean visible, Any text, CustomColor color);

# Next High in
def NH = (HighestHigh1 / modifier) * 30.437;
# def HighPrice = if BarNumber() == Floor(BeginBarH) then AsDollars(high) else Double.NaN;
def NextHighDate = HighDate + NH;

def targetBar1 = DaysTillDate(NextHighDate) == 0;

# Next Low in
def NL = (LowestLow1 / modifier) * 30.437;
def NextLowDate = LowDate + NL;

AddLabel ( yes, "Next High in = " + AsText(NH)+ " Days", Color.BLUE);
AddLabel ( yes, "Next Low in = " + AsText(NL) + " Days", Color.RED);

AddVerticalLine(BarNumber() == Floor(BeginBarH), "                                  " + AsDollars(high) + " @ " + GetMonth() +  "/" + GetDayOfMonth(GetYYYYMMDD()) +  "/" + AsPrice(GetYear()), Color.BLUE, Curve.FIRM);

AddVerticalLine(BarNumber() == Floor(BeginBarL), "                                  " + AsDollars(low) + " @ " + GetMonth() +  "/" + GetDayOfMonth(GetYYYYMMDD()) +  "/" + AsPrice(GetYear()), Color.RED, Curve.FIRM);

# FORECASTED DATES & PRICES

AddVerticalLine(BarNumber() == Floor(BeginBarH + NH), "                                  " + " FORECASTED DATE & PRICE    " + AsDollars(high) + " @ " + GetMonth() +  "/" + GetDayOfMonth(GetYYYYMMDD()) +  "/" + AsPrice(GetYear()), Color.BLUE, Curve.MEDIUM_DASH);

AddVerticalLine(BarNumber() == Floor(BeginBarL + NL), "                                  " + " FORECASTED DATE & PRICE    " +  AsDollars(low) + " @ " + GetMonth() +  "/" + GetDayOfMonth(GetYYYYMMDD()) +  "/" + AsPrice(GetYear()), Color.RED, Curve.MEDIUM_DASH);
Code:
Time & Price 2.jpg
 

Attachments

  • Gann_PriceAndTime R2.txt
    5 KB · Views: 126
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
479 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top