GANN Square Of 9 Indicator for ThinkorSwim

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

@Katsu . On your chart under Patterns (far right) looks like sideways "S" click on it then you will see fit study. When you manully adjust chart it turn arrows with sideways 'S". Or do as MerryDay suggested on post #121
 
The GANN9 code in post 114 has been updated to version 1.2 with the following features:
  1. Fixed the "fit studies" bug
  2. Added a feature that allows this to work on forex and penny stocks. It normalizes very small values to have two decimal places, runs the calculation, then restores the original resolution. This is controlled by the "normalize to two dps" input parameter.
You can see here it looks pretty good on forex!


Merry Christmas!
 
I use GANN Sq of 9 AFL (Amibroker code) that show something like this every day at 8:30 AM CT (9:30 AM CT during Day light time Feb-Nov) with defined entry, stop loss and targets. It works 90% of the time every day. Sometimes you get both buy and sell trades on the same day. Target 3 and 4 are regular. Target 6 + are coming on trending days. BTW, the same entry points are visible on GANN Bigboss TOS script if you look at that time.


I can put the AFL code down, which is there on internet at several places. I don't know how to convert this to TOS or Ninja. I really needed this on Ninjatrader.

// Formula Name: TRAILING STOP PROFIT TAKER AFL By pipschart.com
// Author : KrT group
// Uploader : www.pipschart.com
// E-mail : [email protected]
// Amibroker Blog: www.pipschart.com/amibroker
// Origin : Modified & Collected from different sources.
//------------------------------------------------------
/*

*/
//------------------------------------------------------------------------------
_SECTION_BEGIN("Volume At Price");
PlotVAPOverlay( Param("Lines", 300, 100, 1000, 1 ), Param("Width", 12, 1, 100, 1 ), ParamColor("Color", colorViolet ), ParamToggle("Side", "Left|Right" ) | 4*ParamToggle("Z-order", "On top|Behind", 0 ) );
_SECTION_END();

_SECTION_BEGIN("JIMBERG");
EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );
ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) );
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorOrange, colorGrey50 ));
TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);

/* plot price chart and stops */
Plot( TrailStop, "Trailing stop", colorBrown, styleThick | styleLine );
Plot( ProfitTaker, "Profit taker", colorLime, styleThick );
Plot( C, "Price", color, styleCandle );

/* plot color ribbon */
Plot( 2, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );


/* **********************************

Code to automatically identify pivots

********************************** */

// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",100,50,5000,10);
nBars = Param("Number of bars", 12, 5, 40);

// -- Title.

/* Title = Name() + " (" + StrLeft(FullName(), 15) + ") O: " + Open + ",

H: " + High + ", L: " + Low + ", C: " + Close; */

// -- Plot basic candle chart

PlotOHLC(Open, High, Low, Close,

"\n" + "O = " + O + "\n"+"H = "+ H + "\n"+"L = " + L

+ "\n"+"C",

color, styleCandle);

GraphXSpace=7;

// -- Create 0-initialized arrays the size of barcount

aHPivs = H - H;

aLPivs = L - L;

// -- More for future use, not necessary for basic plotting

aHPivHighs = H - H;

aLPivLows = L - L;

aHPivIdxs = H - H;

aLPivIdxs = L - L;

nHPivs = 0;

nLPivs = 0;

lastHPIdx = 0;

lastLPIdx = 0;

lastHPH = 0;

lastLPL = 0;

curPivBarIdx = 0;

// -- looking back from the current bar, how many bars

// back were the hhv and llv values of the previous

// n bars, etc.?

aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);

// -- Would like to set this up so pivots are calculated back from

// last visible bar to make it easy to "go back" and see the pivots

// this code would find. However, the first instance of

// _Trace output will show a value of 0

aVisBars = Status("barvisible");

nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));

_TRACE("Last visible bar: " + nLastVisBar);

// -- Initialize value of curTrend

curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] <

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}

// -- Loop through bars. Search for

// entirely array-based approach

// in future version

for (i=0; i<farback; i++) {

curBar = (BarCount - 1) - i;

// -- Have we identified a pivot? If trend is down...

if (aLLVBars[curBar] < aHHVBars[curBar]) {

// ... and had been up, this is a trend change

if (curTrend == "U") {

curTrend = "D";

// -- Capture pivot information

curPivBarIdx = curBar - aLLVBars[curBar];

aLPivs[curPivBarIdx] = 1;

aLPivLows[nLPivs] = L[curPivBarIdx];

aLPivIdxs[nLPivs] = curPivBarIdx;

nLPivs++;

}

// -- or current trend is up

} else {

if (curTrend == "D") {

curTrend = "U";

curPivBarIdx = curBar - aHHVBars[curBar];

aHPivs[curPivBarIdx] = 1;

aHPivHighs[nHPivs] = H[curPivBarIdx];

aHPivIdxs[nHPivs] = curPivBarIdx;

nHPivs++;

}

// -- If curTrend is up...else...

}

// -- loop through bars

}

// -- Basic attempt to add a pivot this logic may have missed

// -- OK, now I want to look at last two pivots. If the most

// recent low pivot is after the last high, I could

// still have a high pivot that I didn't catch

// -- Start at last bar

curBar = (BarCount-1);

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if (lastLPIdx > lastHPIdx) {

// -- Bar and price info for candidate pivot

candIdx = curBar - aHHVBars[curBar];

candPrc = aHHV[curBar];

if (

lastHPH < candPrc AND

candIdx > lastLPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aHPivs[candIdx] = 1;

// ...and then rearrange elements in the

// pivot information arrays

for (j=0; j<nHPivs; j++) {

aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-

(j+1)];

aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];

}

aHPivHighs[0] = candPrc ;

aHPivIdxs[0] = candIdx;

nHPivs++;

}

} else {


// -- Bar and price info for candidate pivot

candIdx = curBar - aLLVBars[curBar];

candPrc = aLLV[curBar];

if (

lastLPL > candPrc AND

candIdx > lastHPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aLPivs[candIdx] = 1;

// ...and then rearrange elements in the

// pivot information arrays

for (j=0; j<nLPivs; j++) {

aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];

aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];

}

aLPivLows[0] = candPrc;

aLPivIdxs[0] = candIdx;

nLPivs++;

}

}

// -- Dump inventory of high pivots for debugging

/*

for (k=0; k<nHPivs; k++) {

_TRACE("High pivot no. " + k

+ " at barindex: " + aHPivIdxs[k] + ", "

+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],

DateTime(), 1), formatDateTime)

+ ", " + aHPivHighs[k]);

}

*/

// -- OK, let's plot the pivots using arrows

PlotShapes(

IIf(aHPivs==1, shapeDownArrow, shapeNone), colorRed, 0,

High, Offset=-15);

PlotShapes(
IIf(aLPivs==1, shapeUpArrow , shapeNone), colorGreen, 0,

Low, Offset=-15);

AlertIf( aHPivs==1, "SOUND C:\\Windows\\Media\\Ding.wav", "Sell " + C,2,1+2,1);
AlertIf( aLPivs==1, "SOUND C:\\Windows\\Media\\Ding.wav","Buy " + C,1,1+2,1);

_SECTION_END();

_SECTION_BEGIN("SkyBlue's Animated BkGround");

for( i = 1; i < BarCount; i++ )
z = (GetPerformanceCounter()/100)%256;
anim=ColorHSB( ( i + z ) % 256, 255, 100 );
SetChartBkColor(anim);
RequestTimedRefresh(1);

_SECTION_END();

/////GANN SQ of 9 indicator.
_SECTION_BEGIN("GaNN Square of Nine");

