Sunday, 24 November 2019

মার্কেট এর সাথে সাথে এই শেয়ারগুলার পজিশন ও একটু একটু করে উপরের দিকে উঠে চলছে

মার্কেট এর সাথে সাথে এই শেয়ারগুলার পজিশন ও একটু একটু করে উপরের দিকে উঠে চলছে , এমন ভাবে বাকী শেয়ার ও তার পজিশন আস্তে আস্তে এভাবেই পরিবর্তন হবে তখন আর ইনডেক্স কে মার্কেট ম্যানুপুলেটর খারাপ পজিশনে ধরে রেখে আপনাদের বিভ্রান্ত্রিতে ফেলতে পারবে না , তখন ইনডেক্স ও আপনাকে সঠিক দৃষ্টি ভঙ্গি দেতে শুরু করবে ।  

এখন যারা এগিয়ে তাদের একটা সর্ট লিস্ট দেওয়া হল ঃ


 

Thursday, 14 November 2019

Exploration Filter AFL Amibroker


One Click Market Summaries
Exploration Filter AFL Amibroker Market Explorer



To get This Exploration Filter AFL
Mail: asfatul.alam@yahoo.com

Exploration Filter AFL Amibroker





One Click Market Summaries



To get This Exploration Filter AFL 
Mail: asfatul.alam@yahoo.com

Tuesday, 29 October 2019

Chart Looks Like - Afl Amibroker

Chart Looks Like  - AFL Amibroker


If you wants This AFL
Email: asfatul.alam@yahoo.com

Sunday, 27 October 2019

WayToWin Trading System


WayToWin Trading System



If you wants This Trading System
Email: asfatul.alam@yahoo.com
 

Compare fit for Amibroker (AFL)

 Least Squares Polynomial Fit test
 comparing a least squares fit using matrix calculations
 with one that does not

Button Style Trading Control’s in Amibroker

Button Style Trading Control’s in Amibroker 




If any one wants to get This AFL Email: asfatul.alam@yahoo.com

Saturday, 26 October 2019

Fisher transform indicator AFL Amibroker



Ehlers formulas from Ehlers, John F. Cybernetic Analysis for Stocks and Futures. Wiley. 2004. Chapter 1, p. 1. Code on p. 7.

Thursday, 24 October 2019

Controlled Trailing Stop-Loss AFL Amibroker

Controlled Trailing Stop-Loss (TSL): It is necessary to ensure that TSL always goes up for Long positions and goes down for Short positions or remains constant to the previous value. "Percentage or Points" based TSLs does not account market Volatility, so it is not dynamic. "Standard Deviation" based TSL or "ATR" based TSLs are ideal. For demo using ATR based TSL here:


Here is one way to deal with daily pivots AFL Amibroker


Here is one way to deal with daily pivots:


https://drive.google.com/file/d/1_KQNmw2_RwEuPKwATKbs1hA0Nc83zwG3/view?usp=sharing

Mean band for Amibroker (AFL)



You can buy a stock when candle stick is above the band and in similar way u can sell when the candle stick is below the band…it is really a helpful AFL….


Bollinger band with entry signals AFL for Amibroker



Trading system, Amibroker, Axploration, Bands


The formula use macd and stoch astick signals with the bollinger band and moving averages for entry and exit signals


All in one AFL for Amibroker



All in one has Patterns Wave, MACD, Candle Details, Guppy Movement, Support-Resistance, BB, Pivot indicator.

One can easily determine the trend.

https://drive.google.com/file/d/1HtAZaKWbP84k_nMXecHPxAmHR3rjwZjT/view?usp=sharing


Wednesday, 23 October 2019

NICK MA Swing + heikin pivots DoubleTop for Amibroker (AFL)



NICK MA Swing + heikin pivots







_SECTION_BEGIN("NICK MA Swing + heikin pivots");
SetBarsRequired(200,0);

GraphXSpace = 5;
SetChartOptions(0,chartShowArrows|chartShowDates);
k = Optimize("K",Param("K",1,0.25,5,0.25),0.25,5,0.25);
Per= Optimize("atr",Param("atr",4,3,20,1),3,20,1);
HACLOSE=(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), colorWhite, styleCandle | styleNoLabel );
j=Haclose;

f=ATR(14);

rfsctor = WMA(H-L, Per);

revers = k * rfsctor;

Trend = 1;
NW[0] = 0;


for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j[i] < NW[i-1])
{
Trend[i] = -1;
NW[i] = j[i] + Revers[i];
}
else
{
Trend[i] = 1;
if((j[i] - Revers[i]) > NW[i-1])
{
NW[i] = j[i] - Revers[i];
}
else
{
NW[i] = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j[i] > NW[i-1])
{
Trend[i] = 1;
NW[i] = j[i] - Revers[i];
}
else
{
Trend[i] = -1;
if((j[i] + Revers[i]) < NW[i-1])
{
NW[i] = j[i] + Revers[i];
}
else
{
NW[i] = NW[i-1];
}
}
}
}



_SECTION_BEGIN("ema5,13sound");
x = EMA(Close,5);
y = EMA(Close,13);
Plot(EMA(Close,5),"",colorBrightGreen,styleLine, styleThick);
Plot(EMA(Close,13),"",colorOrange,styleLine, styleThick);
XR=(EMA(Close,5) * (2 / 6 - 1) - EMA(Close,13) * (2 / 11 - 1)) / (2 / 6 - 2 / 11);


Buy=Cross(j,nw);
Cover=Cross(j,nw);
Sell=Cross(nw,j);
Short=Cross(nw,j);
SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );
_SECTION_END();
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "NICK MA Swing System" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorRed)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+
WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+
WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-30);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-40);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-35);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-30);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-40);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-35);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
AlertIf( Ref(Buy,-1), "SOUND C:\\Windows\\Media\\Windows XP Startup.wav", "Nick MA Buy", 2 );
AlertIf( Ref(Sell,-1), "SOUND C:\\Windows\\Media\\Ringin.wav", "Nick MA Sell", 2 );
_SECTION_END();

_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 8, 2, 200, 1 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") | styleNoRescale );
_SECTION_END();

_SECTION_BEGIN("Mid MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 34, 2, 300, 1 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") | styleNoRescale );
_SECTION_END();

_SECTION_BEGIN("Long MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 200, 2, 400, 1 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") | styleNoRescale );
_SECTION_END();
_SECTION_END();

_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
_SECTION_END();
_SECTION_BEGIN("Sup / Res Lines");
RSIperiod = 15; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 2; //Param("EMA p",4,5,10,1);
HHVperiod = 8; //Param("HHV p",3,5,10,1);
NumLine = 2; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);


for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorRed, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen, styleLine);

}_SECTION_END();


_SECTION_BEGIN("heikin");

// Calculate Moving Average
MAPeriod = Param("MA Period", 15, 1, 100);
MAOpen = EMA(Open, MAPeriod);
MAHigh = EMA(High, MAPeriod);
MALow = EMA(Low, MAPeriod);
MAClose = EMA(Close, MAPeriod);

HaClose = (MAOpen + MAHigh + MALow + MAClose) / 4;
HaOpen = AMA(Ref(HaClose, -1), 0.5);


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

HaClose[i] = Null;


HaHigh = Max(MAHigh, Max(HaClose, HaOpen));
HaLow = Min(MALow, Min(HaClose, HaOpen));


"BarIndex = " + BarIndex();
"Open = " + Open;
"High = " + High;
"Low = " + Low;
"Close = "+ Close;
"HaOpen = " + HaOpen;
"HaHigh = " + HaHigh;
"HaLow = " + HaLow;
"HaClose = "+ HaClose;


farback=Param("How Far back to go",100,50,5000,10);
nBars = Param("Number of bars", 12, 5, 40);



aHPivs = H - H;

aLPivs = L - L;


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;


aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);



aVisBars = Status("barvisible");

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

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


curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] <

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}



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

curBar = (BarCount - 1) - i;



if (curTrend == "U") {

curTrend = "D";



aLPivs[curPivBarIdx] = 1;



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

}



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++;

}

}



PlotShapes(

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

High, Offset=-15);

PlotShapes(

IIf(aLPivs==1, shapeUpArrow , shapeNone), colorBrightGreen, 0,

Low, Offset=-15);

AlertIf( Ref(aLPivs==1,-1), "SOUND C:\\Windows\\Media\\Windows XP Startup.wav", "Heikin Buy ", 2 );
AlertIf( Ref(aHPivs==1,-1), "SOUND C:\\Windows\\Media\\Ringin.wav", "Heikin Sell", 2 );