BarsToday = 1 + BarsSince( Day() != Ref(Day(), -1));

StartBar =Open;


RefOpen = ValueWhen(TimeNum() == Param("Stock/",092000,092000,100500,8500), Open,1);

BaseNum = (int(sqrt(RefOpen))-1);
sBelow = BaseNum + BaseNum;
sBelowI = 1;


//Calculate levels for GANN Square of Nine

for( i = 1; i < 50; i++ )
{
VarSet( "GANN"+i, (BaseNum * BaseNum) );
BaseNum = BaseNum + 0.125;
sBelowI = IIf( VarGet("GANN"+i)< RefOpen, i, sBelowI);
bAboveI = sBelowI + 1;
sBelow = round(VarGet("GANN"+sBelowI));
bAbove = round(VarGet("GANN"+bAboveI));
}

// Resistance Levels (or Targets for Buy trade)
BTgt1 = 0.9995 * VarGet("Gann"+(bAboveI+1));
BTgt2 = 0.9995 * VarGet("Gann"+(bAboveI+2));
BTgt3 = 0.9995 * VarGet("Gann"+(bAboveI+3));
BTgt4 = 0.9995 * VarGet("Gann"+(baboveI+4));
BTgt5 = 0.9995 * VarGet("Gann"+(bAboveI+5));
BTgt6 = 0.9995 * VarGet("Gann"+(baboveI+6));
// Support Levels (or Targets for Short trade)
STgt1 = 1.0005 * VarGet("Gann"+(sBelowI-1));
STgt2 = 1.0005 * VarGet("Gann"+(sBelowI-2));
STgt3 = 1.0005 * VarGet("Gann"+(sBelowI-3));
STgt4 = 1.0005 * VarGet("Gann"+(sbelowI-4));
STgt5 = 1.0005 * VarGet("Gann"+(sBelowI-5));
STgt6 = 1.0005 * VarGet("Gann"+(sBelowI-6));

Sstop= babove-((babove-sbelow)/3) ;
Bstop= sbelow+((babove-sbelow)/3) ;

BuySignal = TimeNum()>092000 AND Cross(C,babove);
ShortSignal = TimeNum()>092000 AND Cross(Sbelow,C);

BuySignal = ExRem(BuySignal,ShortSignal);
ShortSignal = ExRem(ShortSignal,BuySignal);

ShortProfitStop= (STgt1 AND L<=Stgt1 AND C>Stgt1) OR (STgt2 AND L<=Stgt2 AND C>Stgt2) OR (STgt3 AND L<=Stgt3 AND C>Stgt3) OR (STgt4 AND L<=Stgt4 AND C>Stgt4) OR (STgt5 AND L<=Stgt5 AND C>Stgt5) OR (STgt6 AND L<=Stgt6 AND C>Stgt6);

BuyProfitStop= (Btgt1 AND H>=btgt1 AND C<Btgt1) OR (Btgt2 AND H>=Btgt2 AND C<btgt2) OR (Btgt3 AND H>=Btgt3 AND C<btgt3) OR (Btgt4 AND H>=Btgt4 AND C<btgt4) OR (Btgt5 AND H>=Btgt5 AND C<btgt5) OR (Btgt6 AND H>=Btgt6 AND C<btgt6);
Buy = BuySignal;
Sell = C<Bstop ;
Short = ShortSignal;
Cover = C>SStop ;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);



Sstop= round(babove) ;
Bstop= round(sbelow) ;
_SECTION_BEGIN("Background text");
SetChartBkColor(colorBlack);
strWeekday = StrMid("---SUNDAY---MONDAY--TUESDAYWEDNESDAY-THURSDAY--FRIDAY--SATURDAY", SelectedValue(DayOfWeek())*9,9);
GraphXSpace=Param("GraphXSpace",0,-55,200,1);
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Candara", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15+200);
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor(ColorRGB (217,217,213));
GfxTextOut( "L.T.P. : "+ C +"", Status("pxwidth")/C14, Status("pxheight")/C15*2+200 );
GfxSelectFont("Candara", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( ""+DD+ " ( "+xx+"%)", Status("pxwidth")/C14, Status("pxheight")/C15*2.5+200);
GfxTextOut( "Sai Stock Broking", Status("pxwidth")/C14, Status("pxheight")/C15*2.5+220);
GfxTextOut( "09825340778", Status("pxwidth")/C14, Status("pxheight")/C15*2.5+240);
GfxSelectFont("Candara", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (0,265,0));
GfxTextOut( "Buy Above :"+sstop+"", Status("pxwidth")/C14-450, Status("pxheight")/C15*6);
GfxSetTextColor( ColorRGB (255,74,74));
GfxTextOut( "Buy S/L :"+Bstop+"", Status("pxwidth")/C14-350, Status("pxheight")/C15*7);
GfxSetTextColor( ColorRGB (265,0,0));
GfxTextOut( "Sell Below :"+bstop+"", Status("pxwidth")/C14+450, Status("pxheight")/C15*6);
GfxSetTextColor( ColorRGB (100,255,100));
GfxTextOut( "Sell S/L :"+sstop+"", Status("pxwidth")/C14+350, Status("pxheight")/C15*5);
GfxSetTextColor( ColorRGB (0,265,0));
GfxTextOut( "Buy TGT 1 : "+BTgt1+"", Status("pxwidth")/C14-350, Status("pxheight")/C15*5);
GfxTextOut( "Buy TGT 6 : "+BTgt6+"", Status("pxwidth")/C14+225, Status("pxheight")/C15*4);
GfxTextOut( "Buy TGT 2 : "+BTgt2+"", Status("pxwidth")/C14-225, Status("pxheight")/C15*4);
GfxTextOut( "Buy TGT 5 : "+BTgt5+"", Status("pxwidth")/C14+125, Status("pxheight")/C15*3);
GfxTextOut( "Buy TGT 3 : "+BTgt3+"", Status("pxwidth")/C14-125, Status("pxheight")/C15*3);
GfxTextOut( "Buy TGT 4 : "+BTgt4+"", Status("pxwidth")/C14, Status("pxheight")/C15*2);
GfxSetTextColor( ColorRGB (265,0,0));
GfxTextOut( "Sell TGT 1 : "+STgt1+"", Status("pxwidth")/C14+350, Status("pxheight")/C15*7);
GfxTextOut( "Sell TGT 6 : "+STgt6+"", Status("pxwidth")/C14-225, Status("pxheight")/C15*8);
GfxTextOut( "Sell TGT 2 : "+STgt2+"", Status("pxwidth")/C14+225, Status("pxheight")/C15*8);
GfxTextOut( "Sell TGT 5 : "+STgt5+"", Status("pxwidth")/C14-125, Status("pxheight")/C15*9);
GfxTextOut( "Sell TGT 3 : "+STgt3+"", Status("pxwidth")/C14+125, Status("pxheight")/C15*9);
GfxTextOut( "Sell TGT 4 : "+STgt4+"", Status("pxwidth")/C14, Status("pxheight")/C15*10);

_SECTION_END();

_SECTION_BEGIN("Title");

DODay = TimeFrameGetPrice("O", inDaily);
DHiDay = TimeFrameGetPrice("H", inDaily);
DLoDay = TimeFrameGetPrice("L", inDaily);
Title = EncodeColor(colorWhite)+EncodeColor(colorCustom8)+ "|| Sai Stock Broking - 09825340778 || "+EncodeColor(colorCustom10)+ Interval(2) + ", " + EncodeColor(colorCustom11)+Date() + EncodeColor(colorCustom14)+" - "+strWeekday + " - " +
EncodeColor(colorBlue) + "Open " + EncodeColor(colorWhite) + O +

EncodeColor(colorRed)+ " High : " +EncodeColor(colorWhite) + H +
EncodeColor(colorBrightGreen)+ " Low : " +EncodeColor(colorWhite) + L +
EncodeColor(colorCustom16) +" Close : " + EncodeColor(colorWhite) +C +
EncodeColor(colorBlue)+ " Day-Open : " +DODay + EncodeColor(colorBrightGreen)+" Day-High : " +DHiDay +EncodeColor(colorRed)+ " Day-Low : " + DLoDay
;
 
I use GANN Sq of 9 AFL (Amibroker code) that show something like this every day at 8:30 AM CT (9:30 AM CT during Day light time Feb-Nov) with defined entry, stop loss and targets. It works 90% of the time every day. Sometimes you get both buy and sell trades on the same day. Target 3 and 4 are regular. Target 6 + are coming on trending days. BTW, the same entry points are visible on GANN Bigboss TOS script if you look at that time.


I can put the AFL code down, which is there on internet at several places. I don't know how to convert this to TOS or Ninja. I really needed this on Ninjatrader.

// Formula Name: TRAILING STOP PROFIT TAKER AFL By pipschart.com
// Author : KrT group
// Uploader : www.pipschart.com
// E-mail : [email protected]
// Amibroker Blog: www.pipschart.com/amibroker
// Origin : Modified & Collected from different sources.
//------------------------------------------------------
/*

*/
//------------------------------------------------------------------------------
_SECTION_BEGIN("Volume At Price");
PlotVAPOverlay( Param("Lines", 300, 100, 1000, 1 ), Param("Width", 12, 1, 100, 1 ), ParamColor("Color", colorViolet ), ParamToggle("Side", "Left|Right" ) | 4*ParamToggle("Z-order", "On top|Behind", 0 ) );
_SECTION_END();

_SECTION_BEGIN("JIMBERG");
EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );
ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) );
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorOrange, colorGrey50 ));
TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);

/* plot price chart and stops */
Plot( TrailStop, "Trailing stop", colorBrown, styleThick | styleLine );
Plot( ProfitTaker, "Profit taker", colorLime, styleThick );
Plot( C, "Price", color, styleCandle );

/* plot color ribbon */
Plot( 2, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );


/* **********************************

Code to automatically identify pivots

********************************** */

// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",100,50,5000,10);
nBars = Param("Number of bars", 12, 5, 40);

// -- Title.

/* Title = Name() + " (" + StrLeft(FullName(), 15) + ") O: " + Open + ",

H: " + High + ", L: " + Low + ", C: " + Close; */

// -- Plot basic candle chart

PlotOHLC(Open, High, Low, Close,

"\n" + "O = " + O + "\n"+"H = "+ H + "\n"+"L = " + L

+ "\n"+"C",

color, styleCandle);

GraphXSpace=7;

// -- Create 0-initialized arrays the size of barcount

aHPivs = H - H;

aLPivs = L - L;

// -- More for future use, not necessary for basic plotting

aHPivHighs = H - H;

aLPivLows = L - L;

aHPivIdxs = H - H;

aLPivIdxs = L - L;

nHPivs = 0;

nLPivs = 0;

lastHPIdx = 0;

lastLPIdx = 0;

lastHPH = 0;

lastLPL = 0;

curPivBarIdx = 0;

// -- looking back from the current bar, how many bars

// back were the hhv and llv values of the previous

// n bars, etc.?

aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);

// -- Would like to set this up so pivots are calculated back from

// last visible bar to make it easy to "go back" and see the pivots

// this code would find. However, the first instance of

// _Trace output will show a value of 0

aVisBars = Status("barvisible");

nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));

_TRACE("Last visible bar: " + nLastVisBar);

// -- Initialize value of curTrend

curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] <

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}

// -- Loop through bars. Search for

// entirely array-based approach

// in future version

for (i=0; i<farback; i++) {

curBar = (BarCount - 1) - i;

// -- Have we identified a pivot? If trend is down...

if (aLLVBars[curBar] < aHHVBars[curBar]) {

// ... and had been up, this is a trend change

if (curTrend == "U") {

curTrend = "D";

// -- Capture pivot information

curPivBarIdx = curBar - aLLVBars[curBar];

aLPivs[curPivBarIdx] = 1;

aLPivLows[nLPivs] = L[curPivBarIdx];

aLPivIdxs[nLPivs] = curPivBarIdx;

nLPivs++;

}

// -- or current trend is up

} else {

if (curTrend == "D") {

curTrend = "U";

curPivBarIdx = curBar - aHHVBars[curBar];

aHPivs[curPivBarIdx] = 1;

aHPivHighs[nHPivs] = H[curPivBarIdx];

aHPivIdxs[nHPivs] = curPivBarIdx;

nHPivs++;

}

// -- If curTrend is up...else...

}

// -- loop through bars

}

// -- Basic attempt to add a pivot this logic may have missed

// -- OK, now I want to look at last two pivots. If the most

// recent low pivot is after the last high, I could

// still have a high pivot that I didn't catch

// -- Start at last bar

curBar = (BarCount-1);

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if (lastLPIdx > lastHPIdx) {

// -- Bar and price info for candidate pivot

candIdx = curBar - aHHVBars[curBar];

candPrc = aHHV[curBar];

if (

lastHPH < candPrc AND

candIdx > lastLPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aHPivs[candIdx] = 1;

// ...and then rearrange elements in the

// pivot information arrays

for (j=0; j<nHPivs; j++) {

aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-

(j+1)];

aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];

}

aHPivHighs[0] = candPrc ;

aHPivIdxs[0] = candIdx;

nHPivs++;

}

} else {


// -- Bar and price info for candidate pivot

candIdx = curBar - aLLVBars[curBar];

candPrc = aLLV[curBar];

if (

lastLPL > candPrc AND

candIdx > lastHPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aLPivs[candIdx] = 1;

// ...and then rearrange elements in the

// pivot information arrays

for (j=0; j<nLPivs; j++) {

aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];

aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];

}

aLPivLows[0] = candPrc;

aLPivIdxs[0] = candIdx;

nLPivs++;

}

}

// -- Dump inventory of high pivots for debugging

/*

for (k=0; k<nHPivs; k++) {

_TRACE("High pivot no. " + k

+ " at barindex: " + aHPivIdxs[k] + ", "

+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],

DateTime(), 1), formatDateTime)

+ ", " + aHPivHighs[k]);

}

*/

// -- OK, let's plot the pivots using arrows

PlotShapes(

IIf(aHPivs==1, shapeDownArrow, shapeNone), colorRed, 0,

High, Offset=-15);

PlotShapes(
IIf(aLPivs==1, shapeUpArrow , shapeNone), colorGreen, 0,

Low, Offset=-15);

AlertIf( aHPivs==1, "SOUND C:\\Windows\\Media\\Ding.wav", "Sell " + C,2,1+2,1);
AlertIf( aLPivs==1, "SOUND C:\\Windows\\Media\\Ding.wav","Buy " + C,1,1+2,1);

_SECTION_END();

_SECTION_BEGIN("SkyBlue's Animated BkGround");

for( i = 1; i < BarCount; i++ )
z = (GetPerformanceCounter()/100)%256;
anim=ColorHSB( ( i + z ) % 256, 255, 100 );
SetChartBkColor(anim);
RequestTimedRefresh(1);

_SECTION_END();