Buy=(aLPivs==1);
Cover=(aLPivs==1);
Sell=(aHPivs==1);
Short=(aHPivs==1);
SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );
_SECTION_END();
//=================TITLE================================================================================================
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorLightBlue)+ "Heikin-Ashi pivot + NMA Swing system - Boxed arrows NMA buy-sell - Normal Arrows Heikin Pivot Buy-Sell" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorRed)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+
WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+
WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));
AlertIf( Ref(Buy, -1), "SOUND C:\\Windows\\Media\\Windows XP Startup.wav", "ActionIndicator Buy", 2 );
AlertIf( Ref(Sell, -1), "SOUND C:\\Windows\\Media\\Ringin.wav", "Action Indicator Sell", 2 );
_SECTION_END();

_SECTION_BEGIN("Shiree_Hanging Man bullish +bearish with volume");

BT = BBandTop( C, 20, 2 );
BB = BBandBot( C, 20, 2 );
X=(BT-BB);

RBuy=EMA(C,3)<EMA(C,10) AND C<EMA(C,3) AND ((O+C)/2)>L+0.7*(H-L) AND abs(O-C)<0.4*(H-L) AND V>MA(V,10) AND (H-L)>=0.8*MA((H-L),10) AND X>1.2*MA(X,10);
Rsell=EMA(C,3)>EMA(C,10) AND C>EMA(C,3) AND ((O+C)/2)<H-0.7*(H-L) AND abs(O-C)<0.4*(H-L) AND V>MA(V,10) AND (H-L)>=0.8*MA((H-L),10) AND X>1.2*MA(X,10);


PlotShapes(Rsell*shapeDownTriangle,colorCustom12, 0, High, Offset =-40);
PlotShapes(Rsell*shapeDigit5,colorCustom12, 0, High, Offset =55);

PlotShapes(RBuy*shapeDigit5,colorYellow, 0, High, Offset =-70);
PlotShapes(RBuy*shapeUpTriangle,colorYellow, 0, Low, Offset =-10);


Filter =Rbuy OR Rsell;

AddColumn( IIf(RBuy,1,IIf(Rsell,-1,Null)) ,"RBS",1.0,colorWhite,IIf(RBuy,colorDarkGreen,IIf( Rsell,colorRed,Null)));

_SECTION_END();

_SECTION_BEGIN("Double top detection");

percdiff = 5;
fwdcheck = 5;
mindistance = 10;
validdiff = percdiff/400;
PK= Peak( H, percdiff, 1 ) == High;

x = Cum( 1 );
XPK1 = ValueWhen( PK, x, 1 );
XPK2 = ValueWhen( PK, x, 2 );

peakdiff = ValueWhen( PK, H, 1 )/ValueWhen( PK, H, 2 );
doubletop = PK AND abs( peakdiff - 1 ) < validdiff AND (XPK1 - XPK2)>mindistance
AND High > HHV( Ref( H, fwdcheck ), fwdcheck - 1 );
Buy = doubletop;
Sell = 0;

WriteIf( Highest( doubletop ) == 1, "AmiBroker has detected some possible double top patterns for " + Name() + "\nLook for green arrows on the price chart.", "There are no double top patterns for " + Name() );
_SECTION_END();

}

FOREX INTRADAY HEIKIN ASHI + PIVOT POINTS for Amibroker (AFL)

FOREX INTRADAY HEIKIN ASHI + PIVOT POINTS for Amibroker (AFL)



_SECTION_BEGIN("The_Beast_2");
SetBarsRequired(10000,10000); 

Prd1=Param("ATR Period 1-20",4,1,20,1);
Prd2=Param("LookBack Period 1-20",7,1,20,1);
Green=HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);      

RED=LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);

HaClose =EMA((O+H+L+C)/4,3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
Color = IIf(C>Green ,colorBrightGreen,IIf(C < RED,colorRed,colorBlue));

PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", color, styleCandle,styleThick );


Odd=13;
CoefOdd=round(Odd/2);

Even=12;
Coefeven=Even/2;
Coefeven2=Coefeven+1;

CongestionPercent=2.8;

TriangularOdd=MA(MA(C,CoefOdd),CoefOdd);
TriangularEven=MA(MA(C,Coefeven),Coefeven2);

finalMov_avg=IIf(Odd > even,triangularOdd,TriangularEven);

Color=colorBrightGreen;
tickercolor=colorBlack;

Plot(finalMov_avg,"",IIf(C < finalmov_avg,colorRed,Color),styleLine|styleThick);


LB= Param("Look Back Periods",10,1,30,1);
R=ValueWhen(Cross(MA(C,LB),C),HHV(H,LB),1);
S=ValueWhen(Cross(C,MA(C,LB)),LLV(L,LB),1);


UpClose = Close - Ref(Close,-1);
Color = IIf(UpClose > 0, colorBrightGreen, colorRed);


Plot (R,"Resz",ParamColor("R Color",colorRed),8+16);
Plot (S,"Supp",ParamColor("S Color",colorGreen),8+16);


GraphXSpace=4;


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} -                       "+ EncodeColor(colorYellow)+"Open = "+ EncodeColor(colorYellow) +"%g    "+ EncodeColor(colorBrightGreen)+"High = "+ EncodeColor(colorBrightGreen) +"%g - "+ EncodeColor(colorRed)+"Low = "+ EncodeColor(colorRed) +"%g    "+ EncodeColor(colorYellow) +"Close = "+ EncodeColor(colorYellow) +" %g                                                                                                                                                                                                                                                                                                                                         (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));