/////GANN SQ of 9 indicator.
_SECTION_BEGIN("GaNN Square of Nine");

BarsToday = 1 + BarsSince( Day() != Ref(Day(), -1));

StartBar =Open;


RefOpen = ValueWhen(TimeNum() == Param("Stock/",092000,092000,100500,8500), Open,1);

BaseNum = (int(sqrt(RefOpen))-1);
sBelow = BaseNum + BaseNum;
sBelowI = 1;


//Calculate levels for GANN Square of Nine

for( i = 1; i < 50; i++ )
{
VarSet( "GANN"+i, (BaseNum * BaseNum) );
BaseNum = BaseNum + 0.125;
sBelowI = IIf( VarGet("GANN"+i)< RefOpen, i, sBelowI);
bAboveI = sBelowI + 1;
sBelow = round(VarGet("GANN"+sBelowI));
bAbove = round(VarGet("GANN"+bAboveI));
}

// Resistance Levels (or Targets for Buy trade)
BTgt1 = 0.9995 * VarGet("Gann"+(bAboveI+1));
BTgt2 = 0.9995 * VarGet("Gann"+(bAboveI+2));
BTgt3 = 0.9995 * VarGet("Gann"+(bAboveI+3));
BTgt4 = 0.9995 * VarGet("Gann"+(baboveI+4));
BTgt5 = 0.9995 * VarGet("Gann"+(bAboveI+5));
BTgt6 = 0.9995 * VarGet("Gann"+(baboveI+6));
// Support Levels (or Targets for Short trade)
STgt1 = 1.0005 * VarGet("Gann"+(sBelowI-1));
STgt2 = 1.0005 * VarGet("Gann"+(sBelowI-2));
STgt3 = 1.0005 * VarGet("Gann"+(sBelowI-3));
STgt4 = 1.0005 * VarGet("Gann"+(sbelowI-4));
STgt5 = 1.0005 * VarGet("Gann"+(sBelowI-5));
STgt6 = 1.0005 * VarGet("Gann"+(sBelowI-6));

Sstop= babove-((babove-sbelow)/3) ;
Bstop= sbelow+((babove-sbelow)/3) ;

BuySignal = TimeNum()>092000 AND Cross(C,babove);
ShortSignal = TimeNum()>092000 AND Cross(Sbelow,C);

BuySignal = ExRem(BuySignal,ShortSignal);
ShortSignal = ExRem(ShortSignal,BuySignal);

ShortProfitStop= (STgt1 AND L<=Stgt1 AND C>Stgt1) OR (STgt2 AND L<=Stgt2 AND C>Stgt2) OR (STgt3 AND L<=Stgt3 AND C>Stgt3) OR (STgt4 AND L<=Stgt4 AND C>Stgt4) OR (STgt5 AND L<=Stgt5 AND C>Stgt5) OR (STgt6 AND L<=Stgt6 AND C>Stgt6);

BuyProfitStop= (Btgt1 AND H>=btgt1 AND C<Btgt1) OR (Btgt2 AND H>=Btgt2 AND C<btgt2) OR (Btgt3 AND H>=Btgt3 AND C<btgt3) OR (Btgt4 AND H>=Btgt4 AND C<btgt4) OR (Btgt5 AND H>=Btgt5 AND C<btgt5) OR (Btgt6 AND H>=Btgt6 AND C<btgt6);
Buy = BuySignal;
Sell = C<Bstop ;
Short = ShortSignal;
Cover = C>SStop ;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);



Sstop= round(babove) ;
Bstop= round(sbelow) ;
_SECTION_BEGIN("Background text");
SetChartBkColor(colorBlack);
strWeekday = StrMid("---SUNDAY---MONDAY--TUESDAYWEDNESDAY-THURSDAY--FRIDAY--SATURDAY", SelectedValue(DayOfWeek())*9,9);
GraphXSpace=Param("GraphXSpace",0,-55,200,1);
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Candara", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15+200);
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor(ColorRGB (217,217,213));
GfxTextOut( "L.T.P. : "+ C +"", Status("pxwidth")/C14, Status("pxheight")/C15*2+200 );
GfxSelectFont("Candara", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( ""+DD+ " ( "+xx+"%)", Status("pxwidth")/C14, Status("pxheight")/C15*2.5+200);
GfxTextOut( "Sai Stock Broking", Status("pxwidth")/C14, Status("pxheight")/C15*2.5+220);
GfxTextOut( "09825340778", Status("pxwidth")/C14, Status("pxheight")/C15*2.5+240);
GfxSelectFont("Candara", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (0,265,0));
GfxTextOut( "Buy Above :"+sstop+"", Status("pxwidth")/C14-450, Status("pxheight")/C15*6);
GfxSetTextColor( ColorRGB (255,74,74));
GfxTextOut( "Buy S/L :"+Bstop+"", Status("pxwidth")/C14-350, Status("pxheight")/C15*7);
GfxSetTextColor( ColorRGB (265,0,0));
GfxTextOut( "Sell Below :"+bstop+"", Status("pxwidth")/C14+450, Status("pxheight")/C15*6);
GfxSetTextColor( ColorRGB (100,255,100));
GfxTextOut( "Sell S/L :"+sstop+"", Status("pxwidth")/C14+350, Status("pxheight")/C15*5);
GfxSetTextColor( ColorRGB (0,265,0));
GfxTextOut( "Buy TGT 1 : "+BTgt1+"", Status("pxwidth")/C14-350, Status("pxheight")/C15*5);
GfxTextOut( "Buy TGT 6 : "+BTgt6+"", Status("pxwidth")/C14+225, Status("pxheight")/C15*4);
GfxTextOut( "Buy TGT 2 : "+BTgt2+"", Status("pxwidth")/C14-225, Status("pxheight")/C15*4);
GfxTextOut( "Buy TGT 5 : "+BTgt5+"", Status("pxwidth")/C14+125, Status("pxheight")/C15*3);
GfxTextOut( "Buy TGT 3 : "+BTgt3+"", Status("pxwidth")/C14-125, Status("pxheight")/C15*3);
GfxTextOut( "Buy TGT 4 : "+BTgt4+"", Status("pxwidth")/C14, Status("pxheight")/C15*2);
GfxSetTextColor( ColorRGB (265,0,0));
GfxTextOut( "Sell TGT 1 : "+STgt1+"", Status("pxwidth")/C14+350, Status("pxheight")/C15*7);
GfxTextOut( "Sell TGT 6 : "+STgt6+"", Status("pxwidth")/C14-225, Status("pxheight")/C15*8);
GfxTextOut( "Sell TGT 2 : "+STgt2+"", Status("pxwidth")/C14+225, Status("pxheight")/C15*8);
GfxTextOut( "Sell TGT 5 : "+STgt5+"", Status("pxwidth")/C14-125, Status("pxheight")/C15*9);
GfxTextOut( "Sell TGT 3 : "+STgt3+"", Status("pxwidth")/C14+125, Status("pxheight")/C15*9);
GfxTextOut( "Sell TGT 4 : "+STgt4+"", Status("pxwidth")/C14, Status("pxheight")/C15*10);

_SECTION_END();

_SECTION_BEGIN("Title");

DODay = TimeFrameGetPrice("O", inDaily);
DHiDay = TimeFrameGetPrice("H", inDaily);
DLoDay = TimeFrameGetPrice("L", inDaily);
Title = EncodeColor(colorWhite)+EncodeColor(colorCustom8)+ "|| Sai Stock Broking - 09825340778 || "+EncodeColor(colorCustom10)+ Interval(2) + ", " + EncodeColor(colorCustom11)+Date() + EncodeColor(colorCustom14)+" - "+strWeekday + " - " +
EncodeColor(colorBlue) + "Open " + EncodeColor(colorWhite) + O +

EncodeColor(colorRed)+ " High : " +EncodeColor(colorWhite) + H +
EncodeColor(colorBrightGreen)+ " Low : " +EncodeColor(colorWhite) + L +
EncodeColor(colorCustom16) +" Close : " + EncodeColor(colorWhite) +C +
EncodeColor(colorBlue)+ " Day-Open : " +DODay + EncodeColor(colorBrightGreen)+" Day-High : " +DHiDay +EncodeColor(colorRed)+ " Day-Low : " + DLoDay
;

This was GANN NQ levels today 8:20 AM CT.
 

This was GANN NQ levels today 8:20 AM CT.
@antojoseph take a look at the following code - I modified the Gann9 to start at 9:20 and use target calculations, ported the Trail Stop and Take Profit indicators and their bar coloring, and added in a study by mobius called scalper pivots that gets pretty close to the pivots the AFL code uses.

Ruby:
# PROFIT TAKER TRAIL STOP PIVOT GANN9
# ported (cobbled, hacked?!) to thinkscript by bigboss
# original by KrT Group / www.pipcharts.com
#
# Version 1.0 - 20211227 Initial port with Pivot, GANN9, and ATR components
#                        Todo: volume profile and ribbon

# JIMBERG
def EntrySignal = close > ( lowest( low, 20 ) + 2 * ATR( 10 ) );
def ExitSignal = close < ( highest( high, 20 ) - 2 * ATR( 10 ) );
AssignPriceColor(If EntrySignal then color.Blue else if ExitSignal then color.dark_Orange else color.Gray );

plot TrailStop = Highest( Close - 2 * ATR(10), 15 );
plot ProfitTaker = ExpAverage( high, 13 ) + 2 * ATR(10);
profittaker.setdefaultColor(color.lime);
trailstop.setdefaultColor(color.red);

#PIVOTS
# Mobius_Scalper_Pivots
# V01.2011
input n = 12;
#input ShowLines = yes;
#input SoundAlerts = yes;

def h = high;
def l = low;
def Firstbar = BarNumber();
def Highest = fold i = 1 to n + 1
              with p = 1
              while p
              do h > GetValue(h, -i);
def A = if (Firstbar > n and
            h == Highest(h, n) and
            Highest)
        then h
        else Double.NaN;
def Lowest = fold j = 1 to n + 1
             with q = 1
             while q
             do l < GetValue(l, -j);
def B = if (Firstbar > n and
            l == Lowest(l, n) and Lowest)
        then l
        else Double.NaN;
def Al = if !IsNaN(A)
         then A
         else Al[1];
def Bl = if !IsNaN(B)
         then B
         else Bl[1];

plot ph = Round(A, 2);
     ph.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
     ph.SetDefaultColor(Color.RED);


plot pl = Round(B, 2);
     pl.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
     pl.SetDefaultColor(Color.GREEN);

# End Study Mobius_Scalper_Pivots

# GANN9 by bigboss
input normalizeGannToTwoDps = yes; #hint normalizeToTwoSDs: treat small values (e.g. forex, penny stocks) as if they are large values with two digits after the decimal.

# This gets the # of significant digits to round values to.
def rf = fold index = 1 to 10 with c = 1 while power(10,index)*ticksize()%1 != 0 do c+1;
def mf = if normalizeGannToTwoDps then power(10,rf-2) else 1;

def srFactor = .0005;

def rthStart = RegularTradingStart(GetYYYYMMDD());
def rthEnd = RegularTradingEnd(GetYYYYMMDD());

input Gann9StartTime = 0920;

def isupdateTime =
    if secondsTillTime(Gann9StartTime) == 0
or barnumber() == 1
then 1 else 0;

# if Show after hours is yes, then always show the lines, otherwise only between RTH

def gannprice = if isupdateTime then sqrt(open * mf) else gannprice[1];
def gannpricebase = rounddown(gannprice,0);

# Calculate the angle of price, and adjust if it is a multiple of 45 degrees so the buy/sell lines are unique.
def angle = gannprice - gannpricebase;
def angleAdjusted = if angle % .125 == 0 then angle+.001 else angle;

# Calculate the buy and sell lines, which are the nearest angle cleanly divisible by 45 above and below price.
def lowergannangle = rounddown(angleadjusted / .125,0)*.125;
def uppergannangle = roundup(angleadjusted / .125,0)*.125;
plot SellBelow = round(power(gannpricebase + lowergannangle,2)/mf,rf);
plot BuyAbove = round(power(gannpricebase + uppergannangle,2)/mf,rf);

# Calculate the next 5 resistance/targets, each in +45 degrees increments from the BuyAbove price
plot R1 = round(power(gannpricebase + uppergannangle+.125,2)*(1-srfactor)/mf,rf);
plot R2 = round(power(gannpricebase + uppergannangle+.250,2)*(1-srfactor)/mf,rf);
plot R3 = round(power(gannpricebase + uppergannangle+.375,2)*(1-srfactor)/mf,rf);
plot R4 = round(power(gannpricebase + uppergannangle+.500,2)*(1-srfactor)/mf,rf);
plot R5 = round(power(gannpricebase + uppergannangle+.625,2)*(1-srfactor)/mf,rf);
plot R6 = round(power(gannpricebase + uppergannangle+.750,2)*(1-srfactor)/mf,rf);

# Calculate the next 5 support/targets, each in -45 degree increments from the SellBelow price
plot S1 = round(power(gannpricebase + lowergannangle-.125,2)*(1+srfactor)/mf,rf);
plot S2 = round(power(gannpricebase + lowergannangle-.250,2)*(1+srfactor)/mf,rf);
plot S3 = round(power(gannpricebase + lowergannangle-.375,2)*(1+srfactor)/mf,rf);
plot S4 = round(power(gannpricebase + lowergannangle-.500,2)*(1+srfactor)/mf,rf);
plot S5 = round(power(gannpricebase + lowergannangle-.625,2)*(1+srfactor)/mf,rf);
plot S6 = round(power(gannpricebase + uppergannangle+.750,2)*(1-srfactor)/mf,rf);

SellBelow.SetDefaultColor(Color.RED);
BuyAbove.SetDefaultColor(Color.GREEN);

R1.SetDefaultColor(color.dark_gray);
R2.SetDefaultColor(color.dark_gray);
R3.SetDefaultColor(color.dark_gray);
R4.SetDefaultColor(color.dark_gray);
R5.SetDefaultColor(color.dark_gray);
R6.SetDefaultColor(color.dark_gray);

S1.SetDefaultColor(color.dark_gray);
S2.SetDefaultColor(color.dark_gray);
S3.SetDefaultColor(color.dark_gray);
S4.SetDefaultColor(color.dark_gray);
S5.SetDefaultColor(color.dark_gray);
S6.SetDefaultColor(color.dark_gray);

AddLabel(1, "Buy Above: $" + BuyAbove, color.green);
AddLabel(1, "Sell Below: $" + SellBelow, color.red);

/NQ 1 min 12/23

/NQ 5 min 12/27
 
Last edited:
@antojoseph take a look at the following code - I modified the Gann9 to start at 9:20 and use target calculations, ported the Trail Stop and Take Profit indicators and their bar coloring, and added in a study by mobius called scalper pivots that gets pretty close to the pivots the AFL code uses.

Ruby:
# PROFIT TAKER TRAIL STOP PIVOT GANN9
# ported (cobbled, hacked?!) to thinkscript by bigboss
# original by KrT Group / www.pipcharts.com
#
# Version 1.0 - 20211227 Initial port with Pivot, GANN9, and ATR components
#                        Todo: volume profile and ribbon

# JIMBERG
def EntrySignal = close > ( lowest( low, 20 ) + 2 * ATR( 10 ) );
def ExitSignal = close < ( highest( high, 20 ) - 2 * ATR( 10 ) );
AssignPriceColor(If EntrySignal then color.Blue else if ExitSignal then color.dark_Orange else color.Gray );

plot TrailStop = Highest( Close - 2 * ATR(10), 15 );
plot ProfitTaker = ExpAverage( high, 13 ) + 2 * ATR(10);
profittaker.setdefaultColor(color.lime);
trailstop.setdefaultColor(color.red);

#PIVOTS
# Mobius_Scalper_Pivots
# V01.2011
input n = 12;
#input ShowLines = yes;
#input SoundAlerts = yes;

def h = high;
def l = low;
def Firstbar = BarNumber();
def Highest = fold i = 1 to n + 1
              with p = 1
              while p
              do h > GetValue(h, -i);
def A = if (Firstbar > n and
            h == Highest(h, n) and
            Highest)
        then h
        else Double.NaN;
def Lowest = fold j = 1 to n + 1
             with q = 1
             while q
             do l < GetValue(l, -j);
def B = if (Firstbar > n and
            l == Lowest(l, n) and Lowest)
        then l
        else Double.NaN;
def Al = if !IsNaN(A)
         then A
         else Al[1];
def Bl = if !IsNaN(B)
         then B
         else Bl[1];

plot ph = Round(A, 2);
     ph.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
     ph.SetDefaultColor(Color.RED);


plot pl = Round(B, 2);
     pl.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
     pl.SetDefaultColor(Color.GREEN);

# End Study Mobius_Scalper_Pivots

# GANN9 by bigboss
input normalizeGannToTwoDps = yes; #hint normalizeToTwoSDs: treat small values (e.g. forex, penny stocks) as if they are large values with two digits after the decimal.

# This gets the # of significant digits to round values to.
def rf = fold index = 1 to 10 with c = 1 while power(10,index)*ticksize()%1 != 0 do c+1;
def mf = if normalizeGannToTwoDps then power(10,rf-2) else 1;

def srFactor = .0005;

def rthStart = RegularTradingStart(GetYYYYMMDD());
def rthEnd = RegularTradingEnd(GetYYYYMMDD());

input Gann9StartTime = 0920;

def isupdateTime =
    if secondsTillTime(Gann9StartTime) == 0
or barnumber() == 1
then 1 else 0;

# if Show after hours is yes, then always show the lines, otherwise only between RTH

def gannprice = if isupdateTime then sqrt(open * mf) else gannprice[1];
def gannpricebase = rounddown(gannprice,0);

# Calculate the angle of price, and adjust if it is a multiple of 45 degrees so the buy/sell lines are unique.
def angle = gannprice - gannpricebase;
def angleAdjusted = if angle % .125 == 0 then angle+.001 else angle;

# Calculate the buy and sell lines, which are the nearest angle cleanly divisible by 45 above and below price.
def lowergannangle = rounddown(angleadjusted / .125,0)*.125;
def uppergannangle = roundup(angleadjusted / .125,0)*.125;
plot SellBelow = round(power(gannpricebase + lowergannangle,2)/mf,rf);
plot BuyAbove = round(power(gannpricebase + uppergannangle,2)/mf,rf);

# Calculate the next 5 resistance/targets, each in +45 degrees increments from the BuyAbove price
plot R1 = round(power(gannpricebase + uppergannangle+.125,2)*(1-srfactor)/mf,rf);
plot R2 = round(power(gannpricebase + uppergannangle+.250,2)*(1-srfactor)/mf,rf);
plot R3 = round(power(gannpricebase + uppergannangle+.375,2)*(1-srfactor)/mf,rf);
plot R4 = round(power(gannpricebase + uppergannangle+.500,2)*(1-srfactor)/mf,rf);
plot R5 = round(power(gannpricebase + uppergannangle+.625,2)*(1-srfactor)/mf,rf);
plot R6 = round(power(gannpricebase + uppergannangle+.750,2)*(1-srfactor)/mf,rf);

# Calculate the next 5 support/targets, each in -45 degree increments from the SellBelow price
plot S1 = round(power(gannpricebase + lowergannangle-.125,2)*(1+srfactor)/mf,rf);
plot S2 = round(power(gannpricebase + lowergannangle-.250,2)*(1+srfactor)/mf,rf);
plot S3 = round(power(gannpricebase + lowergannangle-.375,2)*(1+srfactor)/mf,rf);
plot S4 = round(power(gannpricebase + lowergannangle-.500,2)*(1+srfactor)/mf,rf);
plot S5 = round(power(gannpricebase + lowergannangle-.625,2)*(1+srfactor)/mf,rf);
plot S6 = round(power(gannpricebase + uppergannangle+.750,2)*(1-srfactor)/mf,rf);

SellBelow.SetDefaultColor(Color.RED);
BuyAbove.SetDefaultColor(Color.GREEN);

R1.SetDefaultColor(color.dark_gray);
R2.SetDefaultColor(color.dark_gray);
R3.SetDefaultColor(color.dark_gray);
R4.SetDefaultColor(color.dark_gray);
R5.SetDefaultColor(color.dark_gray);
R6.SetDefaultColor(color.dark_gray);

S1.SetDefaultColor(color.dark_gray);
S2.SetDefaultColor(color.dark_gray);
S3.SetDefaultColor(color.dark_gray);
S4.SetDefaultColor(color.dark_gray);
S5.SetDefaultColor(color.dark_gray);
S6.SetDefaultColor(color.dark_gray);

AddLabel(1, "Buy Above: $" + BuyAbove, color.green);
AddLabel(1, "Sell Below: $" + SellBelow, color.red);

/NQ 1 min 12/23

/NQ 5 min 12/27
Wow, this is beautiful. Thanks a lot BigBoss!
 
@bigboss Thanks for providing your code, i loaded it. It looks dope, when I was running it today, can you let me know if those up and down arrows (ph and pl) are supposed to be real-time or is it like end of the day, it will refresh? i didn't see any arrow pop up today for the first 2.5hours, but now that I went back, i'm seeing a lot more arrows. Thanks
 
@bigboss Thanks for providing your code, i loaded it. It looks dope, when I was running it today, can you let me know if those up and down arrows (ph and pl) are supposed to be real-time or is it like end of the day, it will refresh? i didn't see any arrow pop up today for the first 2.5hours, but now that I went back, i'm seeing a lot more arrows. Thanks

The arrows lag by a certain number of bars depending on what input you put for "n". I'm not that happy with the pivot points so I'll probably change it out to use something more responsive -- there are quite a few pivot point studies around here.
 
The arrows lag by a certain number of bars depending on what input you put for "n". I'm not that happy with the pivot points so I'll probably change it out to use something more responsive -- there are quite a few pivot point studies around here.
got it; i'll play around with it, if you happen to see a better pivot set up and update the code. I'd appreciate it truly if you share it here too. thanks!
 
which platform is that on? I tried to add it to TOS, but my levels look funny. doesn't look like your setup or any other setups that people posted up. Is there a setting i have to change? Which version is the latest one to download?
Did you know that clicking on a member's avatar will allow you to see when a member was last seen on the uTS forum? @babouin77 has not been seen in a while. :(
 
heres a code that also calculates the positive gann square of nine from yesterdays close, i am trying to code it so it can be switched from todays open is you wish. the code is there i just have it turned off.
Code:
#calculates gann square of 9 based on either todays open or yesterdays close.



input aggregationPeriod = AggregationPeriod.DAY;

def yesterday= close(period = aggregationPeriod)[1];
#def today = open(period = aggregationPeriod);


def sh= yesterday;

def data00 = Sqrt(sh) - (0 / 180);
def data0 = Power(data00, 2);
plot line00 = data0;


def data45 = Sqrt(sh) - (45 / 180);
def data1 = Power(data45, 2);
plot line45 = data1;
def up1 = sh- line45;
plot up11 = up1+ sh;
line45.SetDefaultColor(Color.GREEN);
up11.SetDefaultColor(Color.red);

def data90 = Sqrt(sh) - (90 / 180);
def data2 = Power(data90, 2);
plot line90 = data2;
def up2 = sh- line90;
plot up22= sh +up2;
up22.SetDefaultColor(Color.red);

line90.SetDefaultColor(Color.GREEN);

def data135 = Sqrt(sh) - (135 / 180);
def data3 = Power(data135, 2);
plot line135 = data3;
def up3 = sh- line135;
plot up33 = sh+ up3;
up33.SetDefaultColor(Color.red);

line135.SetDefaultColor(Color.GREEN);
the code doesn't work. Is there version that I should be downloading?
 
@antojoseph take a look at the following code - I modified the Gann9 to start at 9:20 and use target calculations, ported the Trail Stop and Take Profit indicators and their bar coloring, and added in a study by mobius called scalper pivots that gets pretty close to the pivots the AFL code uses.

Ruby:
# PROFIT TAKER TRAIL STOP PIVOT GANN9
# ported (cobbled, hacked?!) to thinkscript by bigboss
# original by KrT Group / www.pipcharts.com
#
# Version 1.0 - 20211227 Initial port with Pivot, GANN9, and ATR components
#                        Todo: volume profile and ribbon

# JIMBERG
def EntrySignal = close > ( lowest( low, 20 ) + 2 * ATR( 10 ) );
def ExitSignal = close < ( highest( high, 20 ) - 2 * ATR( 10 ) );
AssignPriceColor(If EntrySignal then color.Blue else if ExitSignal then color.dark_Orange else color.Gray );

plot TrailStop = Highest( Close - 2 * ATR(10), 15 );
plot ProfitTaker = ExpAverage( high, 13 ) + 2 * ATR(10);
profittaker.setdefaultColor(color.lime);
trailstop.setdefaultColor(color.red);

#PIVOTS
# Mobius_Scalper_Pivots
# V01.2011
input n = 12;
#input ShowLines = yes;
#input SoundAlerts = yes;

def h = high;
def l = low;
def Firstbar = BarNumber();
def Highest = fold i = 1 to n + 1
              with p = 1
              while p
              do h > GetValue(h, -i);
def A = if (Firstbar > n and
            h == Highest(h, n) and
            Highest)
        then h
        else Double.NaN;
def Lowest = fold j = 1 to n + 1
             with q = 1
             while q
             do l < GetValue(l, -j);
def B = if (Firstbar > n and
            l == Lowest(l, n) and Lowest)
        then l
        else Double.NaN;
def Al = if !IsNaN(A)
         then A
         else Al[1];
def Bl = if !IsNaN(B)
         then B
         else Bl[1];

plot ph = Round(A, 2);
     ph.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
     ph.SetDefaultColor(Color.RED);


plot pl = Round(B, 2);
     pl.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
     pl.SetDefaultColor(Color.GREEN);

# End Study Mobius_Scalper_Pivots

# GANN9 by bigboss
input normalizeGannToTwoDps = yes; #hint normalizeToTwoSDs: treat small values (e.g. forex, penny stocks) as if they are large values with two digits after the decimal.

# This gets the # of significant digits to round values to.
def rf = fold index = 1 to 10 with c = 1 while power(10,index)*ticksize()%1 != 0 do c+1;
def mf = if normalizeGannToTwoDps then power(10,rf-2) else 1;

def srFactor = .0005;

def rthStart = RegularTradingStart(GetYYYYMMDD());
def rthEnd = RegularTradingEnd(GetYYYYMMDD());

input Gann9StartTime = 0920;

def isupdateTime =
    if secondsTillTime(Gann9StartTime) == 0
or barnumber() == 1
then 1 else 0;

# if Show after hours is yes, then always show the lines, otherwise only between RTH

def gannprice = if isupdateTime then sqrt(open * mf) else gannprice[1];
def gannpricebase = rounddown(gannprice,0);

# Calculate the angle of price, and adjust if it is a multiple of 45 degrees so the buy/sell lines are unique.
def angle = gannprice - gannpricebase;
def angleAdjusted = if angle % .125 == 0 then angle+.001 else angle;

# Calculate the buy and sell lines, which are the nearest angle cleanly divisible by 45 above and below price.
def lowergannangle = rounddown(angleadjusted / .125,0)*.125;
def uppergannangle = roundup(angleadjusted / .125,0)*.125;
plot SellBelow = round(power(gannpricebase + lowergannangle,2)/mf,rf);
plot BuyAbove = round(power(gannpricebase + uppergannangle,2)/mf,rf);

# Calculate the next 5 resistance/targets, each in +45 degrees increments from the BuyAbove price
plot R1 = round(power(gannpricebase + uppergannangle+.125,2)*(1-srfactor)/mf,rf);
plot R2 = round(power(gannpricebase + uppergannangle+.250,2)*(1-srfactor)/mf,rf);
plot R3 = round(power(gannpricebase + uppergannangle+.375,2)*(1-srfactor)/mf,rf);
plot R4 = round(power(gannpricebase + uppergannangle+.500,2)*(1-srfactor)/mf,rf);
plot R5 = round(power(gannpricebase + uppergannangle+.625,2)*(1-srfactor)/mf,rf);
plot R6 = round(power(gannpricebase + uppergannangle+.750,2)*(1-srfactor)/mf,rf);

# Calculate the next 5 support/targets, each in -45 degree increments from the SellBelow price
plot S1 = round(power(gannpricebase + lowergannangle-.125,2)*(1+srfactor)/mf,rf);
plot S2 = round(power(gannpricebase + lowergannangle-.250,2)*(1+srfactor)/mf,rf);
plot S3 = round(power(gannpricebase + lowergannangle-.375,2)*(1+srfactor)/mf,rf);
plot S4 = round(power(gannpricebase + lowergannangle-.500,2)*(1+srfactor)/mf,rf);
plot S5 = round(power(gannpricebase + lowergannangle-.625,2)*(1+srfactor)/mf,rf);
plot S6 = round(power(gannpricebase + uppergannangle+.750,2)*(1-srfactor)/mf,rf);

SellBelow.SetDefaultColor(Color.RED);
BuyAbove.SetDefaultColor(Color.GREEN);

R1.SetDefaultColor(color.dark_gray);
R2.SetDefaultColor(color.dark_gray);
R3.SetDefaultColor(color.dark_gray);
R4.SetDefaultColor(color.dark_gray);
R5.SetDefaultColor(color.dark_gray);
R6.SetDefaultColor(color.dark_gray);

S1.SetDefaultColor(color.dark_gray);
S2.SetDefaultColor(color.dark_gray);
S3.SetDefaultColor(color.dark_gray);
S4.SetDefaultColor(color.dark_gray);
S5.SetDefaultColor(color.dark_gray);
S6.SetDefaultColor(color.dark_gray);

AddLabel(1, "Buy Above: $" + BuyAbove, color.green);
AddLabel(1, "Sell Below: $" + SellBelow, color.red);

/NQ 1 min 12/23

/NQ 5 min 12/27
@bigboss hi, just chance upon this script, it looks pretty impressive on SPY, just like to know if the signal will repaint? thank u
 
I am not seeing a red dot when the price hit $3845, can u please help understand what time you checked?

IKC6MrG.png
hi, can you share the strategy version with me? thank you in advance.
 
@antojoseph take a look at the following code - I modified the Gann9 to start at 9:20 and use target calculations, ported the Trail Stop and Take Profit indicators and their bar coloring, and added in a study by mobius called scalper pivots that gets pretty close to the pivots the AFL code uses.

Ruby:
# PROFIT TAKER TRAIL STOP PIVOT GANN9
# ported (cobbled, hacked?!) to thinkscript by bigboss
# original by KrT Group / www.pipcharts.com
#
# Version 1.0 - 20211227 Initial port with Pivot, GANN9, and ATR components
#                        Todo: volume profile and ribbon

# JIMBERG
def EntrySignal = close > ( lowest( low, 20 ) + 2 * ATR( 10 ) );
def ExitSignal = close < ( highest( high, 20 ) - 2 * ATR( 10 ) );
AssignPriceColor(If EntrySignal then color.Blue else if ExitSignal then color.dark_Orange else color.Gray );

plot TrailStop = Highest( Close - 2 * ATR(10), 15 );
plot ProfitTaker = ExpAverage( high, 13 ) + 2 * ATR(10);
profittaker.setdefaultColor(color.lime);
trailstop.setdefaultColor(color.red);

#PIVOTS
# Mobius_Scalper_Pivots
# V01.2011
input n = 12;
#input ShowLines = yes;
#input SoundAlerts = yes;

def h = high;
def l = low;
def Firstbar = BarNumber();
def Highest = fold i = 1 to n + 1
              with p = 1
              while p
              do h > GetValue(h, -i);
def A = if (Firstbar > n and
            h == Highest(h, n) and
            Highest)
        then h
        else Double.NaN;
def Lowest = fold j = 1 to n + 1
             with q = 1
             while q
             do l < GetValue(l, -j);
def B = if (Firstbar > n and
            l == Lowest(l, n) and Lowest)
        then l
        else Double.NaN;
def Al = if !IsNaN(A)
         then A
         else Al[1];
def Bl = if !IsNaN(B)
         then B
         else Bl[1];

plot ph = Round(A, 2);
     ph.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
     ph.SetDefaultColor(Color.RED);


plot pl = Round(B, 2);
     pl.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
     pl.SetDefaultColor(Color.GREEN);

# End Study Mobius_Scalper_Pivots

# GANN9 by bigboss
input normalizeGannToTwoDps = yes; #hint normalizeToTwoSDs: treat small values (e.g. forex, penny stocks) as if they are large values with two digits after the decimal.

# This gets the # of significant digits to round values to.
def rf = fold index = 1 to 10 with c = 1 while power(10,index)*ticksize()%1 != 0 do c+1;
def mf = if normalizeGannToTwoDps then power(10,rf-2) else 1;

def srFactor = .0005;

def rthStart = RegularTradingStart(GetYYYYMMDD());
def rthEnd = RegularTradingEnd(GetYYYYMMDD());

input Gann9StartTime = 0920;

def isupdateTime =
    if secondsTillTime(Gann9StartTime) == 0
or barnumber() == 1
then 1 else 0;

# if Show after hours is yes, then always show the lines, otherwise only between RTH

def gannprice = if isupdateTime then sqrt(open * mf) else gannprice[1];
def gannpricebase = rounddown(gannprice,0);

# Calculate the angle of price, and adjust if it is a multiple of 45 degrees so the buy/sell lines are unique.
def angle = gannprice - gannpricebase;
def angleAdjusted = if angle % .125 == 0 then angle+.001 else angle;

# Calculate the buy and sell lines, which are the nearest angle cleanly divisible by 45 above and below price.
def lowergannangle = rounddown(angleadjusted / .125,0)*.125;
def uppergannangle = roundup(angleadjusted / .125,0)*.125;
plot SellBelow = round(power(gannpricebase + lowergannangle,2)/mf,rf);
plot BuyAbove = round(power(gannpricebase + uppergannangle,2)/mf,rf);

# Calculate the next 5 resistance/targets, each in +45 degrees increments from the BuyAbove price
plot R1 = round(power(gannpricebase + uppergannangle+.125,2)*(1-srfactor)/mf,rf);
plot R2 = round(power(gannpricebase + uppergannangle+.250,2)*(1-srfactor)/mf,rf);
plot R3 = round(power(gannpricebase + uppergannangle+.375,2)*(1-srfactor)/mf,rf);
plot R4 = round(power(gannpricebase + uppergannangle+.500,2)*(1-srfactor)/mf,rf);
plot R5 = round(power(gannpricebase + uppergannangle+.625,2)*(1-srfactor)/mf,rf);
plot R6 = round(power(gannpricebase + uppergannangle+.750,2)*(1-srfactor)/mf,rf);

# Calculate the next 5 support/targets, each in -45 degree increments from the SellBelow price
plot S1 = round(power(gannpricebase + lowergannangle-.125,2)*(1+srfactor)/mf,rf);
plot S2 = round(power(gannpricebase + lowergannangle-.250,2)*(1+srfactor)/mf,rf);
plot S3 = round(power(gannpricebase + lowergannangle-.375,2)*(1+srfactor)/mf,rf);
plot S4 = round(power(gannpricebase + lowergannangle-.500,2)*(1+srfactor)/mf,rf);
plot S5 = round(power(gannpricebase + lowergannangle-.625,2)*(1+srfactor)/mf,rf);
plot S6 = round(power(gannpricebase + uppergannangle+.750,2)*(1-srfactor)/mf,rf);

SellBelow.SetDefaultColor(Color.RED);
BuyAbove.SetDefaultColor(Color.GREEN);

R1.SetDefaultColor(color.dark_gray);
R2.SetDefaultColor(color.dark_gray);
R3.SetDefaultColor(color.dark_gray);
R4.SetDefaultColor(color.dark_gray);
R5.SetDefaultColor(color.dark_gray);
R6.SetDefaultColor(color.dark_gray);

S1.SetDefaultColor(color.dark_gray);
S2.SetDefaultColor(color.dark_gray);
S3.SetDefaultColor(color.dark_gray);
S4.SetDefaultColor(color.dark_gray);
S5.SetDefaultColor(color.dark_gray);
S6.SetDefaultColor(color.dark_gray);

AddLabel(1, "Buy Above: $" + BuyAbove, color.green);
AddLabel(1, "Sell Below: $" + SellBelow, color.red);

/NQ 1 min 12/23

/NQ 5 min 12/27
I was curious. When does the does the arrows get triggered or when does the arrow actually show up. Is it after the move had already happened? Is there a way the indicator shows up 1 bar after?
 
I was curious. When does the does the arrows get triggered or when does the arrow actually show up. Is it after the move had already happened? Is there a way the indicator shows up 1 bar after?
Those arrows repaint. The arrows are painted after the fact when the low or high has been established.
This is not the traditional manner of using Mobius Trend Pivots. They are meant to be used as Support&Resistance bands not arrows.
The support or the resistance gets repainted when price breaks below / above.
Here is the original study: https://usethinkscript.com/threads/...ort-resistance-indicator-for-thinkorswim.158/
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
550 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