DayH = TimeFrameGetPrice("H", inDaily, -1);     DayHI = LastValue (DayH,1);// yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1);     DayLI = LastValue (DayL,1);    // yesterdays low
DayC = TimeFrameGetPrice("C", inDaily, -1);         // yesterdays close
DayO = TimeFrameGetPrice("O", inDaily);            // current day open
DayH2= TimeFrameGetPrice("H", inDaily, -2);  DayH2I = LastValue (DayH2,1); // Two days before high
DayL2= TimeFrameGetPrice("L", inDaily, -2);  DayL2I = LastValue (DayL2,1);  // Two days before low
DayH3= TimeFrameGetPrice("H", inDaily, -3);  DayH3I = LastValue (DayH3,1);  // Three days before high
DayL3= TimeFrameGetPrice("L", inDaily, -3);  DayL3I = LastValue (DayL3,1);  // Three days before low

numbars = LastValue(Cum(Status("barvisible")));
hts  = -33.5;

YHL = ParamToggle("Yesterday HI LO","Show|Hide",1);
if(YHL==1) {
  Plot(DayL,"YL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(DayH,"YH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  PlotText(" YH " ,     LastValue(BarIndex())-(numbars/Hts), DayHI, colorTurquoise);
  PlotText(" YL " ,     LastValue(BarIndex())-(numbars/Hts), DayLI, colorTurquoise);
}

TDBHL = ParamToggle("2/3Days before HI LO","Show|Hide",0);
if(TDBHL==1) {
  Plot(DayL2,"2DBL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(DayH2,"2DBH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(DayL3,"3DBL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(DayH3,"3DBH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  PlotText(" 2DBH " ,     LastValue(BarIndex())-(numbars/Hts), DayH2I, colorTurquoise);
  PlotText(" 2DBL " ,     LastValue(BarIndex())-(numbars/Hts), DayL2I, colorTurquoise);
  PlotText(" 3DBH " ,     LastValue(BarIndex())-(numbars/Hts), DayH3I, colorTurquoise);
  PlotText(" 3DBL " ,     LastValue(BarIndex())-(numbars/Hts), DayL3I, colorTurquoise);
}

// Pivot Levels //
PP = (DayL + DayH + DayC)/3;  PPI = LastValue (PP,1);   // Pivot
R1  =  (PP * 2) - DayL;       R1I = LastValue (R1,1);   // Resistance 1
S1  =  (PP * 2)  - DayH;      S1I = LastValue (S1,1);   // Support 1
R2  =  PP + R1 - S1;          R2I = LastValue (R2,1);   // Resistance 2
S2  =  PP - R1 + S1;          S2I = LastValue (S2,1);   // Support 2
R3  =  PP + R2 - S1;          R3I = LastValue (R3,1);   // Resistance 3
S3  =  PP - R2 + S1;          S3I = LastValue (S3,1);   // Support 3

ppl = ParamToggle("Pivot Levels","Show|Hide",1);
if(ppl==1)  {
  Plot(PP, "PP",colorYellow,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(R1, "R1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(S1, "S1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(R2, "R2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(S2, "S2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(R3, "R3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
  Plot(S3, "S3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

  PlotText(" Pivot ",  LastValue(BarIndex())-(numbars/Hts), PPI, colorYellow);
  PlotText(" R1 " ,    LastValue(BarIndex())-(numbars/Hts), R1I, colorViolet);
  PlotText(" S1 " ,    LastValue(BarIndex())-(numbars/Hts), S1I, colorViolet);
  PlotText(" R2 " ,    LastValue(BarIndex())-(numbars/Hts), R2I, colorViolet);
  PlotText(" S2 " ,    LastValue(BarIndex())-(numbars/Hts), S2I, colorViolet);
  PlotText(" R3 " ,    LastValue(BarIndex())-(numbars/Hts), R3I, colorViolet);
  PlotText(" S3 " ,    LastValue(BarIndex())-(numbars/Hts), S3I, colorViolet);
}
// Camerilla Levels //

rg = (DayH - DayL);

H5=DayC+1.1*rg;     H5I = LastValue (H5,1);
H4=DayC+1.1*rg/2;   H4I = LastValue (H4,1);
H3=DayC+1.1*rg/4;   H3I = LastValue (H3,1);
H2=DayC+1.1*rg/6;   H2I = LastValue (H2,1);
H1=DayC+1.1*rg/12;  H1I = LastValue (H1,1);
L1=DayC-1.1*rg/12;  L1I = LastValue (L1,1);
L2=DayC-1.1*rg/6;   L2I = LastValue (L2,1);
L3=DayC-1.1*rg/4;   L3I = LastValue (L3,1);
L4=DayC-1.1*rg/2;   L4I = LastValue (L4,1);
L5=DayC-1.1*rg;     L5I = LastValue (L5,1);

pcl = ParamToggle("Camerilla Levels","Show|Hide",0);
if(pcl==1)  {
   Plot(H5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(H4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(H3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(H2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(H1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(L1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(L2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(L3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(L4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   Plot(L5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
   PlotText(" H5 = " ,     LastValue(BarIndex())-(numbars/Hts), H5I  +0.05, colorRose);
   PlotText(" H4 = " ,     LastValue(BarIndex())-(numbars/Hts), H4I  +0.05, colorRose);
   PlotText(" H3 = " ,     LastValue(BarIndex())-(numbars/Hts), H3I  +0.05, colorRose);
   PlotText(" H2 = " ,     LastValue(BarIndex())-(numbars/Hts), H2I  +0.05, colorRose);
   PlotText(" H1 = " ,     LastValue(BarIndex())-(numbars/Hts), H1I  +0.05, colorRose);
   PlotText(" L1 = " ,     LastValue(BarIndex())-(numbars/Hts), L1I  +0.05, colorRose);
   PlotText(" L2 = " ,     LastValue(BarIndex())-(numbars/Hts), L2I  +0.05, colorRose);
   PlotText(" L3 = " ,     LastValue(BarIndex())-(numbars/Hts), L3I  +0.05, colorRose);
   PlotText(" L4 = " ,     LastValue(BarIndex())-(numbars/Hts), L4I  +0.05, colorRose);
   PlotText(" L5 = " ,     LastValue(BarIndex())-(numbars/Hts), L5I  +0.05, colorRose);
}

THL = ParamToggle("Todays Hi Lo","Show|Hide",1);
if(THL==1)  {
  isRth = TimeNum() >= 084500 & TimeNum() <= 085959;
  isdRth = TimeNum() >= 084500 & TimeNum() <= 160000;
  aRthL = IIf(isRth, L, 1000000);
  aRthH = IIf(isdRth, H, Null);
  aRthLd = IIf(isdRth, L, 1000000);
  DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
  DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
  DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
  DayL = TimeFrameExpand( DayL, inDaily, expandFirst );
  Bars = BarsSince(TimeNum() >= 94500 AND TimeNum() < 095959);
  x0 = BarCount-LastValue(Bars);
  x1 = BarCount-1;
  DayHline=LineArray(x0,LastValue(DayH),x1,LastValue (DayH),0);
  DayLline=LineArray(x0,LastValue(DayL),x1,LastValue (DayL),0);
  DayHlineI = LastValue (DayHline,1);
  DayLlineI = LastValue (DayLline,1);
  Plot(DayHline,"DayH",colorYellow,styleBar|styleNoRescale|styleNoTitle);
  Plot(DayLline,"DayL",colorYellow,styleBar|styleNoRescale|styleNoTitle);
  PlotText(" Day Hi " ,     LastValue(BarIndex())-(numbars/Hts), DayHlineI  +0.05, colorYellow);
  PlotText(" Day Lo " ,     LastValue(BarIndex())-(numbars/Hts), DayLlineI  +0.05, colorYellow);
 }


_SECTION_BEGIN("Pivot_Finder");


farback=Param("How Far back to go",200,0,5000,10);
nBars = Param("Number of bars", 12, 5, 40);


aHPivs = H - H;

aLPivs = L - L;


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;


aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);



aVisBars = Status("barvisible");

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

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



curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] <

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}



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

curBar = (BarCount - 1) - i;



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



if (curTrend == "U") {

curTrend = "D";



curPivBarIdx = curBar - aLLVBars[curBar];

aLPivs[curPivBarIdx] = 1;

aLPivLows[nLPivs] = L[curPivBarIdx];

aLPivIdxs[nLPivs] = curPivBarIdx;

nLPivs++;

}



} else {

if (curTrend == "D") {

curTrend = "U";

curPivBarIdx = curBar - aHHVBars[curBar];

aHPivs[curPivBarIdx] = 1;

aHPivHighs[nHPivs] = H[curPivBarIdx];

aHPivIdxs[nHPivs] = curPivBarIdx;

nHPivs++;

}



}



}



curBar = (BarCount-1);

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if (lastLPIdx > lastHPIdx) {



candIdx = curBar - aHHVBars[curBar];

candPrc = aHHV[curBar];

if (

lastHPH < candPrc AND

candIdx > lastLPIdx AND

candIdx < curBar) {




aHPivs[candIdx] = 1;



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 {




candIdx = curBar - aLLVBars[curBar];

candPrc = aLLV[curBar];

if (

lastLPL > candPrc AND

candIdx > lastHPIdx AND

candIdx < curBar) {




aLPivs[candIdx] = 1;



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++;

}

}

 



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]);

}



PlotShapes(

IIf(aHPivs==1, shapeStar, shapeNone), colorBrightGreen, 0, H, 25);

PlotShapes(

IIf(aLPivs==1, shapeStar , shapeNone), colorRed, 0, L, -20);


farback=Param("How Far back to go",200,12,30,1);
nBars = Param("Number of bars", 12, 1, 30, 1);

aHPivs = H - H;
aLPivs = L - L;

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;

aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);

aVisBars = Status("barvisible");
nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
_TRACE("Last visible bar: " + nLastVisBar);

curBar = (BarCount-1);
curTrend = "";
if (aLLVBars[curBar] <
aHHVBars[curBar]) {
curTrend = "D";
}
else {
curTrend = "U";
}

for (i=0; i<farback; i++) {
curBar = (BarCount - 1) - i;

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

if (curTrend == "U") {
curTrend = "D";

curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}

} else {
if (curTrend == "D") {
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}

}

}

curBar = (BarCount-1);
candIdx = 0;
candPrc = 0;
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
if (lastLPIdx > lastHPIdx) {

candIdx = curBar - aHHVBars[curBar];
candPrc = aHHV[curBar];
if (
lastHPH < candPrc AND
candIdx > lastLPIdx AND
candIdx < curBar) {

aHPivs[candIdx] = 1;

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 {

candIdx = curBar - aLLVBars[curBar];
candPrc = aLLV[curBar];
if (
lastLPL > candPrc AND
candIdx > lastHPIdx AND
candIdx < curBar) {

aLPivs[candIdx] = 1;

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++;
}
}

PlotShapes(IIf(aHPivs==1, shapeSmallDownTriangle, shapeNone), colorCustom12, 0, High, Offset=-5);
PlotShapes(IIf(aLPivs==1, shapeSmallUpTriangle , shapeNone), colorCustom11, 0, Low, Offset=-5);

Sell = aHPivs == 1 ;
Buy = aLPivs == 1 ;
Filter=Buy OR Sell;
Sell=ExRem(Sell,Buy);
Buy=ExRem(Buy,Sell);



R=3;
m=0.015*(HHV(H,159)-LLV(L,159));
x=Cum(1);
per = 2.5;
pR = PeakBars( H, per, 1 ) == 0;
x01= LastValue(ValueWhen( pR, x, 1 ));
x02=LastValue(ValueWhen( pR, x, 2 ));
x03=LastValue(ValueWhen( pR, x, 3 ));
y01 = LastValue(ValueWhen( pR, H, 1 ) );
y02=LastValue(ValueWhen( pR, H, 2 ) );
y03 = LastValue( ValueWhen( pR, H, 3 ));

y0=y01;x0=x01;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y02;x0=x02;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y03;x0=x03;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
TpR = TroughBars( L, per, 1 ) == 0;//Trough condition
x01T= LastValue(ValueWhen( TpR, x, 1 ));
x02T=LastValue(ValueWhen( TpR, x, 2 ));
x03T=LastValue(ValueWhen( TpR, x, 3 ));
y01T = LastValue(ValueWhen( TpR, L, 1 ) );
y02T=LastValue(ValueWhen( TpR, L, 2 ) );
y03T = LastValue( ValueWhen( TpR, L, 3 ));
y0T=y01T;x0T=x01T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(Y,"",5,1);Plot(Y1,"",5,1);
y0T=y02T;x0T=x02T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);
y0T=y03T;x0T=x03T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);

R=2;//Marking circle radius
m=0.015*(HHV(H,159)-LLV(L,159));//scaling factor
x=Cum(1);
per = 1.5;//Sensitivity Calibration
pR = PeakBars( H, per, 1 ) == 0;//Peak condition
x01= LastValue(ValueWhen( pR, x, 1 ));
x02=LastValue(ValueWhen( pR, x, 2 ));
x03=LastValue(ValueWhen( pR, x, 3 ));
y01 = LastValue(ValueWhen( pR, H, 1 ) );
y02=LastValue(ValueWhen( pR, H, 2 ) );
y03 = LastValue( ValueWhen( pR, H, 3 ));

y0=y01;x0=x01;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y02;x0=x02;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y03;x0=x03;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
TpR = TroughBars( L, per, 1 ) == 0;//Trough condition
x01T= LastValue(ValueWhen( TpR, x, 1 ));
x02T=LastValue(ValueWhen( TpR, x, 2 ));
x03T=LastValue(ValueWhen( TpR, x, 3 ));
y01T = LastValue(ValueWhen( TpR, L, 1 ) );
y02T=LastValue(ValueWhen( TpR, L, 2 ) );
y03T = LastValue( ValueWhen( TpR, L, 3 ));
y0T=y01T;x0T=x01T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(Y,"",5,1);Plot(Y1,"",5,1);
y0T=y02T;x0T=x02T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);
y0T=y03T;x0T=x03T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);


R=1;
m=0.015*(HHV(H,159)-LLV(L,159));//scaling factor
x=Cum(1);
per = 0.325;//Sensitivity Calibration
pR = PeakBars( H, per, 1 ) == 0;//Peak condition
x01= LastValue(ValueWhen( pR, x, 1 ));
x02=LastValue(ValueWhen( pR, x, 2 ));
x03=LastValue(ValueWhen( pR, x, 3 ));
y01 = LastValue(ValueWhen( pR, H, 1 ) );
y02=LastValue(ValueWhen( pR, H, 2 ) );
y03 = LastValue( ValueWhen( pR, H, 3 ));

y0=y01;x0=x01;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y02;x0=x02;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
y0=y03;x0=x03;
y=y0+m*sqrt(R^2-(x-x0)^2);
y1=y0-m*sqrt(R^2-(x-x0)^2);
Plot(y,"",4,1);Plot(y1,"",4,1);
TpR = TroughBars( L, per, 1 ) == 0;//Trough condition
x01T= LastValue(ValueWhen( TpR, x, 1 ));
x02T=LastValue(ValueWhen( TpR, x, 2 ));
x03T=LastValue(ValueWhen( TpR, x, 3 ));
y01T = LastValue(ValueWhen( TpR, L, 1 ) );
y02T=LastValue(ValueWhen( TpR, L, 2 ) );
y03T = LastValue( ValueWhen( TpR, L, 3 ));
y0T=y01T;x0T=x01T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(Y,"",5,1);Plot(Y1,"",5,1);
y0T=y02T;x0T=x02T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);
y0T=y03T;x0T=x03T;
y=y0T+m*sqrt(R^2-(x-x0T)^2);
y1=y0T-m*sqrt(R^2-(x-x0T)^2);
Plot(y,"",5,1);Plot(y1,"",5,1);

EMA34 = EMA(C,34);
LSMA = LinearReg(C,23);


_SECTION_BEGIN("Price");

SetChartOptions(0,chartShowArrows|chartShowDates);

_N(Title = EncodeColor(colorCustom12) +StrFormat(" {{NAME}} - {{INTERVAL}}     {{DATE}} "+ EncodeColor(colorWhite) +"                       Open  = "+ EncodeColor(colorWhite) +"%g  "+ EncodeColor(colorBrightGreen) +"    High : "+ EncodeColor(colorBrightGreen) +" %g "+ EncodeColor(colorRed) +"  -   Low : "+ EncodeColor(colorRed) +" %g "+ EncodeColor(colorWhite) +"     Close  = "+ EncodeColor(colorWhite) +"%g                                                                                                                                                                                                                                                                              
{{VALUES}}",O,H,L,C ));

_SECTION_END();


_SECTION_BEGIN("Break Outs");
//{Buy}
x1=5; x2=4; x3=3; x4=2; x5=1; x6=.5;
//{Lowest price stock <5}
AA=IIf(C<5,Cross(C,ValueWhen(Peak(H,x1,1) !=Ref(Peak(H,x1,1),-1),H,1)),
//{Price between 5 AND 20}
IIf(C>5 AND C<20,Cross(C,ValueWhen(Peak(H,x2,1) !=Ref(Peak(H,x2,1),-1),H,1)),
//{Price between 20 AND 70}
IIf(C>20 AND C<70,Cross(C,ValueWhen(Peak(H,x3,1) !=Ref(Peak(H,x3,1),-1),H,1)),
//{Price between 70 AND 150}
IIf(C>70 AND C<150,Cross(C,ValueWhen(Peak(H,x4,1) !=Ref(Peak(H,x4,1),-1),H,1)),
//{Price between 150 AND 300}
IIf(C>150 AND C<300,Cross(C,ValueWhen(Peak(H,x5,1) !=Ref(Peak(H,x5,1),-1),H,1)),
//{Price over 300}
Cross(C,ValueWhen(Peak(H,x6,1)!=Ref(Peak(H,x6,1),-1),H,1)))))));

//{Sell }
x1=5; x2=4; x3=3; x4=2; x5=1; x6=.5;
//{Lowest price stock <5}
BB=IIf(C<5,Cross(ValueWhen(Trough(L,x1,1) !=Ref(Trough(L,x1,1),-1),L,1),C),
//{Price between 5 AND 20}
IIf(C>5 AND C<20,Cross(ValueWhen(Trough(L,x2,1) !=Ref(Trough(L,x2,1),-1),L,1),C),
//{Price between 20 AND 70}
IIf(C>20 AND C<70,Cross(ValueWhen(Trough(L,x3,1) !=Ref(Trough(L,x3,1),-1),L,1),C),
//{Price between 70 AND 150}
IIf(C>70 AND C<150,Cross(ValueWhen(Trough(L,x4,1) !=Ref(Trough(L,x4,1),-1),L,1),C),
//{Price between 150 AND 300}
IIf(C>150 AND C<300,Cross(ValueWhen(Trough(L,x5,1) !=Ref(Trough(L,x5,1),-1),L,1),C),
//{Price over 300}
Cross(ValueWhen(Trough(L,x6,1)!=Ref(Trough(L,x6,1),-1),L,1),C))))));

Color=IIf(BarsSince(AA)>BarsSince(BB),colorRed,IIf(RSI()>70,colorCustom11,colorDarkGreen));



P6=Param("Trailing Stop Risk",2.5,2,3.5,0.1);
P7=Param("Trailing Stop LookBack",2,5,25,1);
P8=Param("Trailing Stop PrevLow Switch",0,0,1,1);
PrevLow=IIf(P8==1, Ref(C,-TroughBars(C,3,1)) ,Null);

MyTotalPort = Param("MyTotalPort",1000000,10000,10000000,100000);
AcceptableRisk = Param("AcceptableRisk",0.5,0.1,3,0.1);
BarsFromStart = BarsSince(Cross(AA,BB)AND Ref(Color,-1)==colorRed) ;
InitialStopLoss =Ref( H - P6*ATR(P7),-BarsFromStart);
PositionSizing = 0.01*AcceptableRisk*MyTotalPort/( C - InitialStopLoss );

PPP = IIf( HHV(H - P6*ATR(P7),BarsFromStart+1) <C ,HHV(H - P6*ATR(P7),BarsFromStart+1),Null);
Plot( PPP ,"",colorCustom12);



_SECTION_BEGIN("Magnified Market Price");

FS=Param("Font Size",30,30,100,1);
GfxSelectFont("Arial", FS, 900, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorYellow) );
Hor=Param("Horizontal Position",1350,1350,1350,1350);
Ver=Param("Vertical Position",12,14,16,18);
GfxTextOut(""+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );
_SECTION_END();



_SECTION_BEGIN("Ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();
Plot( 1, "ribbon",
IIf( uptrend, colorLime, IIf( downtrend, colorRed,IIf(Signal()<MACD(), colorBlack, colorBlack ))), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -01, 50 );
_SECTION_END();



GraphXSpace=10;