shree chkra afl

#1
_SECTION_BEGIN("1 IDENTIFIER");
//Plot(Close, "Close", colorWhite, styleCandle);

Change = 3.0;





GannIncrement = 0.0625;
procedure PlotShapeAt( x, y, shape, shift )
{
PlotShapes( IIf( BarIndex() == x, shape, 0 ), colorRed, 0, y, shift );
}
procedure PlotBlueDot( x, y )
{
//PlotShapes( IIf( BarIndex() == x, shapeSmallCircle, 0 ),
//colorBlue, 0, y, 0 );

for( i = -2; i <= 2; i++ )
{
if( i != 0 )
{
yGann = ( sqrt( y ) + i * GannIncrement ) ^ 2;
// PlotShapes( IIf( BarIndex() == x, shapeSmallCircle, 0 ),
// colorOrange, 0, yGann, 0 );
}
}
}
bi = BarIndex();
sbi = SelectedValue( bi );
GraphXSpace = 2;
//Plot( Zig( C, Change ), "Zigzag", colorGreen, styleThick );
//Plot( C, "Price", IIf( bi > sbi, colorLightGrey, colorWhite ), styleBar );
upshift = 15;
if( SelectedValue( PeakBars( C, Change ) < TroughBars( C, Change ) ) )
{
pt1 = PeakBars( C, Change, 1 ) == 0 ;
pt2 = TroughBars( C, Change, 1 ) == 0 ;
}
else
{
pt1 = TroughBars( C, Change, 1 ) == 0 ;
pt2 = PeakBars( C, Change, 1 ) == 0 ;
upshift = -upshift;
}
bpt1 = SelectedValue( ValueWhen( pt1, bi ) );
bpt2 = SelectedValue( ValueWhen( pt2, bi ) );
bpt3 = SelectedValue( ValueWhen( pt1, bi, 2 ) );
bpt4 = SelectedValue( ValueWhen( pt2, bi, 2 ) );
bpt5 = SelectedValue( ValueWhen( pt1, bi, 3 ) );
bpt6 = SelectedValue( ValueWhen( pt2, bi, 3 ) );
//PlotShapeAt( bpt1, C, shapeDigit1, upshift );
//PlotShapeAt( bpt2, C, shapeDigit2, -upshift );
//PlotShapeAt( bpt3, C, shapeDigit3, upshift );
//PlotShapeAt( bpt4, C, shapeDigit4, -upshift );
//PlotShapeAt( bpt5, C, shapeDigit5, upshift );
//PlotShapeAt( bpt6, C, shapeDigit6, -upshift );
Level = SelectedValue( ValueWhen( pt1, C ) );
PlotBlueDot( round( bpt1 + 1.618 * ( bpt1 - bpt2 ) ), Level );
PlotBlueDot( round( bpt1 + 0.382 * ( bpt1 - bpt2 ) ), Level );
PlotBlueDot( round( bpt1 + 0.5 * ( bpt2 - bpt3 ) ), Level );
PlotBlueDot( round( bpt1 + 1.732 * ( bpt2 - bpt3 ) ), Level );
PlotBlueDot( round( bpt1 + 0.618 * ( bpt4 - bpt5 ) ), Level );
PlotBlueDot( round( bpt1 + 2 * ( bpt4 - bpt5 ) ), Level );
PlotBlueDot( round( bpt2 + 0.6707 * ( bpt4 - bpt2 ) ), Level );
PlotBlueDot( round( bpt2 + 2.618 * ( bpt4 - bpt2 ) ), Level );
PlotBlueDot( round( bpt2 + 1 * ( bpt6 - bpt2 ) ), Level );
PlotBlueDot( round( bpt2 + 3 * ( bpt6 - bpt2 ) ), Level );


TROUGHCover=bpt1=TroughBars(C,Change,1)==0;
PEAKShort=bpt1=PeakBars(C,Change,1)==0;






//ShortPrice=ValueWhen(Short,H,1);
//CoverPrice=ValueWhen(Cover,L,1);


MAPeriod = Param("MA Period", 6, 1, 50);
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.44);
// for graph collapse
//for (i = 0; i <= MAPeriod; i++)
// HaClose = Null;
/*
// same
// HaOpen = (Ref(HaOpen, -1) + Ref(HaClose, -1)) / 2;
HaOpen[ 0 ] = HaClose[ 0 ];
for(i = 1; i < BarCount; i++) {
HaOpen = (HaOpen[i - 1] + HaClose[i - 1]) / 2;

*/
HaHigh = Max(MAHigh, Max(HaClose, HaOpen));
HaLow = Min(MALow, Min(HaClose, HaOpen));
// outs comments
"BarIndex = " + BarIndex();
"Open = " + Open;
"High = " + High;
"Low = " + Low;
"Close = " + Close;
"HaOpen = " + HaOpen;
"HaHigh = " + HaHigh;
"HaLow = " + HaLow;
"HaClose = " + HaClose;
// Plot graphs
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} HaOpen %g, HaHigh %g, HaLow %g, HaClose %g (%.1f%%) {{VALUES}}", HaOpen, HaHigh, HaLow, HaClose, SelectedValue(ROC(HaClose, 1))));



// you can switch between Heikin-Ashi chart and regular candlestick chart

//tambahan Ku
//Hacol = IIf(Cover, colorGreen, colorRed);
//Hacol = IIf(Short, colorRed, colorGreen);

//SetBarFillColor(Hacol);

if( ParamToggle("Plot Heikin-Ashi", "No,Yes", 1 ) )
PlotOHLC( HaOpen, HaHigh, HaLow, Close, " " + Name(), IIf(C>TROUGHCover, colorBlue, colorRed), styleCandle); //colorBlue, styleCandle );
//else
//Plot( C, "Regular candles " + Name(), IIf(Cover, colorBlue, colorRed), styleCandle );
//Plot( C, "Regular Candles", IIf(Cover, colorBrightGreen, IIf(Short,colorRed, ParamStyle("Price Style",styleCandle))));


EnableTextOutput(False);
SetChartOptions(0,chartShowArrows|chartShowDates);
Title_X = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
//Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorDarkGrey), ParamColor("Title", colorTeal));
SetChartBkColor(ParamColor("Background", colorBlack));



//Indicators Used

RSI_Periods = Param("RSI Periods", 2, 10, 10, 1);
MA_Periods = Param("Periods for MAV", 50, 1, 200, 1);
Daily_Trend_MA_Pds = Param("Periods for Trend EMA", 6, 1, 100, 1);
Weekly_Trend_MA_Pds = Param("periods for Trend EMA",6,1,100,1);
Monthly_Trend_MA_Pds = Param("periods for Trend EMA",6,1,100,1);


SetBarsRequired(100000, 100000);

// Find nearest UP and DOWN bar before current bar
Up_Day = Close > Open;
Down_Day = Close < Open;
Reference_Low = ValueWhen(Up_Day, L, 1);
Reference_High = ValueWhen(Down_Day, H, 1);
Buy_Condition = C > O AND C > Reference_High;
Sell_Condition = C < O AND C < Reference_Low;
a= Buy_Condition;
b= Sell_Condition;
state=IIf(BarsSince(a)<BarsSince(b),1,0);
s=state>Ref(state,-1);
ss=state<Ref(state,-1);
sss=state==Ref(state,-1);
col=IIf(state == 1 ,51,IIf(state ==0,4,1));
Buy_Views = WriteIf(s,"EXIT ALL SHORT POSITIONS\n AND TRADE LONG WITH STOPLOSS="+EncodeColor(colorBrightGreen)+WriteVal(L,1.2)+",","");
Sell_Views = WriteIf(ss,"EXIT ALL LONG POSITIONS \n AND TRADE SHORT WITH STOPLOSS="+EncodeColor(colorRed)+WriteVal(H,1.2)+",","");



// RSI and Vol ratio calculation
RSI_Value = RSI(RSI_Periods);
MAV_Value = V/EMA(V, MA_Periods);

// New Formula for stock movement

//Percentage change

sDIFF=C-Ref(C,-1);
t=(sDIFF/Ref(C,-1))*100;
Percentage= t;

//Percentage Change in Volume

w = V -Ref(V,-1);
x = (w/Ref(V,-1))*100;
Volume_Ratio = x;
//Volume_Ratio = V/EMA(V,50);
//Conditions

Condition1 = Percentage > 0.5 AND Volume_Ratio > 1.5;
Condition2 = Percentage > 1 AND Volume_Ratio < -1.5;
Condition3 = Percentage < 0 AND Volume_Ratio > -1.5;
Condition4 = Percentage < 1 AND Volume_Ratio < 1.5;
Condition5 = IIf(NOT Condition1 AND NOT Condition2 AND NOT Condition3 AND NOT Condition4, True,False);


Fresh_Buying = WriteIf(Condition1,"Fresh Buying", "");
Short_Covering = WriteIf(Condition2,"Short Covering", "");
Fresh_Short_Building = WriteIf(Condition3,"Fresh Short Building", "");
Possible_Bottom = WriteIf(Condition4,"Possible Bottom OR Top", "");
No_Major_Move = WriteIf(Condition5, "No_Major_Move","");


EnableTextOutput(True);
"\nSell Below: " + WriteVal(ValueWhen(Up_Day, L, 1), 1.2);
"Buy Above : " + WriteVal(Reference_High, 1.2);
"";
"Current RSI Value: " + WriteVal(RSI_Value, 1.2);
"Current Vol. Ratio: " + WriteVal(MAV_Value, 1.2);

EnableTextOutput(False);

Filter = Buy_Condition OR Sell_Condition;


// Trading System
PositionSize = BuyPrice * 1;
logixBuy = Buy_condition;
logixSell = Sell_condition;
//Short = Sell_condition;
//Cover = Buy_condition;

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


// Experimental Code BEGIN
Is_Last_Bar = BarIndex()+1 == BarCount;
printf("Last Bar: %g\n", Is_Last_Bar);
Buy_Alert = logixBuy AND Is_Last_Bar;
Sell_Alert = logixSell AND Is_Last_Bar;
Buy_Alert_Text = WriteIf(Buy_Alert, "BUY WARNING!!!", "");
Sell_Alert_Text = WriteIf(Sell_Alert, "SELL WARNING!!!", "");
Buy_Alert_Text1 = WriteIf(Buy_Alert, "BUY", "");
Sell_Alert_Text1 = WriteIf(Sell_Alert, "SELL", "");
LastbarsignalCol = IIf(Buy_Alert, colorGreen, IIf(Sell_Alert, colorRed, colorLightGrey));


//Buy & Sell Arrows Signal

//PlotShapes(shapeUpArrow * Buy * (NOT Is_Last_Bar), colorBrightGreen, 0, L, -15);
//PlotShapes(shapeHollowUpArrow * Cover, colorBrightGreen, 0, L, -30);
//PlotShapes(shapeDownArrow * Sell * (NOT Is_Last_Bar), colorRed, 0, H, -15);
//PlotShapes(shapeHollowDownArrow * Short, colorRed, 0, H, -30);
PlotShapes(shapeCircle * Buy_Alert, colorCustom11, 0, L, 5);
PlotShapes(shapeCircle * Sell_Alert, colorOrange, 0, H, 15);




// Check if previous day's close is above its 6-day EMA
DailyClose = TimeFrameCompress(Close, inDaily);
DailyEMA = EMA( DailyClose, Daily_Trend_MA_Pds);
DailyClose = TimeFrameExpand(DailyClose, inDaily, expandFirst);
DailyEma = TimeFrameExpand(DailyEMA, inDaily, expandFirst);

// Trend detection based on 6EMA for Daily
Daily_Trend_UP = DailyClose > DailyEMA;
Daily_Trend_DOWN = DailyClose < DailyEMA;
Trend_UP_Text = WriteIf(Daily_Trend_UP, "Daily Trend UP", "");
Trend_DOWN_Text = WriteIf(Daily_Trend_DOWN, "Daily Trend DOWN", "");
Trend_Neutral_Text = WriteIf(NOT Daily_Trend_DOWN AND NOT Daily_Trend_UP, "Neutral", "");
TrendCol = IIf(Daily_Trend_UP, colorGreen, IIf(Daily_Trend_DOWN, colorRed, colorLightGrey));

// Check if previous Week's Close is above its 6-Weeks EMA
WeeklyClose = TimeFrameCompress(Close, inWeekly);
weeklyEMA = EMA( weeklyClose, Weekly_Trend_MA_Pds);
weeklyClose = TimeFrameExpand(WeeklyClose, inWeekly, expandFirst);
WeeklyEMA = TimeFrameExpand(weeklyEMA, inWeekly, expandFirst);


// Trend detection based on 6EMA for weekly
Weekly_Trend_UP = WeeklyClose > WeeklyEMA;
Weekly_Trend_DOWN = WeeklyClose < WeeklyEMA;
Weekly_Trend_UP_Text = WriteIf(Weekly_Trend_UP, "Weekly Trend UP", "");
Weekly_Trend_DOWN_Text = WriteIf(Weekly_Trend_DOWN, "Weekly Trend DOWN", "");
Wekly_Trend_Neutral_Text = WriteIf(NOT Weekly_Trend_DOWN AND NOT Weekly_Trend_UP, "Neutral", "");
TrendCol = IIf(Weekly_Trend_UP, colorGreen, IIf(Weekly_Trend_DOWN, colorRed, colorLightGrey));

// Check if previous Month's Close is above its 6-Months EMA
MonthlyClose = TimeFrameCompress(Close, inMonthly);
MonthlyEMA = EMA( MonthlyClose, Monthly_Trend_MA_Pds);
MonthlyClose = TimeFrameExpand(MonthlyClose, inMonthly, expandFirst);
MonthlyEMA = TimeFrameExpand(MonthlyEMA, inMonthly, expandFirst);

/** Debug BEGIN */
printf("\nDaily Close: %g ", DailyClose);
printf("\nDaily Trend: %g", (DailyEMA));
printf("\nWeekly Trend: %g", (WeeklyEMA));
printf("\nMonthly Trend: %g", (MonthlyEMA));
/* Debug END ****/

// Trend detection based on 6EMA for Monthly
Monthly_Trend_Up = MonthlyClose > MonthlyEMA;
Monthly_Trend_DOWN = MonthlyClose < MonthlyEMA;
Monthly_Trend_UP_Text = WriteIf(Monthly_Trend_UP, "Monthly Trend UP", "");
Monthly_Trend_DOWN_Text = WriteIf(Monthly_Trend_DOWN, "Monthly Trend DOWN", "");
Monthly_Trend_Neutral_Text = WriteIf(NOT Monthly_Trend_DOWN AND NOT Monthly_Trend_UP, "Neutral", "");
TrendCol = IIf(Monthly_Trend_UP, colorGreen, IIf(Monthly_Trend_DOWN, colorRed, colorLightGrey));





//Inerpretation
Title = Title_X + "\n" +

EncodeColor(colorBlack) + "RSI(" + WriteVal(RSI_Periods, 1) + "): " +
EncodeColor(colorBrightGreen) + WriteVal(RSI_Value, 1.2) + "\n" +
EncodeColor(colorBlack) + "Vol. Ratio: " + EncodeColor(colorDarkGreen) + WriteVal(MAV_Value, 1.2) + "\n" +
EncodeColor(colorRed) + Trend_Down_Text + EncodeColor(colorBrightGreen) + Trend_Up_Text +
EncodeColor(colorWhite) + Trend_Neutral_Text + "\n" +
EncodeColor(colorRed) + Weekly_Trend_Down_Text + EncodeColor(colorBrightGreen) + Weekly_Trend_Up_Text + "\n" +
EncodeColor(colorRed) + Monthly_Trend_Down_Text + EncodeColor(colorBrightGreen) + Monthly_Trend_Up_Text + "\n" +
EncodeColor(colorRed) + Sell_Alert_Text + EncodeColor(colorBrightGreen) + Buy_Alert_Text + "\n" +
EncodeColor(colorRed) + Fresh_Short_Building + EncodeColor(colorBrightGreen) + Fresh_Buying + EncodeColor(colorWhite) + Short_Covering + EncodeColor(colorWhite) + Possible_Bottom +"\n" +
EncodeColor(colorBrightGreen)+ "Buy Above : " + WriteVal(Reference_High, 1.2)+ "\n" +
EncodeColor(colorCustom5) + "Sell Below: " + WriteVal(ValueWhen(Up_Day, L, 1), 1.2) + "\n" +
EncodeColor(colorCustom12) + "Trend value: " + WriteVal(DailyEMA,1) +"\n"+
EncodeColor(colorBlue)+ Buy_Views + EncodeColor(colorBlue)+ Sell_Views;




//Average, Volitility & Percentage Scale.
av0=V/EMA(V,3);
av1=V/EMA(V,5);
av2=V/EMA(V,13);
av3=V/EMA(V,50);
av4=V/EMA(V,200);
V1= MA(V,50);
r = RSI(2);
s=C-Ref(C,-1);
t=(s/Ref(C,-1))*100;
p=H-L;
ZZ=(p/Ref(C,-1))*100;


//MRam Povit for Daily, Weekly & Monthly

k=IIf(ParamList("select type","daily|next day")=="daily",-1,0);
k1=-1;
TimeFrameSet(inDaily);
day_h= LastValue(Ref(H,K));
day_l= LastValue(Ref(L,K));
day_c= LastValue(Ref(C,K));
TimeFrameRestore();

TimeFrameSet(inWeekly);
Week_h= LastValue(Ref(H,K1));
Week_l= LastValue(Ref(L,K1));;
Week_c= LastValue(Ref(C,K1));;
TimeFrameRestore();

TimeFrameSet(inMonthly);
month_h= LastValue(Ref(H,K1));
month_l= LastValue(Ref(L,K1));
month_c= LastValue(Ref(C,K1));
TimeFrameRestore();

/*--------------------------------------*/
// day
DH=Day_h;
DL=Day_L;
DC=Day_C;

// DAY PIVOT Calculation
pd = ( DC + DC-6 )/2;
sd1 = DC - (DH - DL)/2;
sd2 = DC - (DH - DL);

rd1 = DC + (DH - DL)/2;
rd2 = DC +(DH -DL);

Plot(pd, "PP",colorYellow,styleLine+styleNoLine);
Plot(rd1, "R1",colorBlue,styleLine+styleNoLine);
Plot(Sd1, "S1",colorRed,styleLine+styleNoLine);
Plot(Rd2, "R2",colorBlue,styleLine+styleNoLine);
Plot(Sd2, "S2",colorRed,styleLine+styleNoLine);

// week
WH=Week_h;
WL=Week_l;
WC=Week_c;

// WEEK PIVOT Calculation
pw = ( WC+ WC -6 )/2;
sw1 = WC - (WH - WL )/2;
sw2 = WC -(WH - WL);

rw1 = WC + (WH - WL)/2;
rw2 = WC +(WH -WL);

// month
MH=month_h;
ML=month_l;
MC=month_c;

// MONTH PIVOT Calculation
pm = ( MC + MC - 6 )/2;
sm1 = MC - ( MH - ML )/2;
sm2 = MC -(MH - ML);

rm1 = MC + (MH - ML)/2;
rm2 = MC +(MH -ML);

//stochbuy = Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() > Signal()AND Cross(myStochK, myStochD) AND V>50000;
//stochsell= Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() < Signal()AND Cross(myStochK, myStochD) AND V>50000;

//Filter = Buy AND C>=10 AND V >50000 OR Buy_Alert AND C>=10 AND V >50000 OR Sell AND C>=10 AND V >50000 OR Sell_Alert AND C>=10 AND V >50000;


_SECTION_BEGIN("VELVOORT HEIKIN CANDLE SAR THREE");
//AFL Heikin Ashi

HaClose = (H+L+C)/3;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );

// Velvoort is using not original, but modified Heikin-Ashi close
HaClose = ( HaClose + HaOpen + HaHigh + HaLow )/4;


_SECTION_BEGIN("Price");
//SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
//Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


// you can switch between Heikin-Ashi chart and regular candlestick chart

//tambahan Ku
//Hacol = IIf(HaClose>HaOpen, colorGreen, colorDarkRed);
//SetBarFillColor(Hacol);

//if( ParamToggle("Plot Heikin-Ashi", "No,Yes", 1 ) )
//PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, " " + Name(), IIf(HaClose>HaOpen, colorBlue, colorRed), styleCandle); //colorBlue, styleCandle );
//else
//Plot( C, "Regular candles " + Name(), IIf(Close>Open, colorBlue, colorRed), styleCandle );



_SECTION_BEGIN("Background");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("Outer panel",colorBlack)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack));
tchoice=Param("Title Selection ",2,1,2,1);

//Plot(C, "", IIf(C>=O, colorGreen, colorGreen), ParamStyle("Price Style",styleCandle,maskPrice));
//////////////////////////////////////////////////////////////////
_SECTION_BEGIN("Fib Retracements");
fibs = ParamToggle("Plot Fibs","Off|On",1);
pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
Back = Param ("Extend Left = 2",1,1,500,1);
Fwd = Param("Plot Forward", 0, 0, 500, 1);
//Text = ParamToggle("Plot Text","Off|On",1);
hts = Param ("Text Shift", -33.5,-50,50,0.10);
style =ParamStyle("Line Style",styleLine,styleNoLabel);
x = BarIndex();
pRp = PeakBars( H, pctH, 1) == 0;
yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
pSp = TroughBars( L, pctL, 1) == 0;
ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
Delta = yRp0 - ySp0;

function fib(ret)
{
retval = (Delta * ret);
Fibval = IIf(ret < 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0
AND xSp0 > xRp0, ySp0 + retval, Null))));
return FibVal;
}

x0 = Min(xSp0,xRp0)-Back;
x1 = (BarCount -1);
//////////////////////////////////////////////////////////////////
r236 = fib(0.236); r236I = LastValue (r236,1);
r382 = fib(0.382); r382I = LastValue (r382,1);
r050 = fib(0.50); r050I = LastValue (r050,1);
r618 = fib(0.618); r618I = LastValue (r618,1);
r786 = fib(0.786); r786I = LastValue (r786,1);
e127 = fib(1.27); e127I = LastValue (e127,1);
e162 = fib(1.62); e162I = LastValue (e162,1);
e200 = fib(2.00); e200I = LastValue (e200,1);
e262 = fib(2.62); e262I = LastValue (e262,1);
e424 = fib(4.24); e424I = LastValue (e424,1);
//////////////////////////////////////////////////////////////////
p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
//////////////////////////////////////////////////////////////////
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
//////////////////////////////////////////////////////////////////
if(fibs==1)
{
Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null, Null,Fwd);
}
//////////////////////////////////////////////////////////////////
//if(Text==1)
{
PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00);
//PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
//PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
//PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
//PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
//PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
//PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
//PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
//PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
//PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
//PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
//PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
}
_SECTION_END();
//////////////////////////////////////////////////////////////////
if (tchoice==1 )
{
_N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} - {{INTERVAL}} {{DATE}} Open: %g, High: %g, Low: %g, Close: %g {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
}
//////////////////////////////////////////////////////////////////
if (tchoice==2 )
{
Title = EncodeColor(colorWhite)+ Date() + " Tick = " + EncodeColor(5) + Interval()+
EncodeColor(colorWhite) + " Open = " + EncodeColor(colorWhite) + O +
EncodeColor(colorWhite) + " High = " + EncodeColor(5) + H +
EncodeColor(colorWhite) + " Low = " + EncodeColor(colorRed) + L +
EncodeColor(colorWhite) + " Close = " + EncodeColor(colorWhite) + C + "\n" +
EncodeColor( colorWhite) +"_______________"+"\n"+
EncodeColor( colorWhite) + "424% = " + EncodeColor(25)+ e424 + " " +"\n"+
EncodeColor( colorWhite) + "262% = " + EncodeColor(47)+ e262 + " " +"\n"+
EncodeColor( colorWhite) + "200% = " + EncodeColor(47)+ e200 + " " +"\n"+
EncodeColor( colorWhite) + "162% = " + EncodeColor(47)+ e162 + " " +"\n"+
EncodeColor( colorWhite) + "127% = " + EncodeColor(47)+ e127 + " " +"\n"+
EncodeColor( colorYellow) + " Res OR Sup = " + EncodeColor(32)+ p100 + " " +"\n"+
EncodeColor( colorWhite) + " 78% = " + EncodeColor(42)+ r786 + " " +"\n"+
EncodeColor( colorWhite) + " 62% = " + EncodeColor(43)+ r618 + " " +"\n"+
EncodeColor( colorWhite) + " 50% = " + EncodeColor(41)+ r050 + " " +"\n"+
EncodeColor( colorWhite) + " 38% = " + EncodeColor(44)+ r382 + " " +"\n"+
EncodeColor( colorWhite) + " 23% = " + EncodeColor(45)+ r236+ " " +"\n"+
EncodeColor( colorYellow) + " Sup OR Res = " + EncodeColor(34)+ p00 + " " ;
}
GraphXSpace=5;







_SECTION_BEGIN("Peak");
//Peak-Trough System + Auto ATR + Position sizing+Varible Sensitivity//
// Last Update 16 Oct 05 By Kook//

PctVlt=(ATR(14)/C)*100;//PercentVolatility

PK=IIf(PctVlt<0.5,Peak(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Peak(Close,0.70,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Peak(Close,0.90,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Peak(Close,1.10,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Peak(Close,1.30,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Peak(Close,1.50,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Peak(Close,1.70,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Peak(Close,2.00,1),
Peak(Close,2.20,1) ))))))));

TGH=IIf(PctVlt<0.5,Trough(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Trough(Close,0.75,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Trough(Close,1.00,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Trough(Close,1.25,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Trough(Close,1.50,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Trough(Close,1.75,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Trough(Close,2.00,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Trough(Close,2.25,1),
Trough(Close,2.50,1) ))))))));

Sens=IIf(PctVlt<0.5,0.5,
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,0.75,
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,1.00,
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,1.25,
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,1.50,
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,1.75,
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,2.00,
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,2.25,
2.50 ))))))));

Color=IIf(BarsSince(Cross(C,Ref(PK,-1)))<BarsSince(Cross(Ref(TGH,-1),C)),colorBrightGreen,colorRed);

//Plot(C,"C",Color,styleCandle);
//PlotShapes( Cross(C,Ref(PK,-1))*shapeUpArrow,colorYellow,0,L);
//PlotShapes( Cross(Ref(TGH,-1),C)*shapeDownArrow,colorPink,0,H);
//PlotShapes( Cross(84,RSI(36))*shapeDownArrow,colorYellow,0,H,Offset=-28 );
//PlotShapes( Cross(67.4,RSI(171))*shapeDownArrow,colorYellow,0,H,Offset=-28 );
//PlotShapes( Cross(27,RSI(95))*shapeUpArrow,colorYellow,0,L,Offset=-28 );

//PlotShapes( Cross(95.9,StochD(4200))*shapeDownArrow,colorCustom12,0,H,Offset=-28 );
//PlotShapes( Cross(0.50,StochD(4200))*shapeUpArrow,colorCustom12,0,H,Offset=-28 );

Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
TT= RSIa(C,130);
StartBar = ValueWhen(TimeNum() == 093000, BarIndex());
TodayVolume = Sum(TT,Bars_so_far_today);
IIf (BarIndex() >= StartBar, VWAP = Sum (C * TT, Bars_so_far_today ) / TodayVolume,0);
//Plot (VWAP,"VWAP",colorCustom11,4 +8+2048 );


clDay1 = (TimeFrameGetPrice("c",inDaily,-1));
clDay2 = (TimeFrameGetPrice("c",inDaily,-2));
clDay3 = (TimeFrameGetPrice("c",inDaily,-3));
clDay4 = (TimeFrameGetPrice("c",inDaily,-4));
clDay5 = (TimeFrameGetPrice("c",inDaily,-5));




stoploss = (clDay1+clDay2+clDay3+clDay4 +clDay5)/5;


//Plot( (stoploss ),"3",colorBrown,4 +8+2048 );

Buyabv=stoploss+31;

//Plot( (Buyabv ),"3",colorGreen,4 +8+2048 );

Sellbel=stoploss-31;
//Plot( (Sellbel ),"3",colorRed,4 +8+2048 );


Pivot = ParamToggle("Pivot_day", "No|Yes", 1);

if(Pivot)
{
H1 = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
L1 = TimeFrameGetPrice("L", inDaily, -1); // low
C1= TimeFrameGetPrice("C", inDaily, -1); // close
Op = TimeFrameGetPrice("O", inDaily)-1; // current day open

}
else
{
H1 = TimeFrameGetPrice("H", inDaily); // yesterdays high
L1 = TimeFrameGetPrice("L", inDaily); // low
C1= TimeFrameGetPrice("C", inDaily);
Op = TimeFrameGetPrice("O", inDaily); // current day open

}




// PIVOT Calculation
P = ( H1+ L1 +L1 + C1 )/4;
S1 = p-(H1-P);
R1 = (P-L1)+P;
S2 = P -(H1 - L1);
S3 = S1 - (H1-L1);
S4 = S2 - (H1-L1);
S5 = S3 - (H1-L1);
S6 = S4 - (H1-L1);
S7 = S5 - (H1-L1);
S8 = S6 - (H1-L1);
S9 = S7 - (H1-L1);
S10 = S8 - (H1-L1);

R2 = P +(H1 - L1);
R3 = R1 +(H1-L1);
R4 = R2 +(H1-L1);
R5 = R3 +(H1-L1);
R6 = R4 +(H1-L1);
R7 = R5 +(H1-L1);
R8 = R6 +(H1-L1);
R9 = R7 +(H1-L1);
R10 = R8 +(H1-L1);
Ho=(H1-Op)+OP;
Ol=(Op-L1)+OP;

X=( H1+ L1 +L1 + C1 );

TDU=(X/2)-L1;
TDL=(X/2)-H1;

//Plot(round(TDU), "",colorOrange,4+8+2048);

//Plot(round(TDL), "",colorGreen,4+8+2048);

_SECTION_BEGIN("RSI BUY SELL");
per1=Param ("per1", 5.0,0.5,100,0.9);

per=per1;

n=55;

x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa(C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSIa(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(ValueWhen( (S1==trendlineS ), L),"", colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((S11==trendlineR ), H),"", colorRed, styleDashed|styleNoRescale|styleThick);
Cover2 = (S1==trendlineS );
Short2 = (S11==trendlineR );


_SECTION_BEGIN("RSI BUY SELL");
n=55;
per = 5;
x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa(C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSIa(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(ValueWhen( (S1==trendlineS ), L),"", colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((S11==trendlineR ), H),"", colorRed, styleDashed|styleNoRescale|styleThick);
Cover1 = (S1==trendlineS );
Short1 = (S11==trendlineR );

SBuy = TROUGHCover OR Cover1 OR Cover2;

SSell= PEAKShort OR Short1 OR Short2;





{


/*
Heikin-Ashi(Koma-Ashi) with Moving Average Type
*/
SetChartOptions(2, chartWrapTitle);
// Calculate Moving Average
MAPeriod = Param("MA Period", 6, 1, 50);
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.44);
// for graph collapse
for (i = 0; i <= MAPeriod; i++)
HaClose = Null;
/*
// same
// HaOpen = (Ref(HaOpen, -1) + Ref(HaClose, -1)) / 2;
HaOpen[ 0 ] = HaClose[ 0 ];
for(i = 1; i < BarCount; i++) {
HaOpen = (HaOpen[i - 1] + HaClose[i - 1]) / 2;

*/
HaHigh = Max(MAHigh, Max(HaClose, HaOpen));
HaLow = Min(MALow, Min(HaClose, HaOpen));
// outs comments
"BarIndex = " + BarIndex();
"Open = " + Open;
"High = " + High;
"Low = " + Low;
"Close = " + Close;
"HaOpen = " + HaOpen;
"HaHigh = " + HaHigh;
"HaLow = " + HaLow;
"HaClose = " + HaClose;
// Plot graphs
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} HaOpen %g, HaHigh %g, HaLow %g, HaClose %g (%.1f%%) {{VALUES}}", HaOpen, HaHigh, HaLow, HaClose, SelectedValue(ROC(HaClose, 1))));

//PlotOHLC(MaOpen, MaHigh, MaLow, MaClose, _DEFAULT_NAME(), ParamColor("Color", colorBlack), styleCandle);

//bestbuy = Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() > Signal()AND Cross(myStochK, myStochD) AND V>50000 OR Buy AND C>=10 AND V >50000 AND MACD() > Signal()AND Cross(myStochK, myStochD) OR Buy_Alert AND C>=10 AND V >50000 AND MACD() > Signal()AND Cross(myStochK, myStochD);

//bestsell= Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() < Signal()AND Cross(myStochK, myStochD) AND V>10000 OR Sell AND C>=10 AND V >50000 AND MACD() < Signal()AND Cross(myStochK, myStochD) OR Sell_Alert AND C>=10 AND V >50000 AND MACD() < Signal()AND Cross(myStochK, myStochD);

//PlotShapes(IIf( bestSell, shapeDownArrow, shapeNone), colorYellow, 0, High, Offset= 10);
//PlotShapes(IIf( bestBuy , shapeUpArrow , shapeNone), colorYellow, 0, Low, Offset= -10);

//Fractals
nbar = Param("Longer Term",21,2,10000,1);

PHigh = HaHigh > Ref(HHV(HaHigh,nbar),-1) AND Ref(HHV(HaHigh,nbar),nbar) <= HaHigh;
PHighPrice = ValueWhen(PHigh,HaHigh);
PLow = HaLow < Ref(LLV(L,nbar),-1) AND Ref(LLV(HaLow,nbar),nbar) >= HaLow;
PLowPrice = ValueWhen(PLow,HaLow);

//Plot(PLowPrice, "Fractal Low", colorCustom11, styleDots | styleLine);
//Plot(PHighPrice, "Fractal High", colorCustom12, styleDots | styleLine);

//Plot(MA(Close,3),"",colorCustom11, styleLine);
//Plot(MA(HaCLOSE,5),"",colorRed, styleLine);
no= 10 ;
res= EMA(HaHigh,6);
Avg= EMA( HaClose, 6 ) ;
sup= EMA(HaLow,6);
avd=IIf( HaClose>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
supres= IIf(avn==1,sup,res) ;
//Plot(supres," MOBILE: +91-9367151067(India) STOP LOSS ",colorYellow,styleStaircase,0,0,0);

// Plot(EMA(HaClose,18),"",colorCustom12, styleLine);
//_N(Title = "{{NAME}} - {{INTERVAL}} {{DATE}}: "+" : {{OHLCX}} " +EncodeColor( colorRed) +" V "+WriteVal(V, 1));

//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} \nOpen %1.2f, Hi %1.2f, Lo %1.2f, Close %1.2f (%.1f%%) Vol " + WriteVal( V, 1.0 ) + // " {{VALUES}} " +

//"\nEMA-1: " + WriteVal(EMA(C, 1), 1.2) + EncodeColor(colorWhite) +
//"\nEMA-2: " + WriteVal(EMA(C, 2), 1.2) + EncodeColor(colorCustom11) +
//"\nEMA-3: " + WriteVal(EMA(C, 3), 1.2) + EncodeColor(colorCustom9) +
//"\nEMA-6 H: " + WriteVal(EMA(H, 6), 1.2) + EncodeColor(colorCustom12) +
//"\nEMA-6 L: " + WriteVal(EMA(L, 6), 1.2) + EncodeColor(colorOrange) +
//"\nEMA-13: " + WriteVal(EMA(C, 13), 1.2) + EncodeColor(colorDarkOliveGreen) +
//"\nEMA-50: " + WriteVal(EMA(C, 50), 1.2) + EncodeColor(colorGold) +
//"\nEMA-100: " + WriteVal(EMA(C, 100), 1.2) + EncodeColor(colorBrown) +
//"\nEMA-150: " + WriteVal(EMA(C, 150), 1.2) + EncodeColor(colorRed) +
//O,H,L,C ));
_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI() AND MACD()>Signal();
downtrend=MDI()>PDI() AND Signal()>MACD();
//Plot( 2, /* defines the height of the ribbon in percent of pane width */"",
// IIf( uptrend AND EMA(C,50)>=Ref(EMA(C,50),-1), colorLime, IIf( downtrend OR EMA(C,50)<Ref(EMA(C,50),-1),
// colorRed, colorTan)) , /* choose color */styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//TREND ADVISER

pointer[0] = 0;

/* Phase filter */

Cond1 = Close > MA(Close, 50)AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
Cond2 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND NOT(MA(Close, 50) > MA(Close, 200));
Cond3 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond4 = NOT(Close > MA(Close, 50))AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond5 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND MA(Close, 50) > MA(Close, 200);
Cond6 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));


for (i = 1; i < BarCount; i++)
{

if (Cond1)
pointer = 1;
if (Cond2)
pointer = 2;
if (Cond3)
pointer = 3;
if (Cond4)
pointer = 4;
if (Cond5)
pointer = 5;
if (Cond6)
pointer = 6;

}

/* Plot Graphic */
//GraphXSpace= 15 ;
dynamic_color = IIf(pointer < 4, colorGreen, colorRed);
//Plot(pointer, "TrendAdv2", dynamic_color, styleHistogram | styleThick, Null, Null, 0);
//SetChartBkGradientFill(ParamColor("BgTop", colorWhite), ParamColor("BgBottom", colorLightYellow));
Cond= pointer < 4 ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx






/* my entry is very simple(daily data for trading)

kpl system for entry only & exit as follow:

1 st exit at x % from entry price only 1/3 quantity.(ie 1st profit target)
2 nd exit when exit Signal comes from kpl sys remaining 1/3 quantity.
3. scale-in to initial quantity if new kpl Buy Signal comes.
re-do above scaling-out & scaling-in till filal exit.
4. final exit all quantity when Close below 21 Day EMA.

kpl system code bellow :
*/
//AFL by Kamalesh Langote. Email:kpl@...
noR =Param( "SwingR", 6, 1, 55 ) ;
noS =Param( "SwingS", 3, 1, 55 ) ;
res=HHV(H,noR);
sup=LLV(L,noS);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);
//tsl_col=ParamColor( "Color", colorCycle );
tsl_col= IIf(avn==1,colorCustom11,colorRed );
//Plot(tsl, "KPL", tsl_col, styleLine | styleThick);
kplBuy = C > Ref(res,-1);
kplSell = Ref(sup,-1) > C ;
//shape=kplBuy*shapeUpArrow + kplSell*shapeDownArrow;
//PlotShapes(shape,IIf(kplBuy,colorBrightGreen,colorRed),0,IIf(kplBuy,Low,High));
SetPositionSize(300,spsShares);
ApplyStop(0,1,10,1);

//Buy = SBUY OR kplbuy;
//Sell= SSELL OR kplsell;


//Plot( Flip( Buy, Sell ), "", colorDarkGreen, styleArea | styleOwnScale, 100, 10 );
//Plot( Flip( Sell, Buy ), "", colorDarkRed, styleArea | styleOwnScale, 100, 10);




//shape=Cover*shapeUpTriangle + Short*shapeDownTriangle;
//PlotShapes(shape,IIf(Cover,colorGreen,colorCustom12),0,IIf(Cover,HaLow,HaHigh));



//Buy=ExRem(Buy,Sell);
//Sell=ExRem(Sell,Buy);



//dist = 0.3*ATR(5);
//for( i = 0; i < BarCount; i++ )
//{
//if( Buy ) PlotText( " BUY " + L[ i ], i, L[ i ]-dist, colorCustom11);
//if( Sell ) PlotText( " SELL " + H[ i ], i, H[ i ]+dist, colorCustom12);
//}





_SECTION_BEGIN("BW Fractal");

/* UpFractal= ValueWhen( */
SellFractal= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2));

/* DownFractal= ValueWhen( */
BuyFractal= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2));


NewSellFractal=(Ref(SellFractal,2) > Ref(SellFractal,1) OR Ref(SellFractal,2) < Ref(SellFractal,1));
NewBuyFractal=(Ref(BuyFractal,2) > Ref(BuyFractal,1) OR Ref(BuyFractal,2) < Ref(BuyFractal,1) );

//== Added Crash crashandburn59 [at] hotmail.com solution
//Plot(Ref(SellFractal,2), "Sell Fractal", ParamColor("Sell Fractal Color",colorRed), ParamStyle("Sell Fractal Style", styleDashed));
//Plot(Ref(BuyFractal,2), "Buy Fractal",ParamColor("Buy Fractal Color",colorBlue), ParamStyle("Buy Fractal Style", styleDashed));

//PlotShapes(IIf(NewSellFractal,shapeDownArrow,shapeNone),colorRed,0,High,Offset=-12);
//PlotShapes(IIf(NewBuyFractal,shapeUpArrow,shapeNone),colorBlue,0,Low,Offset=-12);


//Plot(Max(HHV(H,3),Ref(UpFractal,2)), "Up Fractal", ParamColor("Up Fractal Color",colorRed), ParamStyle("Up Fractal Style", styleDashed));
//Plot(Max(HHV(H,3),Ref(UpFractal,2)), "Down Fractal",ParamColor("Down Fractal Color",colorBlue), ParamStyle("Down Fractal Style", styleDashed));

_SECTION_END();



//Sell=ExRem(Sell,Buy);
//Buy=ExRem(Buy,Sell);



//Filter = 1; /* all symbols and quotes accepted */
//filer = Buy OR Sell ;
/*DOJI definitions*/

/*Doji Today - (DT)*/

smallBodyMaximum=0.0025;//less than 0.25%

DT = abs(C-O) <= (C*smallBodyMaximum) OR (abs(O-C)<=((H-L)*0.1));

/* Doji Yesterday - (DY)*/
DY = abs(Ref ( C, -1)-Ref(O,-1)) <= Ref ( C, -1) *smallBodyMaximum OR abs (Ref ( O, -1)-Ref(C,-1)) <= (Ref ( H, -1 ) - Ref ( L, -1 ) )*0.1;




}

SetChartOptions(0,chartShowArrows|chartShowDates);

//_N(Title = "{{NAME}} - {{INTERVAL}} {{DATE}}: "+" : {{OHLCX}} " +EncodeColor( colorRed) +" V "+WriteVal(V, 1)+ EncodeColor(colorWhite) );

_SECTION_END();

SwingTrd1 = 100 * (Close - ((MA(C,2)+
MA(MA(C,2),2)+
MA(MA(MA(C,2),2),2) +
MA(MA(MA(MA(C,2),2),2),2) +
MA(MA(MA(MA(MA(C,2),2),2),2),2) +
MA(MA(MA(MA(MA(MA(C,2),2),2),2),2),2) +
MA(MA(MA(MA(MA(MA(MA(C,2),2),2),2),2),2),2)+
MA(MA(MA(MA(MA(MA(MA(MA(C,2),2),2),2),2),2),2),2)+
MA(MA(MA(MA(MA(MA(MA(MA(MA(C,2),2),2),2),2),2),2), 2),2)+
MA(MA(MA(MA(MA(MA(MA(MA(MA(MA(C,2),2),2),2),2),2), 2),2),2),2))/10))/(HHV(C,10)-LLV(C,10));
SwingTrd2=EMA(SwingTrd1,30);
SwingTrd3=EMA(SwingTrd2,30);
RMO= EMA(SwingTrd1,81);
RMOBuy=Cross(SwingTrd2,SwingTrd3);
RMOSell=Cross(SwingTrd3,SwingTrd2);
Bull_Trend=EMA(SwingTrd1,81)>0;
Bear_Trend=EMA(SwingTrd1,81)<0;
Ribbon_kol=IIf(Bull_Trend,colorGreen, IIf(Bear_Trend,colorRed, colorBlack));
//Plot(4, "ribbon", Ribbon_kol, styleOwnScale|styleArea|styleNoLabel, -0.5,100);
Impulse_UP= EMA(SwingTrd1,30) > 0;
Impulse_Down= EMA(SwingTrd1,81) < 0;
bar_kol=IIf(TROUGHCover, colorBlue, IIf(PEAKShort, colorRed,IIf(impulse_down,colorRed, colorBlue)));
//Plot(Close,"Close",bar_kol,styleCandle | styleThick );
//shape = Buy * shapeUpArrow + Sell * shapeDownArrow;



//bestbuy = Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() > Signal()AND Cross(myStochK, myStochD) AND V>50000 OR Buy AND C>=10 AND V >50000 AND MACD() > Signal()AND Cross(myStochK, myStochD) OR Buy_Alert AND C>=10 AND V >50000 AND MACD() > Signal()AND Cross(myStochK, myStochD);

//bestsell= Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() < Signal()AND Cross(myStochK, myStochD) AND V>10000 OR Sell AND C>=10 AND V >50000 AND MACD() < Signal()AND Cross(myStochK, myStochD) OR Sell_Alert AND C>=10 AND V >50000 AND MACD() < Signal()AND Cross(myStochK, myStochD);

//PlotShapes(IIf( bestSell, shapeDownArrow, shapeNone), colorYellow, 0, High, Offset= 10);
//PlotShapes(IIf( bestBuy , shapeUpArrow , shapeNone), colorYellow, 0, Low, Offset= -10);




//stochbuy = Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() > Signal()AND Cross(myStochK, myStochD) AND V>50000;
//stochsell= Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() < Signal()AND Cross(myStochK, myStochD) AND V>50000;

//Filter = Buy AND C>=10 AND V >50000 OR Buy_Alert AND C>=10 AND V >50000 OR Sell AND C>=10 AND V >50000 OR Sell_Alert AND C>=10 AND V >50000;



_SECTION_BEGIN("MACD Exploration");
r1 = Param( "Fast avg", 15, 2, 200, 1 );
r2 = Param( "Slow avg", 30, 2, 200, 1 );
r3 = Param( "Signal avg", 12, 2, 200, 1 );
Z=Param("zig",1,0,10,0.1);
Cond1 = Cross(MACD(r1,r2),Signal(r1,r2,r3));

EMA34 = EMA(C,10);
LSMA = LinearReg(C,25);
//LSMA = LinearReg(C,20);

//Uncomment for lsma.
//Plot(LSMA,"LSMA 25", colorLightBlue, styleLine | styleNoLabel | styleThick);

PI = atan(1.00) * 4;
periods = 30;
HighHigh = HHV(H, periods);
LowLow = LLV(L, periods);
range = 25 / (HighHigh - LowLow) * LowLow;

x1_EMA34 = 0;
x2_EMA34 = 2;
y1_EMA34 = 0;
y2_EMA34 = (Ref(EMA34, -2) - EMA34) / Avg * range;

c_EMA34 = sqrt((x2_EMA34 - x1_EMA34)*(x2_EMA34 - x1_EMA34) + (y2_EMA34 - y1_EMA34)*(y2_EMA34 - y1_EMA34));
angle_EMA34 = round(180 * acos((x2_EMA34 - x1_EMA34)/c_EMA34) / PI);

TitleAngleEMA34 = EncodeColor(colorWhite) + "\nEMA34 angle = ";

angle_EMA34 = IIf(y2_EMA34 > 0, - angle_EMA34, angle_EMA34);
if(abs(SelectedValue(angle_EMA34)) >= 25)
{
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorYellow);
}
else if(abs(SelectedValue(angle_EMA34)) >= 15)
{
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorBlue);
}
else
{
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorRed);
}
TitleAngleEMA34 = TitleAngleEMA34 + angle_EMA34;

//////////////////////////////////////////////////////////////////////////////

Color_ema_eangle= IIf(angle_ema34>=5,colorYellow,IIf(angle_ema34<=-5,colorRed,colorBlue));

//Plot(EMA34,"EMA 34",Color_ema_eangle, styleDots | styleThick|styleThick );


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//TRENDING RIBBON
// Paste the code below to your price chart somewhere and green ribbon means both
// both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX
// are both trending down.
_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI() AND MACD()>Signal();
downtrend=MDI()>PDI() AND Signal()>MACD();
//Plot( 2, /* defines the height of the ribbon in percent of pane width */"",
// IIf( uptrend AND EMA(C,50)>=Ref(EMA(C,50),-1), colorLime, IIf( downtrend OR EMA(C,50)<Ref(EMA(C,50),-1),
// colorRed, colorTan)) , /* choose color */styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//TREND ADVISER

pointer[0] = 0;

/* Phase filter */

Cond1 = Close > MA(Close, 50)AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
Cond2 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND NOT(MA(Close, 50) > MA(Close, 200));
Cond3 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond4 = NOT(Close > MA(Close, 50))AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond5 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND MA(Close, 50) > MA(Close, 200);
Cond6 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));


for (i = 1; i < BarCount; i++)
{

if (Cond1)
pointer = 1;
if (Cond2)
pointer = 2;
if (Cond3)
pointer = 3;
if (Cond4)
pointer = 4;
if (Cond5)
pointer = 5;
if (Cond6)
pointer = 6;

}

/* Plot Graphic */
//GraphXSpace= 15 ;
dynamic_color = IIf(pointer < 4, colorGreen, colorRed);
//Plot(pointer, "TrendAdv2", dynamic_color, styleHistogram | styleThick, Null, Null, 0);
//SetChartBkGradientFill(ParamColor("BgTop", colorWhite), ParamColor("BgBottom", colorLightYellow));
Cond= pointer < 4 ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx




//KPL

/* my entry is very simple(daily data for trading)

kpl system for entry only & exit as follow:

1 st exit at x % from entry price only 1/3 quantity.(ie 1st profit target)
2 nd exit when exit Signal comes from kpl sys remaining 1/3 quantity.
3. scale-in to initial quantity if new kpl Buy Signal comes.
re-do above scaling-out & scaling-in till filal exit.
4. final exit all quantity when Close below 21 Day EMA.

kpl system code bellow :
*/
//AFL by Kamalesh Langote. Email:kpl@...
noR =Param( "SwingR", 5, 1, 55 ) ;
noS =Param( "SwingS", 2, 1, 55 ) ;
res=HHV(H,noR);
sup=LLV(L,noS);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);
//tsl_col=ParamColor( "Color", colorCycle );
tsl_col= IIf(avn==1,colorCustom11,colorRed );
//Plot(tsl, "KPL", tsl_col, styleLine | styleThick);
TSLBuy = C > Ref(res,-1);
TSLSell = Ref(sup,-1) > C ;
//shape=kplBuy*shapeUpArrow + kplSell*shapeDownArrow;
//PlotShapes(shape,IIf(kplBuy,colorBrightGreen,colorRed),0,IIf(kplBuy,Low,High));
SetPositionSize(300,spsShares);
ApplyStop(0,1,10,1);
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//HEIKIN-ASHI
//SetChartOptions(0,chartShowArrows | chartShowDates);
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 ) );
xDiff = (HaHigh - Halow) * 10000;
//barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
barcolor= IIf(HaClose>=HaOpen,colorGreen,colorRed) ;
//SetBarFillColor(IIf(HaClose>=HaOpen,colorLime,colorRed));
//PlotOHLC( Open, High, Low, Close, "", colorWhite, styleCandle );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//FORMULE
P = ParamField("Price field",-1);
cuptop1= C>BBandTop(p,20,1) ;
bot1= BBandBot(p,20,1) ;
top2= BBandTop(p,20,2) ;
bot2= BBandBot(p,20,2) ;
stochup= StochK()>StochD() ;
MACDup= MACD()>Signal() ;
Hist= MACD()-Signal() ;
Histup= Hist>Ref(Hist,-1) ;
MFIupema5= MFI()>EMA(MFI(),5) ;
Cupo= C>=O ;
top1up= BBandTop(p,20,1)>=Ref(BBandTop(p,20,1),-1) ;
top2up= BBandTop(p,20,2)>=Ref(BBandTop(p,20,2),-1) ;
band= BBandTop(p,20,2)-BBandBot(p,20,2) ;
Volatbuy= band>Ref(band,-1) ;
cupbot1= C>BBandBot(p,20,1) ;
bot1up= BBandBot(p,20,1)>Ref(BBandBot(p,20,1),-1) ;
MA20up= MA(C,20)>=Ref(MA(C,20),-1) ;
EMA50up= EMA(C,50)>=Ref(EMA(C,50),-1) ;
Vup10= V>10000 AND C>O ;
Vupma= MA(V,5)>MA(V,21) ;
CCIup0= CCI()>0 ;
CCI200= CCI()<200 ;
Cupma20= C>MA(C,20) ;
ADXup= ADX()>=Ref(ADX(),-1) ;
ADX45= ADX()<45 ;
PDIupmdi= PDI()>MDI() ;
Cond= pointer<4 ;
heikinup= HaClose>=HaOpen ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

myBuy= C>tsl AND Cond AND Heikinup AND Cupo AND EMA50up ;
mySell= C<tsl ;

//Cover = ExRem(mybuy,mysell) ;
//Short = ExRem(mysell,mybuy) ;

//shape=Cover*shapeUpTriangle + Short*shapeDownTriangle;
//PlotShapes(shape,IIf(Cover,colorGreen,colorCustom12),0,IIf(Cover,HaLow,HaHigh));

/////////////////////////////////////////////////////////////////////////////////////////////////////////



_SECTION_BEGIN("Price Line");

PriceLineColor=ParamColor("PriceLineColor",ColorRGB(82,82,82));
PriceLevel = ParamField("PriceField", field = 3 );

Daysback = Param("Bars Back",100,10,500,1);
FirstBar = BarCount - DaysBack;
YY = IIf(BarIndex() >= Firstbar,EndValue(PriceLevel),Null);

//Plot(YY,"Current Price",PriceLineColor,ParamStyle("LineStyle",styleLine|styleDashed|styleNoTitle|styleNoLabel|styleThick,maskAll));


side = Param("side",1,0,1000,1);

dist = 0;

for( i = 0; i < BarCount; i++ )
{
if(i+side== BarCount) PlotText( "\n " + PriceLevel[ i ], i, YY[ i ]-dist, colorWhite );
}

_SECTION_END();
_SECTION_BEGIN("BW Fractal");

/* UpFractal= ValueWhen( */
SellFractal= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2));

/* DownFractal= ValueWhen( */
BuyFractal= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2));


NewSellFractal=(Ref(SellFractal,2) > Ref(SellFractal,1) OR Ref(SellFractal,2) < Ref(SellFractal,1)) OR C < Ref(BUYFRACTAL,4);
NewBuyFractal=(Ref(BuyFractal,2) > Ref(BuyFractal,1) OR Ref(BuyFractal,2) < Ref(BuyFractal,1) ) OR C > Ref(SellFRACTAL,4) ;

//== Added Crash crashandburn59 [at] hotmail.com solution
//Plot(Ref(SellFractal,4), "STOP-UP", ParamColor("SELL FORCE COLOR",colorCustom12), ParamStyle("Sell Fractal Style", styleDashed));
//Plot(Ref(BuyFractal,4), "STOP-DOWN",ParamColor("BUY FORCE COLOR",colorCustom11), ParamStyle("Buy Fractal Style", styleDashed));




// BBands_Stop_v1.mq4 by [email protected]
// translation in Amibroker AFL, E.M.Pottasch, 2011
SetChartBkColor(64);
Length= 10; // Period
Deviation= 1;
// Deviation was 2
MoneyRisk= 1.0;
// Offset Factor
TurnedUp=Nz(StaticVarGet("TurnedUp"));
TurnedDown=Nz(StaticVarGet("TurnedDown"));
SoundON = ParamToggle("Sound","Off|On",1);
procedure
CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown){global UpTrendLine;
global DownTrendLine;
global smax;
global smin;
UpTrendLine=Null;
DownTrendLine=Null;
smax=Null;
smin=Null;
trend=0;
for (i=Length+1;
i<BarCount;
i++){ smax=bbtop;
smin=bbbot;
if (C>smax[i-1]) trend=1;
if (C<smin[i-1]) trend=-1;
if(trend>0 && smin<smin[i-1]) smin=smin[i-1];
if(trend<0 && smax>smax[i-1]) smax=smax[i-1];
bsmax=smax+0.5*(MoneyRisk-1)*(smax-smin);
bsmin=smin-0.5*(MoneyRisk-1)*(smax-smin);
if(trend>0 && bsmin<bsmin[i-1]) bsmin=bsmin[i-1];
if(trend<0 && bsmax>bsmax[i-1]) bsmax=bsmax[i-1];
if (trend>0) { UpTrendLine=bsmin;
if (SoundON==True && !TurnedUp && i==BarCount-1 && IsEmpty(UpTrendLine[i-1])) { Say("BUYYY BUYYY BUYYY BUYYY BUYYY BUYYY");
TurnedUp=StaticVarSet("TurnedUp",1);
TurnedDown=StaticVarSet("TurnedDown",0);
} } if (trend<0) { DownTrendLine=bsmax;
if (SoundON==True && !TurnedDown && i==BarCount-1 && IsEmpty(DownTrendLine[i-1])) { Say("SELLL SELLL SELLL SELLL SELLL SELLL SELLL SELLL");
TurnedUp=StaticVarSet("TurnedUp",0);
TurnedDown=StaticVarSet("TurnedDown",1);
} }}}bbtop=BBandTop(C,Length,Deviation);
bbbot=BBandBot(C,Length,Deviation);
CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown);
UpTrendSigNal=UpTrendLine AND IsEmpty(Ref(UpTrendLine,-1));
DownTrendSigNal=DownTrendLine AND IsEmpty(Ref(DownTrendLine,-1));
// chartGraphXSpace = 5;SetChartOptions(0, chartShowDates);
//Plot(C,"",colorWhite,styleCandle);
Plot(UpTrendLine,"BULL FORCE",colorCustom11,styleThick,3) ;
Plot(DownTrendLine,"BEAR FORCE",colorCustom12,styleThick,3);
PlotShapes(IIf(UpTrendSignal,shapeSmallUpTriangle,shapeNone),ColorRGB(0,191,255),0,L,-15);
//PlotShapes(IIf(UpTrendSignal,shapeHollowSmallCircle,shapeNone),colorWhite,0,C,0);
PlotShapes(IIf(DownTrendSignal,shapeSmallDownTriangle,shapeNone),ColorRGB(255,20,147),0,H,-15);
//PlotShapes(IIf(DownTrendSignal,shapeHollowSmallCircle,shapeNone),colorWhite,0,C,0);

TRENDBuy = UPTRENDSIGNAL;
TRENDSell= DOWNTRENDSIGNAL;


_SECTION_BEGIN("VELVOORT HEIKIN CANDLE SAR THREE");
//AFL Heikin Ashi

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

// Velvoort is using not original, but modified Heikin-Ashi close
HaClose = ( HaClose + HaOpen + HaHigh + HaLow )/4;





// you can switch between Heikin-Ashi chart and regular candlestick chart

//tambahan Ku
Hacol = IIf(HaClose>HaOpen, colorDarkBlue, colorDarkRed);
SetBarFillColor(Hacol);

//if( ParamToggle("Plot Heikin-Ashi", "No,Yes", 1 ) )
//PlotOHLC( haOpen, High, Low, Close, " " + Name(), IIf(HaClose>HaOpen, colorBlue, colorRed), styleCandle); //colorBlue, styleCandle );
//else
//Plot( C, "Regular candles " + Name(), IIf(Close>Open, colorBlue, colorRed), styleCandle );

// E.M.Pottasch, Jul 2010
// from Metastock formula, link:
//http://stocata.org/metastock/stop_trail_atr.html

function vstop_func(tr)
{
trailArray[ 0 ] = HaClose[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];

if (HaClose[ i ] > prev AND HaClose[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,HaClose[ i ] - tr[ i ]);
}
else if (C[ i ] < prev AND HaClose[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,HaClose[ i ] + tr[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = HaClose[ i ] - tr[ i ];
}
else
{
trailArray[ i ] = HaClose[ i ] + tr[ i ];
}
}
return trailArray;
}

per = Param("per",20, 5, 150, 1);
mult = Param("mult",2, 1, 4, 0.05);
tr = mult * ATR(per);
trailArray = vstop_func(tr);
//trailArray = Ref(trailArray,-1);

SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) );
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
//Plot(IIf(trailArray >
//C,trailArray,Null),"\ntrailShort",ParamColor("ColorTrailShort",ColorRGB(255,0,0)),styleStaircase);
//Plot(IIf(trailArray <
//C,trailArray,Null),"\ntrailLong",ParamColor("ColorTrailLong",ColorRGB(0,255,0)),styleStaircase);
//Plot( C, "\nCandle",colorWhite, styleCandle );





acc = Param("Acceleration", 0.03, 0, 3, 0.001 );
accm = Param("Max. acceleration", 0.5, 0, 3, 0.001 );


//Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorYellow ), ParamStyle("Style", styleStaircase | styleLine, maskDefault | styleStaircase | styleLine ) );



SARSell = Cross(SAR( acc, accm ),HaClose) ;
SARBuy = Cross(HaClose,SAR( acc, accm )) ;




_SECTION_BEGIN("Krishna System");
R = RSI(4);
SK = StochK(9, 2);
SD = StochD(9, 2, 2);
MH = MACD(8, 21) - Signal(8, 21, 5);

//Conditions for Buying

Cond1 = ValueWhen(C,O<C);
Cond2 = R > 50;
Cond3 = SD < 80 AND SD > Ref(SD, -1);
Cond4 = MH > 0 OR (MH < 0 AND MH > Ref(MH, -1));

//Conditions for Selling

Cond5 = ValueWhen(C,O>C);
Cond6 = R < 50;
Cond7 = SD > 20 AND SD < Ref(SD, -1);
Cond8 = MH < 0 OR (MH > 0 AND MH < Ref(MH, -1));

strongBuy = Cond1 AND Cond2 AND Cond3 AND Cond4 ;
strongSell = Cond5 AND Cond6 AND Cond7 AND Cond8 ;

res= MA(HHV(H,5),-1);
sup= MA(LLV(L,5),-1);
//res=EMA(H,3);
//sup=EMA(L,3);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
kpl=IIf(avn==1,sup,res);
kpl_col=ParamColor( "Color", colorCycle );
kpl_col= IIf(avn==1,colorCustom11,colorCustom12 );
//Plot(tsl, "TAKE CARE VALUE", tsl_col, styleStaircase | styleThick);



kplBuy = MA(C,5) > tsl;
kplSell = tsL > MA(C,5) ;


SUPERBUY = TSL > SAR(ACC,ACCM) ;
SUPERSELL= TSL < SAR(ACC,ACCM);

RSIperiod = 5; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 5; //Param("HHV p",3,5,10,1);
NumLine = 1; //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", colorCustom12, styleLine);
//Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorBrightGreen, styleLine);
}
//Title = Name() + "; " + Date() + ": Support & Resistance Levels using RSI: " + /*EncodeColor(colorGreen)+ "Support Levels are Green; "+EncodeColor(colorRed)+ "Resistance Levels are Red: "+EncodeColor(colorBlack)+*/ "Num lines ="+WriteVal(numline,1) ;
/* EMA offset bands ver 1_2
I'd guess this is NOT much different to bbands except you can contol the per % offset and the periods ema to off set*/
per=.10;//Percent placement
periods=20;//time periods

/* EMA offset bands ver 1_2
I'd guess this is NOT much different to bbands except you can contol the per % offset and the periods ema to off set*/
per=.10;//Percent placement
periods=20;//time periods
/*********************************/

emaverage= EMA(C,periods);
bandsAdjust=emaverage*per;
k=1; /* multiplication factor*/
n=10; /*period*/
f=ATR(n);


R[0] = Close[0];

S[0] = C[0];
for( i = 11; i < BarCount; i++ )
{


R=R[i-1];
S=S[i-1];

if ( C[i-1] >R[i-1] )
{
r = C[i-1]+k*f[i-1];
s= C[i-1]-k*f[i-1];
}
if ( C[i-1] <S[i-1] )
{
r = C[i-1]+k*f[i-1];
s= C[i-1]-k*f[i-1];
}


FBuy=Close>R;
FSell=Close<S;



GBuy= VUP10 AND FBuy;
GSell= STRONGSELL AND doWNTREND OR FSell;

//Super TEMA by C Chulainn V1.0

n=25; Av=12; Av1=16; Av2=2; stp=2;

if (Name() == "CPTA.MI")// CAPITALIA
{ n=7; Av=18; Av1=14; Av2=2; }
else if (Name() == "BANI.MI")// BNL
{ n=29; Av=30; Av1=10; Av2=2; }
else if (Name() == "FIBK.MI")// B FIDEURAM
{ n=22; Av=15; Av1=22; Av2=2; }
else if (Name() == "FIA.MI")// FIAT
{ n=2; Av=28; Av1=10; Av2=2; }
else if (Name() == "MDBI.MI")// MEDIOBANCA
{ n=21; Av=27; Av1=29; Av2=2; }
else if (Name() == "MS.MI")// MEDIASET
{ n=30; Av=20; Av1=24; Av2=2; }
else if (Name() == "TIM.MI")// TIM
{ n=6; Av=10; Av1=20; Av2=2; }
else if (Name() == "TLIT.MI")// TELECOM IT
{ n=30; Av=25; Av1=29; Av2=3; }

n = Optimize("Periods",n,3,30,1);
av = Optimize("Average",av,10,30,1);
av1 = Optimize("Average1",av1,10,30,1);
av2 = Optimize("Average2",av2,2,5,1);
stp = Optimize("Stop",stp,4,15,1);

Var1= TEMA(Close,n);
Var2= TEMA(var1,av);
Var3= (var1-var2)+var1;
Var1= TEMA(var3,av1);
Var4= MA((var1-var2)+var1,av2);
Var5=(Var1-Var2)+Var1;

TEMASell=Cross(Var4,Var5);
TEMABuy= Cross(Var5,VAR4);

TEMASell=Cross(Var5,Ref(Var5,1));
TEMABuy=Cross(Ref(Var5,1),VAR5);
//PlotShapes(shapeUpArrow*Buy,colorCustom11, 0, L, -5 );
//PlotShapes(shapeDownArrow*Sell,colorCustom11, 0, L, -5 );

//RBuy = VOLATBUY OR kplbuy AND QBUY OR SARBUY AND QBUY OR QBUY AND STRONGBUY;
//RSell = kplsell AND QSELL OR sarsell AND QSELL OR QSELL AND STRONGSELL;



MinBars = 100;
MinBarsOK = IIf(BarCount >= MinBars, True, False);

if (MinBarsOK) { ;





_SECTION_BEGIN("BAPUR");
/* **********************************

Code to automatically identify pivots

********************************** */
// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",100,1,100,1);
nBars = Param("Number of bars", 50, 50, 1);
// -- Title.
//Title = Name() + " (" + StrLeft(FullName(), 15) + ") O: " + Open + ",
//H: " + High + ", L: " + Low + ", C: " + Close;
// -- Plot basic candle chart
//PlotOHLC(Open, High, Low, Close,
//"BIdx = " + BarIndex() +
//"\n" + "O = " + O + "\n"+"H = "+ H + "\n"+"L = " + L
//+ "\n"+"C ",
//colorWhite, 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


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

//PlotShapes(IIf(aHPivs==1, shapeDownTriangle, shapeNone), colorCustom12, 0, High, Offset=-20);
//PlotShapes(IIf(aLPivs==1, shapeUpTriangle , shapeNone), colorCustom11, 0, Low, Offset=-20);



ABuy = TSLBUY AND TRENDBUY OR TSLBUY AND GBuy OR TSLBUY AND sarbuy OR TSLBUY AND strongbuy;
ASell = TSLSELL AND TRENDSELL OR TSLSELL AND GSell OR TSLSELL AND sarsell OR TSLSELL AND strongsell ;

BBUY = TRENDBUY AND GBuy OR TRENDBUY AND KPLBUY OR TRENDBUY AND SARBUY OR TRENDBUY AND STRONGBUY;
BSELL = TRENDSELL AND GSell OR TRENDSELL AND KPLSELL OR TRENDSELL AND SARSELL OR TRENDSELL AND STRONGSELL;

CBUY = GBuy AND KPLBUY OR GBuy AND SARBUY OR GBuy AND STRONGBUY;
CSELL = GSell AND KPLSELL OR GSell AND SARSELL OR GSell AND STRONGSELL;

DBUY = KPLBUY AND SARBUY OR KPLBUY AND STRONGBUY;
DSELL = KPLSELL AND SARSELL OR KPLSELL AND STRONGSELL;

EBUY = SARBUY OR STRONGBUY;
ESELL = SARSELL OR STRONGSELL;

Cump=IIf(Close>R,1,0);
Vanz=IIf(Close<S,1,0);

HBuy = BBuy OR DBuy ;
HSell = ESELL OR TRENDSELL ;


IBUY = HBUY AND TSLBUY OR HBUY AND KPLBUY OR TRENDBUY ;
ISELL= HSELL AND GSELL OR HSELL AND SSELL;



Buy = Cover = IBUY AND TRENDBUY OR TRENDBUY OR TRENDBUY AND LOGIXBUY OR logIXBUY AND IBUY ;
Sell= Short = ISell AND LOGIXSELL OR STRONGSELL AND TRENDSELL OR logIXSELL AND TRENDSELL;


Buy = ExRem( Buy, Sell ); //Elimina semnalele buy consecutive
Sell = ExRem( Sell, Buy ); //Elimina semnalele sell consecutive

PlotShapes(shapeSmallUpTriangle *Buy ,colorCustom9,0,MaLow, -20);
PlotShapes(shapeSmallDownTriangle * Sell,colorCustom12,0,MaHigh,-20);

SellPrice=ValueWhen(Sell,H,1);
BuyPrice=ValueWhen(Buy,L,1);

Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );


//Buy = ExRem(Buy,Sell) ;
//Sell = ExRem(Sell,Buy) ;



//PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,Low,-15);
//PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorYellow, 0,High,-15);

dist = 6.00*ATR(4);
dist1 = 6.00*ATR(4);
for( i = 0; i < BarCount; i++ )
{
if( Buy )
{
PlotText( "\nSL= " + (L*0.9925), i, H[ i ]-dist, colorGreen, colorWhite );
}
if( Sell )
{
PlotText( "\nSL= " + (H*1.0075), i, L[ i ]+dist1, colorRed, colorWhite );
}
}

dist = 0.70*ATR(5);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( " BUY " + Avg[ i ], i, L[ i ]-dist, colorCustom11);
if( Sell ) PlotText( " SELL " + Avg[ i ], i, H[ i ]+dist, colorCustom12);
}

AlertIf(Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Short Triggered!", 3, 8);
AlertIf(Buy, "SOUND C:\\Windows\\Media\\Ding.wav", "Cover Triggered!", 4, 8);



//fig=Cump*shapeHollowUpArrow + Vanz*shapeHollowDownArrow;







_SECTION_BEGIN("Background text");
C11=ParamColor("up panel",colorDarkOliveGreen );
C12=ParamColor("dn panel",colorDarkGrey );
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");
GfxSetBkMode( 0 );
GfxSetOverlayMode(1);
GfxGradientRect(0,0,pxwidth, pxheight, C11, C12 );
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxTextOut( "LTP "+WriteVal(C,1.2), Status("pxwidth")/C14, Status("pxheight")/C15);
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( " SRI CHAKRA", Status("pxwidth")/C14, Status("pxheight")/C15*2 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
GfxSetTextColor(colorYellow);

}}
 
#3
Error solved..

Try this..

_SECTION_BEGIN("1 IDENTIFIER");
//Plot(Close, "Close", colorWhite, styleCandle);

Change = 3.0;





GannIncrement = 0.0625;
procedure PlotShapeAt( x, y, shape, shift )
{
PlotShapes( IIf( BarIndex() == x, shape, 0 ), colorRed, 0, y, shift );
}
procedure PlotBlueDot( x, y )
{
//PlotShapes( IIf( BarIndex() == x, shapeSmallCircle, 0 ),
//colorBlue, 0, y, 0 );

for( i = -2; i <= 2; i++ )
{
if( i != 0 )
{
yGann = ( sqrt( y ) + i * GannIncrement ) ^ 2;
// PlotShapes( IIf( BarIndex() == x, shapeSmallCircle, 0 ),
// colorOrange, 0, yGann, 0 );
}
}
}
bi = BarIndex();
sbi = SelectedValue( bi );
GraphXSpace = 2;
//Plot( Zig( C, Change ), "Zigzag", colorGreen, styleThick );
//Plot( C, "Price", IIf( bi > sbi, colorLightGrey, colorWhite ), styleBar );
upshift = 15;
if( SelectedValue( PeakBars( C, Change ) < TroughBars( C, Change ) ) )
{
pt1 = PeakBars( C, Change, 1 ) == 0 ;
pt2 = TroughBars( C, Change, 1 ) == 0 ;
}
else
{
pt1 = TroughBars( C, Change, 1 ) == 0 ;
pt2 = PeakBars( C, Change, 1 ) == 0 ;
upshift = -upshift;
}
bpt1 = SelectedValue( ValueWhen( pt1, bi ) );
bpt2 = SelectedValue( ValueWhen( pt2, bi ) );
bpt3 = SelectedValue( ValueWhen( pt1, bi, 2 ) );
bpt4 = SelectedValue( ValueWhen( pt2, bi, 2 ) );
bpt5 = SelectedValue( ValueWhen( pt1, bi, 3 ) );
bpt6 = SelectedValue( ValueWhen( pt2, bi, 3 ) );
//PlotShapeAt( bpt1, C, shapeDigit1, upshift );
//PlotShapeAt( bpt2, C, shapeDigit2, -upshift );
//PlotShapeAt( bpt3, C, shapeDigit3, upshift );
//PlotShapeAt( bpt4, C, shapeDigit4, -upshift );
//PlotShapeAt( bpt5, C, shapeDigit5, upshift );
//PlotShapeAt( bpt6, C, shapeDigit6, -upshift );
Level = SelectedValue( ValueWhen( pt1, C ) );
PlotBlueDot( round( bpt1 + 1.618 * ( bpt1 - bpt2 ) ), Level );
PlotBlueDot( round( bpt1 + 0.382 * ( bpt1 - bpt2 ) ), Level );
PlotBlueDot( round( bpt1 + 0.5 * ( bpt2 - bpt3 ) ), Level );
PlotBlueDot( round( bpt1 + 1.732 * ( bpt2 - bpt3 ) ), Level );
PlotBlueDot( round( bpt1 + 0.618 * ( bpt4 - bpt5 ) ), Level );
PlotBlueDot( round( bpt1 + 2 * ( bpt4 - bpt5 ) ), Level );
PlotBlueDot( round( bpt2 + 0.6707 * ( bpt4 - bpt2 ) ), Level );
PlotBlueDot( round( bpt2 + 2.618 * ( bpt4 - bpt2 ) ), Level );
PlotBlueDot( round( bpt2 + 1 * ( bpt6 - bpt2 ) ), Level );
PlotBlueDot( round( bpt2 + 3 * ( bpt6 - bpt2 ) ), Level );


TROUGHCover=bpt1=TroughBars(C,Change,1)==0;
PEAKShort=bpt1=PeakBars(C,Change,1)==0;






//ShortPrice=ValueWhen(Short,H,1);
//CoverPrice=ValueWhen(Cover,L,1);


MAPeriod = Param("MA Period", 6, 1, 50);
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.44);
// for graph collapse
//for (i = 0; i <= MAPeriod; i++)
// HaClose = Null;
/*
// same
// HaOpen = (Ref(HaOpen, -1) + Ref(HaClose, -1)) / 2;
HaOpen[ 0 ] = HaClose[ 0 ];
for(i = 1; i < BarCount; i++) {
HaOpen = (HaOpen[i - 1] + HaClose[i - 1]) / 2;

*/
HaHigh = Max(MAHigh, Max(HaClose, HaOpen));
HaLow = Min(MALow, Min(HaClose, HaOpen));
// outs comments
"BarIndex = " + BarIndex();
"Open = " + Open;
"High = " + High;
"Low = " + Low;
"Close = " + Close;
"HaOpen = " + HaOpen;
"HaHigh = " + HaHigh;
"HaLow = " + HaLow;
"HaClose = " + HaClose;
// Plot graphs
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} HaOpen %g, HaHigh %g, HaLow %g, HaClose %g (%.1f%%) {{VALUES}}", HaOpen, HaHigh, HaLow, HaClose, SelectedValue(ROC(HaClose, 1))));



// you can switch between Heikin-Ashi chart and regular candlestick chart

//tambahan Ku
//Hacol = IIf(Cover, colorGreen, colorRed);
//Hacol = IIf(Short, colorRed, colorGreen);

//SetBarFillColor(Hacol);

if( ParamToggle("Plot Heikin-Ashi", "No,Yes", 1 ) )
PlotOHLC( HaOpen, HaHigh, HaLow, Close, " " + Name(), IIf(C>TROUGHCover, colorBlue, colorRed), styleCandle); //colorBlue, styleCandle );
//else
//Plot( C, "Regular candles " + Name(), IIf(Cover, colorBlue, colorRed), styleCandle );
//Plot( C, "Regular Candles", IIf(Cover, colorBrightGreen, IIf(Short,colorRed, ParamStyle("Price Style",styleCandle))));


EnableTextOutput(False);
SetChartOptions(0,chartShowArrows|chartShowDates);
Title_X = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
//Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorDarkGrey), ParamColor("Title", colorTeal));
SetChartBkColor(ParamColor("Background", colorBlack));



//Indicators Used

RSI_Periods = Param("RSI Periods", 2, 10, 10, 1);
MA_Periods = Param("Periods for MAV", 50, 1, 200, 1);
Daily_Trend_MA_Pds = Param("Periods for Trend EMA", 6, 1, 100, 1);
Weekly_Trend_MA_Pds = Param("periods for Trend EMA",6,1,100,1);
Monthly_Trend_MA_Pds = Param("periods for Trend EMA",6,1,100,1);


SetBarsRequired(100000, 100000);

// Find nearest UP and DOWN bar before current bar
Up_Day = Close > Open;
Down_Day = Close < Open;
Reference_Low = ValueWhen(Up_Day, L, 1);
Reference_High = ValueWhen(Down_Day, H, 1);
Buy_Condition = C > O AND C > Reference_High;
Sell_Condition = C < O AND C < Reference_Low;
a= Buy_Condition;
b= Sell_Condition;
state=IIf(BarsSince(a)<BarsSince(b),1,0);
s=state>Ref(state,-1);
ss=state<Ref(state,-1);
sss=state==Ref(state,-1);
col=IIf(state == 1 ,51,IIf(state ==0,4,1));
Buy_Views = WriteIf(s,"EXIT ALL SHORT POSITIONS\n AND TRADE LONG WITH STOPLOSS="+EncodeColor(colorBrightGreen)+WriteVal( L,1.2)+",","");
Sell_Views = WriteIf(ss,"EXIT ALL LONG POSITIONS \n AND TRADE SHORT WITH STOPLOSS="+EncodeColor(colorRed)+WriteVal(H,1.2)+" ,","");



// RSI and Vol ratio calculation
RSI_Value = RSI(RSI_Periods);
MAV_Value = V/EMA(V, MA_Periods);

// New Formula for stock movement

//Percentage change

sDIFF=C-Ref(C,-1);
t=(sDIFF/Ref(C,-1))*100;
Percentage= t;

//Percentage Change in Volume

w = V -Ref(V,-1);
x = (w/Ref(V,-1))*100;
Volume_Ratio = x;
//Volume_Ratio = V/EMA(V,50);
//Conditions

Condition1 = Percentage > 0.5 AND Volume_Ratio > 1.5;
Condition2 = Percentage > 1 AND Volume_Ratio < -1.5;
Condition3 = Percentage < 0 AND Volume_Ratio > -1.5;
Condition4 = Percentage < 1 AND Volume_Ratio < 1.5;
Condition5 = IIf(NOT Condition1 AND NOT Condition2 AND NOT Condition3 AND NOT Condition4, True,False);


Fresh_Buying = WriteIf(Condition1,"Fresh Buying", "");
Short_Covering = WriteIf(Condition2,"Short Covering", "");
Fresh_Short_Building = WriteIf(Condition3,"Fresh Short Building", "");
Possible_Bottom = WriteIf(Condition4,"Possible Bottom OR Top", "");
No_Major_Move = WriteIf(Condition5, "No_Major_Move","");


EnableTextOutput(True);
"\nSell Below: " + WriteVal(ValueWhen(Up_Day, L, 1), 1.2);
"Buy Above : " + WriteVal(Reference_High, 1.2);
"";
"Current RSI Value: " + WriteVal(RSI_Value, 1.2);
"Current Vol. Ratio: " + WriteVal(MAV_Value, 1.2);

EnableTextOutput(False);

Filter = Buy_Condition OR Sell_Condition;


// Trading System
PositionSize = BuyPrice * 1;
logixBuy = Buy_condition;
logixSell = Sell_condition;
//Short = Sell_condition;
//Cover = Buy_condition;

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


// Experimental Code BEGIN
Is_Last_Bar = BarIndex()+1 == BarCount;
printf("Last Bar: %g\n", Is_Last_Bar);
Buy_Alert = logixBuy AND Is_Last_Bar;
Sell_Alert = logixSell AND Is_Last_Bar;
Buy_Alert_Text = WriteIf(Buy_Alert, "BUY WARNING!!!", "");
Sell_Alert_Text = WriteIf(Sell_Alert, "SELL WARNING!!!", "");
Buy_Alert_Text1 = WriteIf(Buy_Alert, "BUY", "");
Sell_Alert_Text1 = WriteIf(Sell_Alert, "SELL", "");
LastbarsignalCol = IIf(Buy_Alert, colorGreen, IIf(Sell_Alert, colorRed, colorLightGrey));


//Buy & Sell Arrows Signal

//PlotShapes(shapeUpArrow * Buy * (NOT Is_Last_Bar), colorBrightGreen, 0, L, -15);
//PlotShapes(shapeHollowUpArrow * Cover, colorBrightGreen, 0, L, -30);
//PlotShapes(shapeDownArrow * Sell * (NOT Is_Last_Bar), colorRed, 0, H, -15);
//PlotShapes(shapeHollowDownArrow * Short, colorRed, 0, H, -30);
PlotShapes(shapeCircle * Buy_Alert, colorCustom11, 0, L, 5);
PlotShapes(shapeCircle * Sell_Alert, colorOrange, 0, H, 15);




// Check if previous day's close is above its 6-day EMA
DailyClose = TimeFrameCompress(Close, inDaily);
DailyEMA = EMA( DailyClose, Daily_Trend_MA_Pds);
DailyClose = TimeFrameExpand(DailyClose, inDaily, expandFirst);
DailyEma = TimeFrameExpand(DailyEMA, inDaily, expandFirst);

// Trend detection based on 6EMA for Daily
Daily_Trend_UP = DailyClose > DailyEMA;
Daily_Trend_DOWN = DailyClose < DailyEMA;
Trend_UP_Text = WriteIf(Daily_Trend_UP, "Daily Trend UP", "");
Trend_DOWN_Text = WriteIf(Daily_Trend_DOWN, "Daily Trend DOWN", "");
Trend_Neutral_Text = WriteIf(NOT Daily_Trend_DOWN AND NOT Daily_Trend_UP, "Neutral", "");
TrendCol = IIf(Daily_Trend_UP, colorGreen, IIf(Daily_Trend_DOWN, colorRed, colorLightGrey));

// Check if previous Week's Close is above its 6-Weeks EMA
WeeklyClose = TimeFrameCompress(Close, inWeekly);
weeklyEMA = EMA( weeklyClose, Weekly_Trend_MA_Pds);
weeklyClose = TimeFrameExpand(WeeklyClose, inWeekly, expandFirst);
WeeklyEMA = TimeFrameExpand(weeklyEMA, inWeekly, expandFirst);


// Trend detection based on 6EMA for weekly
Weekly_Trend_UP = WeeklyClose > WeeklyEMA;
Weekly_Trend_DOWN = WeeklyClose < WeeklyEMA;
Weekly_Trend_UP_Text = WriteIf(Weekly_Trend_UP, "Weekly Trend UP", "");
Weekly_Trend_DOWN_Text = WriteIf(Weekly_Trend_DOWN, "Weekly Trend DOWN", "");
Wekly_Trend_Neutral_Text = WriteIf(NOT Weekly_Trend_DOWN AND NOT Weekly_Trend_UP, "Neutral", "");
TrendCol = IIf(Weekly_Trend_UP, colorGreen, IIf(Weekly_Trend_DOWN, colorRed, colorLightGrey));

// Check if previous Month's Close is above its 6-Months EMA
MonthlyClose = TimeFrameCompress(Close, inMonthly);
MonthlyEMA = EMA( MonthlyClose, Monthly_Trend_MA_Pds);
MonthlyClose = TimeFrameExpand(MonthlyClose, inMonthly, expandFirst);
MonthlyEMA = TimeFrameExpand(MonthlyEMA, inMonthly, expandFirst);

/** Debug BEGIN */
printf("\nDaily Close: %g ", DailyClose);
printf("\nDaily Trend: %g", (DailyEMA));
printf("\nWeekly Trend: %g", (WeeklyEMA));
printf("\nMonthly Trend: %g", (MonthlyEMA));
/* Debug END ****/

// Trend detection based on 6EMA for Monthly
Monthly_Trend_Up = MonthlyClose > MonthlyEMA;
Monthly_Trend_DOWN = MonthlyClose < MonthlyEMA;
Monthly_Trend_UP_Text = WriteIf(Monthly_Trend_UP, "Monthly Trend UP", "");
Monthly_Trend_DOWN_Text = WriteIf(Monthly_Trend_DOWN, "Monthly Trend DOWN", "");
Monthly_Trend_Neutral_Text = WriteIf(NOT Monthly_Trend_DOWN AND NOT Monthly_Trend_UP, "Neutral", "");
TrendCol = IIf(Monthly_Trend_UP, colorGreen, IIf(Monthly_Trend_DOWN, colorRed, colorLightGrey));





//Inerpretation
Title = Title_X + "\n" +

EncodeColor(colorBlack) + "RSI(" + WriteVal(RSI_Periods, 1) + "): " +
EncodeColor(colorBrightGreen) + WriteVal(RSI_Value, 1.2) + "\n" +
EncodeColor(colorBlack) + "Vol. Ratio: " + EncodeColor(colorDarkGreen) + WriteVal(MAV_Value, 1.2) + "\n" +
EncodeColor(colorRed) + Trend_Down_Text + EncodeColor(colorBrightGreen) + Trend_Up_Text +
EncodeColor(colorWhite) + Trend_Neutral_Text + "\n" +
EncodeColor(colorRed) + Weekly_Trend_Down_Text + EncodeColor(colorBrightGreen) + Weekly_Trend_Up_Text + "\n" +
EncodeColor(colorRed) + Monthly_Trend_Down_Text + EncodeColor(colorBrightGreen) + Monthly_Trend_Up_Text + "\n" +
EncodeColor(colorRed) + Sell_Alert_Text + EncodeColor(colorBrightGreen) + Buy_Alert_Text + "\n" +
EncodeColor(colorRed) + Fresh_Short_Building + EncodeColor(colorBrightGreen) + Fresh_Buying + EncodeColor(colorWhite) + Short_Covering + EncodeColor(colorWhite) + Possible_Bottom +"\n" +
EncodeColor(colorBrightGreen)+ "Buy Above : " + WriteVal(Reference_High, 1.2)+ "\n" +
EncodeColor(colorCustom5) + "Sell Below: " + WriteVal(ValueWhen(Up_Day, L, 1), 1.2) + "\n" +
EncodeColor(colorCustom12) + "Trend value: " + WriteVal(DailyEMA,1) +"\n"+
EncodeColor(colorBlue)+ Buy_Views + EncodeColor(colorBlue)+ Sell_Views;




//Average, Volitility & Percentage Scale.
av0=V/EMA(V,3);
av1=V/EMA(V,5);
av2=V/EMA(V,13);
av3=V/EMA(V,50);
av4=V/EMA(V,200);
V1= MA(V,50);
r = RSI(2);
s=C-Ref(C,-1);
t=(s/Ref(C,-1))*100;
p=H-L;
ZZ=(p/Ref(C,-1))*100;


//MRam Povit for Daily, Weekly & Monthly

k=IIf(ParamList("select type","daily|next day")=="daily",-1,0);
k1=-1;
TimeFrameSet(inDaily);
day_h= LastValue(Ref(H,K));
day_l= LastValue(Ref(L,K));
day_c= LastValue(Ref(C,K));
TimeFrameRestore();

TimeFrameSet(inWeekly);
Week_h= LastValue(Ref(H,K1));
Week_l= LastValue(Ref(L,K1));;
Week_c= LastValue(Ref(C,K1));;
TimeFrameRestore();

TimeFrameSet(inMonthly);
month_h= LastValue(Ref(H,K1));
month_l= LastValue(Ref(L,K1));
month_c= LastValue(Ref(C,K1));
TimeFrameRestore();

/*--------------------------------------*/
// day
DH=Day_h;
DL=Day_L;
DC=Day_C;

// DAY PIVOT Calculation
pd = ( DC + DC-6 )/2;
sd1 = DC - (DH - DL)/2;
sd2 = DC - (DH - DL);

rd1 = DC + (DH - DL)/2;
rd2 = DC +(DH -DL);

Plot(pd, "PP",colorYellow,styleLine+styleNoLine);
Plot(rd1, "R1",colorBlue,styleLine+styleNoLine);
Plot(Sd1, "S1",colorRed,styleLine+styleNoLine);
Plot(Rd2, "R2",colorBlue,styleLine+styleNoLine);
Plot(Sd2, "S2",colorRed,styleLine+styleNoLine);

// week
WH=Week_h;
WL=Week_l;
WC=Week_c;

// WEEK PIVOT Calculation
pw = ( WC+ WC -6 )/2;
sw1 = WC - (WH - WL )/2;
sw2 = WC -(WH - WL);

rw1 = WC + (WH - WL)/2;
rw2 = WC +(WH -WL);

// month
MH=month_h;
ML=month_l;
MC=month_c;

// MONTH PIVOT Calculation
pm = ( MC + MC - 6 )/2;
sm1 = MC - ( MH - ML )/2;
sm2 = MC -(MH - ML);

rm1 = MC + (MH - ML)/2;
rm2 = MC +(MH -ML);

//stochbuy = Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() > Signal()AND Cross(myStochK, myStochD) AND V>50000;
//stochsell= Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() < Signal()AND Cross(myStochK, myStochD) AND V>50000;

//Filter = Buy AND C>=10 AND V >50000 OR Buy_Alert AND C>=10 AND V >50000 OR Sell AND C>=10 AND V >50000 OR Sell_Alert AND C>=10 AND V >50000;


_SECTION_BEGIN("VELVOORT HEIKIN CANDLE SAR THREE");
//AFL Heikin Ashi

HaClose = (H+L+C)/3;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );

// Velvoort is using not original, but modified Heikin-Ashi close
HaClose = ( HaClose + HaOpen + HaHigh + HaLow )/4;


_SECTION_BEGIN("Price");
//SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
//Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


// you can switch between Heikin-Ashi chart and regular candlestick chart

//tambahan Ku
//Hacol = IIf(HaClose>HaOpen, colorGreen, colorDarkRed);
//SetBarFillColor(Hacol);

//if( ParamToggle("Plot Heikin-Ashi", "No,Yes", 1 ) )
//PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, " " + Name(), IIf(HaClose>HaOpen, colorBlue, colorRed), styleCandle); //colorBlue, styleCandle );
//else
//Plot( C, "Regular candles " + Name(), IIf(Close>Open, colorBlue, colorRed), styleCandle );



_SECTION_BEGIN("Background");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("Outer panel",colorBlack)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack));
tchoice=Param("Title Selection ",2,1,2,1);

//Plot(C, "", IIf(C>=O, colorGreen, colorGreen), ParamStyle("Price Style",styleCandle,maskPrice));
//////////////////////////////////////////////////////////////////
_SECTION_BEGIN("Fib Retracements");
fibs = ParamToggle("Plot Fibs","Off|On",1);
pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
Back = Param ("Extend Left = 2",1,1,500,1);
Fwd = Param("Plot Forward", 0, 0, 500, 1);
//Text = ParamToggle("Plot Text","Off|On",1);
hts = Param ("Text Shift", -33.5,-50,50,0.10);
style =ParamStyle("Line Style",styleLine,styleNoLabel);
x = BarIndex();
pRp = PeakBars( H, pctH, 1) == 0;
yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
pSp = TroughBars( L, pctL, 1) == 0;
ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
Delta = yRp0 - ySp0;

function fib(ret)
{
retval = (Delta * ret);
Fibval = IIf(ret < 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0
AND xSp0 > xRp0, ySp0 + retval, Null))));
return FibVal;
}

x0 = Min(xSp0,xRp0)-Back;
x1 = (BarCount -1);
//////////////////////////////////////////////////////////////////
r236 = fib(0.236); r236I = LastValue (r236,1);
r382 = fib(0.382); r382I = LastValue (r382,1);
r050 = fib(0.50); r050I = LastValue (r050,1);
r618 = fib(0.618); r618I = LastValue (r618,1);
r786 = fib(0.786); r786I = LastValue (r786,1);
e127 = fib(1.27); e127I = LastValue (e127,1);
e162 = fib(1.62); e162I = LastValue (e162,1);
e200 = fib(2.00); e200I = LastValue (e200,1);
e262 = fib(2.62); e262I = LastValue (e262,1);
e424 = fib(4.24); e424I = LastValue (e424,1);
//////////////////////////////////////////////////////////////////
p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
//////////////////////////////////////////////////////////////////
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
//////////////////////////////////////////////////////////////////
if(fibs==1)
{
Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale, Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale, Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale, Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale, Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale, Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoResc ale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoResc ale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoResc ale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoResc ale,Null, Null,Fwd);
//Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoResc ale,Null, Null,Fwd);
}
//////////////////////////////////////////////////////////////////
//if(Text==1)
{
PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00);
//PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
//PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
//PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
//PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
//PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
//PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
//PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
//PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
//PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
//PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
//PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
}
_SECTION_END();
//////////////////////////////////////////////////////////////////
if (tchoice==1 )
{
_N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} - {{INTERVAL}} {{DATE}} Open: %g, High: %g, Low: %g, Close: %g {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
}
//////////////////////////////////////////////////////////////////
if (tchoice==2 )
{
Title = EncodeColor(colorWhite)+ Date() + " Tick = " + EncodeColor(5) + Interval()+
EncodeColor(colorWhite) + " Open = " + EncodeColor(colorWhite) + O +
EncodeColor(colorWhite) + " High = " + EncodeColor(5) + H +
EncodeColor(colorWhite) + " Low = " + EncodeColor(colorRed) + L +
EncodeColor(colorWhite) + " Close = " + EncodeColor(colorWhite) + C + "\n" +
EncodeColor( colorWhite) +"_______________"+"\n"+
EncodeColor( colorWhite) + "424% = " + EncodeColor(25)+ e424 + " " +"\n"+
EncodeColor( colorWhite) + "262% = " + EncodeColor(47)+ e262 + " " +"\n"+
EncodeColor( colorWhite) + "200% = " + EncodeColor(47)+ e200 + " " +"\n"+
EncodeColor( colorWhite) + "162% = " + EncodeColor(47)+ e162 + " " +"\n"+
EncodeColor( colorWhite) + "127% = " + EncodeColor(47)+ e127 + " " +"\n"+
EncodeColor( colorYellow) + " Res OR Sup = " + EncodeColor(32)+ p100 + " " +"\n"+
EncodeColor( colorWhite) + " 78% = " + EncodeColor(42)+ r786 + " " +"\n"+
EncodeColor( colorWhite) + " 62% = " + EncodeColor(43)+ r618 + " " +"\n"+
EncodeColor( colorWhite) + " 50% = " + EncodeColor(41)+ r050 + " " +"\n"+
EncodeColor( colorWhite) + " 38% = " + EncodeColor(44)+ r382 + " " +"\n"+
EncodeColor( colorWhite) + " 23% = " + EncodeColor(45)+ r236+ " " +"\n"+
EncodeColor( colorYellow) + " Sup OR Res = " + EncodeColor(34)+ p00 + " " ;
}
GraphXSpace=5;







_SECTION_BEGIN("Peak");
//Peak-Trough System + Auto ATR + Position sizing+Varible Sensitivity//
// Last Update 16 Oct 05 By Kook//

PctVlt=(ATR(14)/C)*100;//PercentVolatility

PK=IIf(PctVlt<0.5,Peak(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Peak(Close,0.70,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Peak(Close,0.90,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Peak(Close,1.10,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Peak(Close,1.30,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Peak(Close,1.50,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Peak(Close,1.70,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Peak(Close,2.00,1),
Peak(Close,2.20,1) ))))))));

TGH=IIf(PctVlt<0.5,Trough(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Trough(Close,0.75,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Trough(Close,1.00,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Trough(Close,1.25,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Trough(Close,1.50,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Trough(Close,1.75,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Trough(Close,2.00,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Trough(Close,2.25,1),
Trough(Close,2.50,1) ))))))));

Sens=IIf(PctVlt<0.5,0.5,
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,0.75,
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,1.00,
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,1.25,
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,1.50,
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,1.75,
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,2.00,
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,2.25,
2.50 ))))))));

Color=IIf(BarsSince(Cross(C,Ref(PK,-1)))<BarsSince(Cross(Ref(TGH,-1),C)),colorBrightGreen,colorRed);

//Plot(C,"C",Color,styleCandle);
//PlotShapes( Cross(C,Ref(PK,-1))*shapeUpArrow,colorYellow,0,L);
//PlotShapes( Cross(Ref(TGH,-1),C)*shapeDownArrow,colorPink,0,H);
//PlotShapes( Cross(84,RSI(36))*shapeDownArrow,colorYellow,0,H,O ffset=-28 );
//PlotShapes( Cross(67.4,RSI(171))*shapeDownArrow,colorYellow,0, H,Offset=-28 );
//PlotShapes( Cross(27,RSI(95))*shapeUpArrow,colorYellow,0,L,Off set=-28 );

//PlotShapes( Cross(95.9,StochD(4200))*shapeDownArrow,colorCusto m12,0,H,Offset=-28 );
//PlotShapes( Cross(0.50,StochD(4200))*shapeUpArrow,colorCustom1 2,0,H,Offset=-28 );

Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
TT= RSIa(C,130);
StartBar = ValueWhen(TimeNum() == 093000, BarIndex());
TodayVolume = Sum(TT,Bars_so_far_today);
IIf (BarIndex() >= StartBar, VWAP = Sum (C * TT, Bars_so_far_today ) / TodayVolume,0);
//Plot (VWAP,"VWAP",colorCustom11,4 +8+2048 );


clDay1 = (TimeFrameGetPrice("c",inDaily,-1));
clDay2 = (TimeFrameGetPrice("c",inDaily,-2));
clDay3 = (TimeFrameGetPrice("c",inDaily,-3));
clDay4 = (TimeFrameGetPrice("c",inDaily,-4));
clDay5 = (TimeFrameGetPrice("c",inDaily,-5));




stoploss = (clDay1+clDay2+clDay3+clDay4 +clDay5)/5;


//Plot( (stoploss ),"3",colorBrown,4 +8+2048 );

Buyabv=stoploss+31;

//Plot( (Buyabv ),"3",colorGreen,4 +8+2048 );

Sellbel=stoploss-31;
//Plot( (Sellbel ),"3",colorRed,4 +8+2048 );


Pivot = ParamToggle("Pivot_day", "No|Yes", 1);

if(Pivot)
{
H1 = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
L1 = TimeFrameGetPrice("L", inDaily, -1); // low
C1= TimeFrameGetPrice("C", inDaily, -1); // close
Op = TimeFrameGetPrice("O", inDaily)-1; // current day open

}
else
{
H1 = TimeFrameGetPrice("H", inDaily); // yesterdays high
L1 = TimeFrameGetPrice("L", inDaily); // low
C1= TimeFrameGetPrice("C", inDaily);
Op = TimeFrameGetPrice("O", inDaily); // current day open

}




// PIVOT Calculation
P = ( H1+ L1 +L1 + C1 )/4;
S1 = p-(H1-P);
R1 = (P-L1)+P;
S2 = P -(H1 - L1);
S3 = S1 - (H1-L1);
S4 = S2 - (H1-L1);
S5 = S3 - (H1-L1);
S6 = S4 - (H1-L1);
S7 = S5 - (H1-L1);
S8 = S6 - (H1-L1);
S9 = S7 - (H1-L1);
S10 = S8 - (H1-L1);

R2 = P +(H1 - L1);
R3 = R1 +(H1-L1);
R4 = R2 +(H1-L1);
R5 = R3 +(H1-L1);
R6 = R4 +(H1-L1);
R7 = R5 +(H1-L1);
R8 = R6 +(H1-L1);
R9 = R7 +(H1-L1);
R10 = R8 +(H1-L1);
Ho=(H1-Op)+OP;
Ol=(Op-L1)+OP;

X=( H1+ L1 +L1 + C1 );

TDU=(X/2)-L1;
TDL=(X/2)-H1;

//Plot(round(TDU), "",colorOrange,4+8+2048);

//Plot(round(TDL), "",colorGreen,4+8+2048);

_SECTION_BEGIN("RSI BUY SELL");
per1=Param ("per1", 5.0,0.5,100,0.9);

per=per1;

n=55;

x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa (C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSIa(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(ValueWhen( (S1==trendlineS ), L),"", colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((S11==trendlineR ), H),"", colorRed, styleDashed|styleNoRescale|styleThick);
Cover2 = (S1==trendlineS );
Short2 = (S11==trendlineR );


_SECTION_BEGIN("RSI BUY SELL");
n=55;
per = 5;
x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa (C,n),RSIa(O,n)),RSIa(L,n));

pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(ValueWhen( (S1==trendlineS ), L),"", colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((S11==trendlineR ), H),"", colorRed, styleDashed|styleNoRescale|styleThick);
Cover1 = (S1==trendlineS );
Short1 = (S11==trendlineR );

SBuy = TROUGHCover OR Cover1 OR Cover2;

SSell= PEAKShort OR Short1 OR Short2;





{


/*
Heikin-Ashi(Koma-Ashi) with Moving Average Type
*/
SetChartOptions(2, chartWrapTitle);
// Calculate Moving Average
MAPeriod = Param("MA Period", 6, 1, 50);
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.44);
// for graph collapse
for (i = 0; i <= MAPeriod; i++)
HaClose = Null;
/*
// same
// HaOpen = (Ref(HaOpen, -1) + Ref(HaClose, -1)) / 2;
HaOpen[ 0 ] = HaClose[ 0 ];
for(i = 1; i < BarCount; i++) {
HaOpen = (HaOpen[i - 1] + HaClose[i - 1]) / 2;

*/
HaHigh = Max(MAHigh, Max(HaClose, HaOpen));
HaLow = Min(MALow, Min(HaClose, HaOpen));
// outs comments
"BarIndex = " + BarIndex();
"Open = " + Open;
"High = " + High;
"Low = " + Low;
"Close = " + Close;
"HaOpen = " + HaOpen;
"HaHigh = " + HaHigh;
"HaLow = " + HaLow;
"HaClose = " + HaClose;
// Plot graphs
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} HaOpen %g, HaHigh %g, HaLow %g, HaClose %g (%.1f%%) {{VALUES}}", HaOpen, HaHigh, HaLow, HaClose, SelectedValue(ROC(HaClose, 1))));

//PlotOHLC(MaOpen, MaHigh, MaLow, MaClose, _DEFAULT_NAME(), ParamColor("Color", colorBlack), styleCandle);

//bestbuy = Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() > Signal()AND Cross(myStochK, myStochD) AND V>50000 OR Buy AND C>=10 AND V >50000 AND MACD() > Signal()AND Cross(myStochK, myStochD) OR Buy_Alert AND C>=10 AND V >50000 AND MACD() > Signal()AND Cross(myStochK, myStochD);

//bestsell= Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() < Signal()AND Cross(myStochK, myStochD) AND V>10000 OR Sell AND C>=10 AND V >50000 AND MACD() < Signal()AND Cross(myStochK, myStochD) OR Sell_Alert AND C>=10 AND V >50000 AND MACD() < Signal()AND Cross(myStochK, myStochD);

//PlotShapes(IIf( bestSell, shapeDownArrow, shapeNone), colorYellow, 0, High, Offset= 10);
//PlotShapes(IIf( bestBuy , shapeUpArrow , shapeNone), colorYellow, 0, Low, Offset= -10);

//Fractals
nbar = Param("Longer Term",21,2,10000,1);

PHigh = HaHigh > Ref(HHV(HaHigh,nbar),-1) AND Ref(HHV(HaHigh,nbar),nbar) <= HaHigh;
PHighPrice = ValueWhen(PHigh,HaHigh);
PLow = HaLow < Ref(LLV(L,nbar),-1) AND Ref(LLV(HaLow,nbar),nbar) >= HaLow;
PLowPrice = ValueWhen(PLow,HaLow);

//Plot(PLowPrice, "Fractal Low", colorCustom11, styleDots | styleLine);
//Plot(PHighPrice, "Fractal High", colorCustom12, styleDots | styleLine);

//Plot(MA(Close,3),"",colorCustom11, styleLine);
//Plot(MA(HaCLOSE,5),"",colorRed, styleLine);
no= 10 ;
res= EMA(HaHigh,6);
Avg= EMA( HaClose, 6 ) ;
sup= EMA(HaLow,6);
avd=IIf( HaClose>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
supres= IIf(avn==1,sup,res) ;
//Plot(supres," MOBILE: +91-9367151067(India) STOP LOSS ",colorYellow,styleStaircase,0,0,0);

// Plot(EMA(HaClose,18),"",colorCustom12, styleLine);
//_N(Title = "{{NAME}} - {{INTERVAL}} {{DATE}}: "+" : {{OHLCX}} " +EncodeColor( colorRed) +" V "+WriteVal(V, 1));

//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} \nOpen %1.2f, Hi %1.2f, Lo %1.2f, Close %1.2f (%.1f%%) Vol " + WriteVal( V, 1.0 ) + // " {{VALUES}} " +

//"\nEMA-1: " + WriteVal(EMA(C, 1), 1.2) + EncodeColor(colorWhite) +
//"\nEMA-2: " + WriteVal(EMA(C, 2), 1.2) + EncodeColor(colorCustom11) +
//"\nEMA-3: " + WriteVal(EMA(C, 3), 1.2) + EncodeColor(colorCustom9) +
//"\nEMA-6 H: " + WriteVal(EMA(H, 6), 1.2) + EncodeColor(colorCustom12) +
//"\nEMA-6 L: " + WriteVal(EMA(L, 6), 1.2) + EncodeColor(colorOrange) +
//"\nEMA-13: " + WriteVal(EMA(C, 13), 1.2) + EncodeColor(colorDarkOliveGreen) +
//"\nEMA-50: " + WriteVal(EMA(C, 50), 1.2) + EncodeColor(colorGold) +
//"\nEMA-100: " + WriteVal(EMA(C, 100), 1.2) + EncodeColor(colorBrown) +
//"\nEMA-150: " + WriteVal(EMA(C, 150), 1.2) + EncodeColor(colorRed) +
//O,H,L,C ));
_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI() AND MACD()>Signal();
downtrend=MDI()>PDI() AND Signal()>MACD();
//Plot( 2, /* defines the height of the ribbon in percent of pane width */"",
// IIf( uptrend AND EMA(C,50)>=Ref(EMA(C,50),-1), colorLime, IIf( downtrend OR EMA(C,50)<Ref(EMA(C,50),-1),
// colorRed, colorTan)) , /* choose color */styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

//TREND ADVISER

pointer[0] = 0;

/* Phase filter */

Cond1 = Close > MA(Close, 50)AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
Cond2 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND NOT(MA(Close, 50) > MA(Close, 200));
Cond3 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond4 = NOT(Close > MA(Close, 50))AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond5 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND MA(Close, 50) > MA(Close, 200);
Cond6 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));


for (i = 1; i < BarCount; i++)
{

if (Cond1)
pointer = 1;
if (Cond2)
pointer = 2;
if (Cond3)
pointer = 3;
if (Cond4)
pointer = 4;
if (Cond5)
pointer = 5;
if (Cond6)
pointer = 6;

}

/* Plot Graphic */
//GraphXSpace= 15 ;
dynamic_color = IIf(pointer < 4, colorGreen, colorRed);
//Plot(pointer, "TrendAdv2", dynamic_color, styleHistogram | styleThick, Null, Null, 0);
//SetChartBkGradientFill(ParamColor("BgTop", colorWhite), ParamColor("BgBottom", colorLightYellow));
Cond= pointer < 4 ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx






/* my entry is very simple(daily data for trading)

kpl system for entry only & exit as follow:

1 st exit at x % from entry price only 1/3 quantity.(ie 1st profit target)
2 nd exit when exit Signal comes from kpl sys remaining 1/3 quantity.
3. scale-in to initial quantity if new kpl Buy Signal comes.
re-do above scaling-out & scaling-in till filal exit.
4. final exit all quantity when Close below 21 Day EMA.

kpl system code bellow :
*/
//AFL by Kamalesh Langote. Email:kpl@...
noR =Param( "SwingR", 6, 1, 55 ) ;
noS =Param( "SwingS", 3, 1, 55 ) ;
res=HHV(H,noR);
sup=LLV(L,noS);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);
//tsl_col=ParamColor( "Color", colorCycle );
tsl_col= IIf(avn==1,colorCustom11,colorRed );
//Plot(tsl, "KPL", tsl_col, styleLine | styleThick);
kplBuy = C > Ref(res,-1);
kplSell = Ref(sup,-1) > C ;
//shape=kplBuy*shapeUpArrow + kplSell*shapeDownArrow;
//PlotShapes(shape,IIf(kplBuy,colorBrightGreen,color Red),0,IIf(kplBuy,Low,High));
SetPositionSize(300,spsShares);
ApplyStop(0,1,10,1);

//Buy = SBUY OR kplbuy;
//Sell= SSELL OR kplsell;


//Plot( Flip( Buy, Sell ), "", colorDarkGreen, styleArea | styleOwnScale, 100, 10 );
//Plot( Flip( Sell, Buy ), "", colorDarkRed, styleArea | styleOwnScale, 100, 10);




//shape=Cover*shapeUpTriangle + Short*shapeDownTriangle;
//PlotShapes(shape,IIf(Cover,colorGreen,colorCustom1 2),0,IIf(Cover,HaLow,HaHigh));



//Buy=ExRem(Buy,Sell);
//Sell=ExRem(Sell,Buy);



//dist = 0.3*ATR(5);
//for( i = 0; i < BarCount; i++ )
//{
//if( Buy ) PlotText( " BUY " + L[ i ], i, L[ i ]-dist, colorCustom11);
//if( Sell ) PlotText( " SELL " + H[ i ], i, H[ i ]+dist, colorCustom12);
//}





_SECTION_BEGIN("BW Fractal");

/* UpFractal= ValueWhen( */
SellFractal= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2));

/* DownFractal= ValueWhen( */
BuyFractal= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2));


NewSellFractal=(Ref(SellFractal,2) > Ref(SellFractal,1) OR Ref(SellFractal,2) < Ref(SellFractal,1));
NewBuyFractal=(Ref(BuyFractal,2) > Ref(BuyFractal,1) OR Ref(BuyFractal,2) < Ref(BuyFractal,1) );

//== Added Crash crashandburn59 [at] hotmail.com solution
//Plot(Ref(SellFractal,2), "Sell Fractal", ParamColor("Sell Fractal Color",colorRed), ParamStyle("Sell Fractal Style", styleDashed));
//Plot(Ref(BuyFractal,2), "Buy Fractal",ParamColor("Buy Fractal Color",colorBlue), ParamStyle("Buy Fractal Style", styleDashed));

//PlotShapes(IIf(NewSellFractal,shapeDownArrow,shape None),colorRed,0,High,Offset=-12);
//PlotShapes(IIf(NewBuyFractal,shapeUpArrow,shapeNon e),colorBlue,0,Low,Offset=-12);


//Plot(Max(HHV(H,3),Ref(UpFractal,2)), "Up Fractal", ParamColor("Up Fractal Color",colorRed), ParamStyle("Up Fractal Style", styleDashed));
//Plot(Max(HHV(H,3),Ref(UpFractal,2)), "Down Fractal",ParamColor("Down Fractal Color",colorBlue), ParamStyle("Down Fractal Style", styleDashed));

_SECTION_END();



//Sell=ExRem(Sell,Buy);
//Buy=ExRem(Buy,Sell);



//Filter = 1; /* all symbols and quotes accepted */
//filer = Buy OR Sell ;
/*DOJI definitions*/

/*Doji Today - (DT)*/

smallBodyMaximum=0.0025;//less than 0.25%

DT = abs(C-O) <= (C*smallBodyMaximum) OR (abs(O-C)<=((H-L)*0.1));

/* Doji Yesterday - (DY)*/
DY = abs(Ref ( C, -1)-Ref(O,-1)) <= Ref ( C, -1) *smallBodyMaximum OR abs (Ref ( O, -1)-Ref(C,-1)) <= (Ref ( H, -1 ) - Ref ( L, -1 ) )*0.1;




}

SetChartOptions(0,chartShowArrows|chartShowDates);

//_N(Title = "{{NAME}} - {{INTERVAL}} {{DATE}}: "+" : {{OHLCX}} " +EncodeColor( colorRed) +" V "+WriteVal(V, 1)+ EncodeColor(colorWhite) );

_SECTION_END();

SwingTrd1 = 100 * (Close - ((MA(C,2)+
MA(MA(C,2),2)+
MA(MA(MA(C,2),2),2) +
MA(MA(MA(MA(C,2),2),2),2) +
MA(MA(MA(MA(MA(C,2),2),2),2),2) +
MA(MA(MA(MA(MA(MA(C,2),2),2),2),2),2) +
MA(MA(MA(MA(MA(MA(MA(C,2),2),2),2),2),2),2)+
MA(MA(MA(MA(MA(MA(MA(MA(C,2),2),2),2),2),2),2),2)+
MA(MA(MA(MA(MA(MA(MA(MA(MA(C,2),2),2),2),2),2),2), 2),2)+
MA(MA(MA(MA(MA(MA(MA(MA(MA(MA(C,2),2),2),2),2),2), 2),2),2),2))/10))/(HHV(C,10)-LLV(C,10));
SwingTrd2=EMA(SwingTrd1,30);
SwingTrd3=EMA(SwingTrd2,30);
RMO= EMA(SwingTrd1,81);
RMOBuy=Cross(SwingTrd2,SwingTrd3);
RMOSell=Cross(SwingTrd3,SwingTrd2);
Bull_Trend=EMA(SwingTrd1,81)>0;
Bear_Trend=EMA(SwingTrd1,81)<0;
Ribbon_kol=IIf(Bull_Trend,colorGreen, IIf(Bear_Trend,colorRed, colorBlack));
//Plot(4, "ribbon", Ribbon_kol, styleOwnScale|styleArea|styleNoLabel, -0.5,100);
Impulse_UP= EMA(SwingTrd1,30) > 0;
Impulse_Down= EMA(SwingTrd1,81) < 0;
bar_kol=IIf(TROUGHCover, colorBlue, IIf(PEAKShort, colorRed,IIf(impulse_down,colorRed, colorBlue)));
//Plot(Close,"Close",bar_kol,styleCandle | styleThick );
//shape = Buy * shapeUpArrow + Sell * shapeDownArrow;



//bestbuy = Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() > Signal()AND Cross(myStochK, myStochD) AND V>50000 OR Buy AND C>=10 AND V >50000 AND MACD() > Signal()AND Cross(myStochK, myStochD) OR Buy_Alert AND C>=10 AND V >50000 AND MACD() > Signal()AND Cross(myStochK, myStochD);

//bestsell= Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() < Signal()AND Cross(myStochK, myStochD) AND V>10000 OR Sell AND C>=10 AND V >50000 AND MACD() < Signal()AND Cross(myStochK, myStochD) OR Sell_Alert AND C>=10 AND V >50000 AND MACD() < Signal()AND Cross(myStochK, myStochD);

//PlotShapes(IIf( bestSell, shapeDownArrow, shapeNone), colorYellow, 0, High, Offset= 10);
//PlotShapes(IIf( bestBuy , shapeUpArrow , shapeNone), colorYellow, 0, Low, Offset= -10);




//stochbuy = Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() > Signal()AND Cross(myStochK, myStochD) AND V>50000;
//stochsell= Cross(EMA(C,5),EMA(C,12)) AND C>=10 AND MACD() < Signal()AND Cross(myStochK, myStochD) AND V>50000;

//Filter = Buy AND C>=10 AND V >50000 OR Buy_Alert AND C>=10 AND V >50000 OR Sell AND C>=10 AND V >50000 OR Sell_Alert AND C>=10 AND V >50000;



_SECTION_BEGIN("MACD Exploration");
r1 = Param( "Fast avg", 15, 2, 200, 1 );
r2 = Param( "Slow avg", 30, 2, 200, 1 );
r3 = Param( "Signal avg", 12, 2, 200, 1 );
Z=Param("zig",1,0,10,0.1);
Cond1 = Cross(MACD(r1,r2),Signal(r1,r2,r3));

EMA34 = EMA(C,10);
LSMA = LinearReg(C,25);
//LSMA = LinearReg(C,20);

//Uncomment for lsma.
//Plot(LSMA,"LSMA 25", colorLightBlue, styleLine | styleNoLabel | styleThick);

PI = atan(1.00) * 4;
periods = 30;
HighHigh = HHV(H, periods);
LowLow = LLV(L, periods);
range = 25 / (HighHigh - LowLow) * LowLow;

x1_EMA34 = 0;
x2_EMA34 = 2;
y1_EMA34 = 0;
y2_EMA34 = (Ref(EMA34, -2) - EMA34) / Avg * range;

c_EMA34 = sqrt((x2_EMA34 - x1_EMA34)*(x2_EMA34 - x1_EMA34) + (y2_EMA34 - y1_EMA34)*(y2_EMA34 - y1_EMA34));
angle_EMA34 = round(180 * acos((x2_EMA34 - x1_EMA34)/c_EMA34) / PI);

TitleAngleEMA34 = EncodeColor(colorWhite) + "\nEMA34 angle = ";

angle_EMA34 = IIf(y2_EMA34 > 0, - angle_EMA34, angle_EMA34);
if(abs(SelectedValue(angle_EMA34)) >= 25)
{
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorYellow);
}
else if(abs(SelectedValue(angle_EMA34)) >= 15)
{
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorBlue);
}
else
{
TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorRed);
}
TitleAngleEMA34 = TitleAngleEMA34 + angle_EMA34;

//////////////////////////////////////////////////////////////////////////////

Color_ema_eangle= IIf(angle_ema34>=5,colorYellow,IIf(angle_ema34<=-5,colorRed,colorBlue));

//Plot(EMA34,"EMA 34",Color_ema_eangle, styleDots | styleThick|styleThick );


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx

//TRENDING RIBBON
// Paste the code below to your price chart somewhere and green ribbon means both
// both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX
// are both trending down.
_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI() AND MACD()>Signal();
downtrend=MDI()>PDI() AND Signal()>MACD();
//Plot( 2, /* defines the height of the ribbon in percent of pane width */"",
// IIf( uptrend AND EMA(C,50)>=Ref(EMA(C,50),-1), colorLime, IIf( downtrend OR EMA(C,50)<Ref(EMA(C,50),-1),
// colorRed, colorTan)) , /* choose color */styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx

//TREND ADVISER

pointer[0] = 0;

/* Phase filter */

Cond1 = Close > MA(Close, 50)AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
Cond2 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND NOT(MA(Close, 50) > MA(Close, 200));
Cond3 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond4 = NOT(Close > MA(Close, 50))AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond5 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND MA(Close, 50) > MA(Close, 200);
Cond6 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));


for (i = 1; i < BarCount; i++)
{

if (Cond1)
pointer = 1;
if (Cond2)
pointer = 2;
if (Cond3)
pointer = 3;
if (Cond4)
pointer = 4;
if (Cond5)
pointer = 5;
if (Cond6)
pointer = 6;

}

/* Plot Graphic */
//GraphXSpace= 15 ;
dynamic_color = IIf(pointer < 4, colorGreen, colorRed);
//Plot(pointer, "TrendAdv2", dynamic_color, styleHistogram | styleThick, Null, Null, 0);
//SetChartBkGradientFill(ParamColor("BgTop", colorWhite), ParamColor("BgBottom", colorLightYellow));
Cond= pointer < 4 ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx




//KPL

/* my entry is very simple(daily data for trading)

kpl system for entry only & exit as follow:

1 st exit at x % from entry price only 1/3 quantity.(ie 1st profit target)
2 nd exit when exit Signal comes from kpl sys remaining 1/3 quantity.
3. scale-in to initial quantity if new kpl Buy Signal comes.
re-do above scaling-out & scaling-in till filal exit.
4. final exit all quantity when Close below 21 Day EMA.

kpl system code bellow :
*/
//AFL by Kamalesh Langote. Email:kpl@...
noR =Param( "SwingR", 5, 1, 55 ) ;
noS =Param( "SwingS", 2, 1, 55 ) ;
res=HHV(H,noR);
sup=LLV(L,noS);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);
//tsl_col=ParamColor( "Color", colorCycle );
tsl_col= IIf(avn==1,colorCustom11,colorRed );
//Plot(tsl, "KPL", tsl_col, styleLine | styleThick);
TSLBuy = C > Ref(res,-1);
TSLSell = Ref(sup,-1) > C ;
//shape=kplBuy*shapeUpArrow + kplSell*shapeDownArrow;
//PlotShapes(shape,IIf(kplBuy,colorBrightGreen,color Red),0,IIf(kplBuy,Low,High));
SetPositionSize(300,spsShares);
ApplyStop(0,1,10,1);
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//HEIKIN-ASHI
//SetChartOptions(0,chartShowArrows | chartShowDates);
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 ) );
xDiff = (HaHigh - Halow) * 10000;
//barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
barcolor= IIf(HaClose>=HaOpen,colorGreen,colorRed) ;
//SetBarFillColor(IIf(HaClose>=HaOpen,colorLime,colo rRed));
//PlotOHLC( Open, High, Low, Close, "", colorWhite, styleCandle );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//FORMULE
P = ParamField("Price field",-1);
cuptop1= C>BBandTop(p,20,1) ;
bot1= BBandBot(p,20,1) ;
top2= BBandTop(p,20,2) ;
bot2= BBandBot(p,20,2) ;
stochup= StochK()>StochD() ;
MACDup= MACD()>Signal() ;
Hist= MACD()-Signal() ;
Histup= Hist>Ref(Hist,-1) ;
MFIupema5= MFI()>EMA(MFI(),5) ;
Cupo= C>=O ;
top1up= BBandTop(p,20,1)>=Ref(BBandTop(p,20,1),-1) ;
top2up= BBandTop(p,20,2)>=Ref(BBandTop(p,20,2),-1) ;
band= BBandTop(p,20,2)-BBandBot(p,20,2) ;
Volatbuy= band>Ref(band,-1) ;
cupbot1= C>BBandBot(p,20,1) ;
bot1up= BBandBot(p,20,1)>Ref(BBandBot(p,20,1),-1) ;
MA20up= MA(C,20)>=Ref(MA(C,20),-1) ;
EMA50up= EMA(C,50)>=Ref(EMA(C,50),-1) ;
Vup10= V>10000 AND C>O ;
Vupma= MA(V,5)>MA(V,21) ;
CCIup0= CCI()>0 ;
CCI200= CCI()<200 ;
Cupma20= C>MA(C,20) ;
ADXup= ADX()>=Ref(ADX(),-1) ;
ADX45= ADX()<45 ;
PDIupmdi= PDI()>MDI() ;
Cond= pointer<4 ;
heikinup= HaClose>=HaOpen ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx

myBuy= C>tsl AND Cond AND Heikinup AND Cupo AND EMA50up ;
mySell= C<tsl ;

//Cover = ExRem(mybuy,mysell) ;
//Short = ExRem(mysell,mybuy) ;

//shape=Cover*shapeUpTriangle + Short*shapeDownTriangle;
//PlotShapes(shape,IIf(Cover,colorGreen,colorCustom1 2),0,IIf(Cover,HaLow,HaHigh));

/////////////////////////////////////////////////////////////////////////////////////////////////////////



_SECTION_BEGIN("Price Line");

PriceLineColor=ParamColor("PriceLineColor",ColorRGB(82,82,82));
PriceLevel = ParamField("PriceField", field = 3 );

Daysback = Param("Bars Back",100,10,500,1);
FirstBar = BarCount - DaysBack;
YY = IIf(BarIndex() >= Firstbar,EndValue(PriceLevel),Null);

//Plot(YY,"Current Price",PriceLineColor,ParamStyle("LineStyle",style Line|styleDashed|styleNoTitle|styleNoLabel|styleTh ick,maskAll));


side = Param("side",1,0,1000,1);

dist = 0;

for( i = 0; i < BarCount; i++ )
{
if(i+side== BarCount) PlotText( "\n " + PriceLevel[ i ], i, YY[ i ]-dist, colorWhite );
}

_SECTION_END();
_SECTION_BEGIN("BW Fractal");

/* UpFractal= ValueWhen( */
SellFractal= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2));

/* DownFractal= ValueWhen( */
BuyFractal= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2));


NewSellFractal=(Ref(SellFractal,2) > Ref(SellFractal,1) OR Ref(SellFractal,2) < Ref(SellFractal,1)) OR C < Ref(BUYFRACTAL,4);
NewBuyFractal=(Ref(BuyFractal,2) > Ref(BuyFractal,1) OR Ref(BuyFractal,2) < Ref(BuyFractal,1) ) OR C > Ref(SellFRACTAL,4) ;

//== Added Crash crashandburn59 [at] hotmail.com solution
//Plot(Ref(SellFractal,4), "STOP-UP", ParamColor("SELL FORCE COLOR",colorCustom12), ParamStyle("Sell Fractal Style", styleDashed));
//Plot(Ref(BuyFractal,4), "STOP-DOWN",ParamColor("BUY FORCE COLOR",colorCustom11), ParamStyle("Buy Fractal Style", styleDashed));




// BBands_Stop_v1.mq4 by [email protected]
// translation in Amibroker AFL, E.M.Pottasch, 2011
SetChartBkColor(64);
Length= 10; // Period
Deviation= 1;
// Deviation was 2
MoneyRisk= 1.0;
// Offset Factor
TurnedUp=Nz(StaticVarGet("TurnedUp"));
TurnedDown=Nz(StaticVarGet("TurnedDown"));
SoundON = ParamToggle("Sound","Off|On",1);
procedure
CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown){global UpTrendLine;
global DownTrendLine;
global smax;
global smin;
UpTrendLine=Null;
DownTrendLine=Null;
smax=Null;
smin=Null;
trend=0;
for (i=Length+1;
i<BarCount;
i++){ smax=bbtop;
smin=bbbot;
if (C>smax[i-1]) trend=1;
if (C<smin[i-1]) trend=-1;
if(trend>0 && smin<smin[i-1]) smin=smin[i-1];
if(trend<0 && smax>smax[i-1]) smax=smax[i-1];
bsmax=smax+0.5*(MoneyRisk-1)*(smax-smin);
bsmin=smin-0.5*(MoneyRisk-1)*(smax-smin);
if(trend>0 && bsmin<bsmin[i-1]) bsmin=bsmin[i-1];
if(trend<0 && bsmax>bsmax[i-1]) bsmax=bsmax[i-1];
if (trend>0) { UpTrendLine=bsmin;
if (SoundON==True && !TurnedUp && i==BarCount-1 && IsEmpty(UpTrendLine[i-1])) { Say("BUYYY BUYYY BUYYY BUYYY BUYYY BUYYY");
TurnedUp=StaticVarSet("TurnedUp",1);
TurnedDown=StaticVarSet("TurnedDown",0);
} } if (trend<0) { DownTrendLine=bsmax;
if (SoundON==True && !TurnedDown && i==BarCount-1 && IsEmpty(DownTrendLine[i-1])) { Say("SELLL SELLL SELLL SELLL SELLL SELLL SELLL SELLL");
TurnedUp=StaticVarSet("TurnedUp",0);
TurnedDown=StaticVarSet("TurnedDown",1);
} }}}bbtop=BBandTop(C,Length,Deviation);
bbbot=BBandBot(C,Length,Deviation);
CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown);
UpTrendSigNal=UpTrendLine AND IsEmpty(Ref(UpTrendLine,-1));
DownTrendSigNal=DownTrendLine AND IsEmpty(Ref(DownTrendLine,-1));
// chartGraphXSpace = 5;SetChartOptions(0, chartShowDates);
//Plot(C,"",colorWhite,styleCandle);
Plot(UpTrendLine,"BULL FORCE",colorCustom11,styleThick,3) ;
Plot(DownTrendLine,"BEAR FORCE",colorCustom12,styleThick,3);
PlotShapes(IIf(UpTrendSignal,shapeSmallUpTriangle, shapeNone),ColorRGB(0,191,255),0,L,-15);
//PlotShapes(IIf(UpTrendSignal,shapeHollowSmallCircl e,shapeNone),colorWhite,0,C,0);
PlotShapes(IIf(DownTrendSignal,shapeSmallDownTriangle,shapeNone),ColorRGB(255,20,147),0,H,-15);
//PlotShapes(IIf(DownTrendSignal,shapeHollowSmallCir cle,shapeNone),colorWhite,0,C,0);

TRENDBuy = UPTRENDSIGNAL;
TRENDSell= DOWNTRENDSIGNAL;


_SECTION_BEGIN("VELVOORT HEIKIN CANDLE SAR THREE");
//AFL Heikin Ashi

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

// Velvoort is using not original, but modified Heikin-Ashi close
HaClose = ( HaClose + HaOpen + HaHigh + HaLow )/4;





// you can switch between Heikin-Ashi chart and regular candlestick chart

//tambahan Ku
Hacol = IIf(HaClose>HaOpen, colorDarkBlue, colorDarkRed);
SetBarFillColor(Hacol);

//if( ParamToggle("Plot Heikin-Ashi", "No,Yes", 1 ) )
//PlotOHLC( haOpen, High, Low, Close, " " + Name(), IIf(HaClose>HaOpen, colorBlue, colorRed), styleCandle); //colorBlue, styleCandle );
//else
//Plot( C, "Regular candles " + Name(), IIf(Close>Open, colorBlue, colorRed), styleCandle );

// E.M.Pottasch, Jul 2010
// from Metastock formula, link:
//http://stocata.org/metastock/stop_trail_atr.html

function vstop_func(tr)
{
trailArray[ 0 ] = HaClose[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];

if (HaClose[ i ] > prev AND HaClose[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,HaClose[ i ] - tr[ i ]);
}
else if (C[ i ] < prev AND HaClose[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,HaClose[ i ] + tr[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = HaClose[ i ] - tr[ i ];
}
else
{
trailArray[ i ] = HaClose[ i ] + tr[ i ];
}
}
return trailArray;
}

per = Param("per",20, 5, 150, 1);
mult = Param("mult",2, 1, 4, 0.05);
tr = mult * ATR(per);
trailArray = vstop_func(tr);
//trailArray = Ref(trailArray,-1);

SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) );
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
//Plot(IIf(trailArray >
//C,trailArray,Null),"\ntrailShort",ParamColor("Colo rTrailShort",ColorRGB(255,0,0)),styleStaircase);
//Plot(IIf(trailArray <
//C,trailArray,Null),"\ntrailLong",ParamColor("Color TrailLong",ColorRGB(0,255,0)),styleStaircase);
//Plot( C, "\nCandle",colorWhite, styleCandle );





acc = Param("Acceleration", 0.03, 0, 3, 0.001 );
accm = Param("Max. acceleration", 0.5, 0, 3, 0.001 );


//Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorYellow ), ParamStyle("Style", styleStaircase | styleLine, maskDefault | styleStaircase | styleLine ) );



SARSell = Cross(SAR( acc, accm ),HaClose) ;
SARBuy = Cross(HaClose,SAR( acc, accm )) ;




_SECTION_BEGIN("Krishna System");
R = RSI(4);
SK = StochK(9, 2);
SD = StochD(9, 2, 2);
MH = MACD(8, 21) - Signal(8, 21, 5);

//Conditions for Buying

Cond1 = ValueWhen(C,O<C);
Cond2 = R > 50;
Cond3 = SD < 80 AND SD > Ref(SD, -1);
Cond4 = MH > 0 OR (MH < 0 AND MH > Ref(MH, -1));

//Conditions for Selling

Cond5 = ValueWhen(C,O>C);
Cond6 = R < 50;
Cond7 = SD > 20 AND SD < Ref(SD, -1);
Cond8 = MH < 0 OR (MH > 0 AND MH < Ref(MH, -1));

strongBuy = Cond1 AND Cond2 AND Cond3 AND Cond4 ;
strongSell = Cond5 AND Cond6 AND Cond7 AND Cond8 ;



//res=EMA(H,3);
//sup=EMA(L,3);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
kpl=IIf(avn==1,sup,res);
kpl_col=ParamColor( "Color", colorCycle );
kpl_col= IIf(avn==1,colorCustom11,colorCustom12 );
//Plot(tsl, "TAKE CARE VALUE", tsl_col, styleStaircase | styleThick);



kplBuy = MA(C,5) > tsl;
kplSell = tsL > MA(C,5) ;


SUPERBUY = TSL > SAR(ACC,ACCM) ;
SUPERSELL= TSL < SAR(ACC,ACCM);

RSIperiod = 5; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 5; //Param("HHV p",3,5,10,1);
NumLine = 1; //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", colorCustom12, styleLine);
//Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorBrightGreen, styleLine);
}
//Title = Name() + "; " + Date() + ": Support & Resistance Levels using RSI: " + /*EncodeColor(colorGreen)+ "Support Levels are Green; "+EncodeColor(colorRed)+ "Resistance Levels are Red: "+EncodeColor(colorBlack)+*/ "Num lines ="+WriteVal(numline,1) ;
/* EMA offset bands ver 1_2
I'd guess this is NOT much different to bbands except you can contol the per % offset and the periods ema to off set*/
per=.10;//Percent placement
periods=20;//time periods

/* EMA offset bands ver 1_2
I'd guess this is NOT much different to bbands except you can contol the per % offset and the periods ema to off set*/
per=.10;//Percent placement
periods=20;//time periods
/*********************************/

emaverage= EMA(C,periods);
bandsAdjust=emaverage*per;
k=1; /* multiplication factor*/
n=10; /*period*/
f=ATR(n);


R[0] = Close[0];

S[0] = C[0];
for( i = 11; i < BarCount; i++ )
{


R=R[i-1];
S=S[i-1];

if ( C[i-1] >R[i-1] )
{
r = C[i-1]+k*f[i-1];
s= C[i-1]-k*f[i-1];
}
if ( C[i-1] <S[i-1] )
{
r = C[i-1]+k*f[i-1];
s= C[i-1]-k*f[i-1];
}


FBuy=Close>R;
FSell=Close<S;



GBuy= VUP10 AND FBuy;
GSell= STRONGSELL AND doWNTREND OR FSell;

//Super TEMA by C Chulainn V1.0

n=25; Av=12; Av1=16; Av2=2; stp=2;

if (Name() == "CPTA.MI")// CAPITALIA
{ n=7; Av=18; Av1=14; Av2=2; }
else if (Name() == "BANI.MI")// BNL
{ n=29; Av=30; Av1=10; Av2=2; }
else if (Name() == "FIBK.MI")// B FIDEURAM
{ n=22; Av=15; Av1=22; Av2=2; }
else if (Name() == "FIA.MI")// FIAT
{ n=2; Av=28; Av1=10; Av2=2; }
else if (Name() == "MDBI.MI")// MEDIOBANCA
{ n=21; Av=27; Av1=29; Av2=2; }
else if (Name() == "MS.MI")// MEDIASET
{ n=30; Av=20; Av1=24; Av2=2; }
else if (Name() == "TIM.MI")// TIM
{ n=6; Av=10; Av1=20; Av2=2; }
else if (Name() == "TLIT.MI")// TELECOM IT
{ n=30; Av=25; Av1=29; Av2=3; }

n = Optimize("Periods",n,3,30,1);
av = Optimize("Average",av,10,30,1);
av1 = Optimize("Average1",av1,10,30,1);
av2 = Optimize("Average2",av2,2,5,1);
stp = Optimize("Stop",stp,4,15,1);

Var1= TEMA(Close,n);
Var2= TEMA(var1,av);
Var3= (var1-var2)+var1;
Var1= TEMA(var3,av1);
Var4= MA((var1-var2)+var1,av2);
Var5=(Var1-Var2)+Var1;

TEMASell=Cross(Var4,Var5);
TEMABuy= Cross(Var5,VAR4);

TEMASell=Cross(Var5,Ref(Var5,1));
TEMABuy=Cross(Ref(Var5,1),VAR5);
//PlotShapes(shapeUpArrow*Buy,colorCustom11, 0, L, -5 );
//PlotShapes(shapeDownArrow*Sell,colorCustom11, 0, L, -5 );

//RBuy = VOLATBUY OR kplbuy AND QBUY OR SARBUY AND QBUY OR QBUY AND STRONGBUY;
//RSell = kplsell AND QSELL OR sarsell AND QSELL OR QSELL AND STRONGSELL;



MinBars = 100;
MinBarsOK = IIf(BarCount >= MinBars, True, False);

if (MinBarsOK) { ;





_SECTION_BEGIN("BAPUR");
/* **********************************

Code to automatically identify pivots

********************************** */
// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",100,1,100,1);
nBars = Param("Number of bars", 50, 50, 1);
// -- Title.
//Title = Name() + " (" + StrLeft(FullName(), 15) + ") O: " + Open + ",
//H: " + High + ", L: " + Low + ", C: " + Close;
// -- Plot basic candle chart
//PlotOHLC(Open, High, Low, Close,
//"BIdx = " + BarIndex() +
//"\n" + "O = " + O + "\n"+"H = "+ H + "\n"+"L = " + L
//+ "\n"+"C ",
//colorWhite, 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


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

//PlotShapes(IIf(aHPivs==1, shapeDownTriangle, shapeNone), colorCustom12, 0, High, Offset=-20);
//PlotShapes(IIf(aLPivs==1, shapeUpTriangle , shapeNone), colorCustom11, 0, Low, Offset=-20);



ABuy = TSLBUY AND TRENDBUY OR TSLBUY AND GBuy OR TSLBUY AND sarbuy OR TSLBUY AND strongbuy;
ASell = TSLSELL AND TRENDSELL OR TSLSELL AND GSell OR TSLSELL AND sarsell OR TSLSELL AND strongsell ;

BBUY = TRENDBUY AND GBuy OR TRENDBUY AND KPLBUY OR TRENDBUY AND SARBUY OR TRENDBUY AND STRONGBUY;
BSELL = TRENDSELL AND GSell OR TRENDSELL AND KPLSELL OR TRENDSELL AND SARSELL OR TRENDSELL AND STRONGSELL;

CBUY = GBuy AND KPLBUY OR GBuy AND SARBUY OR GBuy AND STRONGBUY;
CSELL = GSell AND KPLSELL OR GSell AND SARSELL OR GSell AND STRONGSELL;

DBUY = KPLBUY AND SARBUY OR KPLBUY AND STRONGBUY;
DSELL = KPLSELL AND SARSELL OR KPLSELL AND STRONGSELL;

EBUY = SARBUY OR STRONGBUY;
ESELL = SARSELL OR STRONGSELL;

Cump=IIf(Close>R,1,0);
Vanz=IIf(Close<S,1,0);

HBuy = BBuy OR DBuy ;
HSell = ESELL OR TRENDSELL ;


IBUY = HBUY AND TSLBUY OR HBUY AND KPLBUY OR TRENDBUY ;
ISELL= HSELL AND GSELL OR HSELL AND SSELL;



Buy = Cover = IBUY AND TRENDBUY OR TRENDBUY OR TRENDBUY AND LOGIXBUY OR logIXBUY AND IBUY ;
Sell= Short = ISell AND LOGIXSELL OR STRONGSELL AND TRENDSELL OR logIXSELL AND TRENDSELL;


Buy = ExRem( Buy, Sell ); //Elimina semnalele buy consecutive
Sell = ExRem( Sell, Buy ); //Elimina semnalele sell consecutive

PlotShapes(shapeSmallUpTriangle *Buy ,colorCustom9,0,MaLow, -20);
PlotShapes(shapeSmallDownTriangle * Sell,colorCustom12,0,MaHigh,-20);

SellPrice=ValueWhen(Sell,H,1);
BuyPrice=ValueWhen(Buy,L,1);

Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );


//Buy = ExRem(Buy,Sell) ;
//Sell = ExRem(Sell,Buy) ;



//PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,Low,-15);
//PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorYellow, 0,High,-15);

dist = 6.00*ATR(4);
dist1 = 6.00*ATR(4);
for( i = 0; i < BarCount; i++ )
{
if( Buy )
{
PlotText( "\nSL= " + (L*0.9925), i, H[ i ]-dist, colorGreen, colorWhite );
}
if( Sell )
{
PlotText( "\nSL= " + (H*1.0075), i, L[ i ]+dist1, colorRed, colorWhite );
}
}

dist = 0.70*ATR(5);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( " BUY " + Avg[ i ], i, L[ i ]-dist, colorCustom11);
if( Sell ) PlotText( " SELL " + Avg[ i ], i, H[ i ]+dist, colorCustom12);
}

AlertIf(Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Short Triggered!", 3, 8);
AlertIf(Buy, "SOUND C:\\Windows\\Media\\Ding.wav", "Cover Triggered!", 4, 8);



//fig=Cump*shapeHollowUpArrow + Vanz*shapeHollowDownArrow;







_SECTION_BEGIN("Background text");
C11=ParamColor("up panel",colorDarkOliveGreen );
C12=ParamColor("dn panel",colorDarkGrey );
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");
GfxSetBkMode( 0 );
GfxSetOverlayMode(1);
GfxGradientRect(0,0,pxwidth, pxheight, C11, C12 );
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxTextOut( "LTP "+WriteVal(C,1.2), Status("pxwidth")/C14, Status("pxheight")/C15);
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( " SRI CHAKRA", Status("pxwidth")/C14, Status("pxheight")/C15*2 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
GfxSetTextColor(colorYellow);

}}


 
#6
Hi shruti.trader,thanks for posting error free afl which was earlier shared by S kumar. Please have a look at the below mentioned afl against query no.3.

Regards
Debashish

_SECTION_BEGIN("TEMA");
function ZeroLagTEMA( array, period )
{
TMA1 = TEMA( array, period );
TMA2 = TEMA( TMA1, period );
Diff = TMA1 - TMA2;
return TMA1 + Diff ;
}

/////////////////////
// Heikin-Ashi code
HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );

avp = Param("Up TEMA avg", 34, 1, 100 );
avpdn = Param("Dn TEMA avg", 34, 1, 100 );

// Velvoort is using not original, but modified Heikin-Ashi close
HaClose = ( HaClose + HaOpen + Max( H, HaOpen ) + Min( L, HaOpen ) )/4;

// up average
ZlHa = ZeroLagTEMA( HaClose, avp );
ZlCl = ZeroLagTEMA( ( H + L ) / 2, avp );
ZlDif = ZlCl - ZlHa;

keep1 = Hold( HaClose >= HaOpen, 2 );
keep2 = ZlDif >= 0;
keeping = keep1 OR keep2;
keepall = keeping OR ( Ref( keeping, -1 ) AND ( C > O ) OR C >= Ref( C, -1 ) );
keep3 = abs( C - O ) < ( H - L ) * 0.35 AND H >= Ref( L, -1 );
utr = keepall OR ( Ref( keepall, -1 ) AND keep3 );

// dn average
ZlHa = ZeroLagTEMA( HaClose, avpdn );
ZlCl = ZeroLagTEMA( ( H + L ) / 2, avpdn );
ZlDif = ZlCl - ZlHa;

keep1 = Hold( HaClose < HaOpen, 2 );
keep2 = ZlDif < 0;
keeping = keep1 OR keep2;
keepall = keeping OR ( Ref( keeping, -1 ) AND ( C < O ) OR C < Ref( C, -1 ) );
keep3 = abs( C - O ) < ( H - L ) * 0.35 AND L <= Ref( H, -1 );
dtr = keepall OR ( Ref( keepall, -1 ) AND keep3 );

upw = dtr == 0 AND Ref( dtr, -1 ) AND utr;
dnw = utr == 0 AND Ref( utr, -1 ) AND dtr;

Haco = Flip( upw, dnw );


if( ParamToggle("Chart Type", "Price with color back|HACO wave" ) )
{
Plot( Haco, "Haco", colorRed );
}
else
{
Plot( C, "Close", colorBlack,
ParamStyle( "Style", styleCandle, maskPrice ) );
Plot( 1, "", IIf( Haco , colorPaleGreen, colorRose ),
styleArea | styleOwnScale, 0, 1 );
}
_SECTION_END();

_SECTION_BEGIN("graph");
SetChartOptions(0,chartShowArrows|chartShowDates);
gxs=Param("GRAPH spaceing",10,5,50,5);
GraphXSpace = gxs;
strWeekday = StrMid("SunMonTueWedThuFriSat", SelectedValue(DayOfWeek())*3,3);
_SECTION_END();
_SECTION_BEGIN("NMA ");
k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);
j=(O+H+L+C)/4;
nm= (H-L);
rfsctor = WMA(nm, PER);
revers = K * rfsctor;
Trend = 1;
NW[0] = 0;
for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j < NW[i-1])
{
Trend = -1;
NW = j + Revers;
}
else
{
Trend = 1;
if((j - Revers) > NW[i-1])
{
NW = j - Revers;
}
else
{
NW = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j > NW[i-1])
{
Trend = 1;
NW = j - Revers;
}
else
{
Trend = -1;
if((j + Revers) < NW[i-1])
{
NW = j + Revers;
}
else
{
NW = NW[i-1];
}
}
}
}

Plot(NW, "", IIf(Trend == 1, 6, 4), 4);

//---------------trading -------------

Buy=Cross(j,nw);
Short=Cross(nw,j);
Sell=Cross(nw,j);
Cover=Cross(j,nw);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorSkyblue, 0,Low,-15);
PlotShapes(IIf(Sell, shapeHollowDownArrow, shapeNone),colorLightYellow, 0,High,-15);
PlotShapes(IIf(Cover, shapeHollowUpArrow, shapeNone),colorTan, 0,Low,-25);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorGold, 0,High,-25);
//-----------end--------------
Long=Flip(Buy,Sell OR Cover);
Shrt=Flip(Sell,Buy OR Cover);
NOTrade= NOT (Long OR shrt);
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
_SECTION_END();
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
Plot(grid_day,"",colorDarkGrey,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
///--------------------------------------------------------------------------------------------------
Candletype=ParamList("Candle Type","Candle|Heinkin",0);
UpCandle = ParamColor("Up Color", colorBrightGreen );
DownCandle = ParamColor("Down Color", colorDarkRed );
Consolidation = ParamColor("Consolidation", colorBlack );
BG2a=HHV(LLV(L,4)+ATR(4),8);
BR2a=LLV(HHV(H,4)-ATR(4),8);
if(Candletype=="Candle")
{
Candlecolor = IIf(Close>BG2a ,UpCandle,IIf(Close < BR2a,DownCandle,Consolidation));
SetBarFillColor( IIf(O <C, colorSeaGreen,colorOrange) );
Plot( Close, "Price", CandleColor, styleCandle );
TimeFrameSet( 2*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M5 = TimeFrameExpand(BG2,2*Interval(),expandFirst );
MM5=TimeFrameExpand( BR2,2*Interval(),expandFirst );
cM5=TimeFrameExpand( C1, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M15 = TimeFrameExpand(BG2,4*Interval(),expandFirst );
MM15=TimeFrameExpand(BR2,4*Interval(),expandFirst );
cM15=TimeFrameExpand( C1,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M30 = TimeFrameExpand(BG2,6*Interval(),expandFirst );
MM30=TimeFrameExpand(BR2,6*Interval(),expandFirst );
cM30=TimeFrameExpand( C1,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
H1 = TimeFrameExpand(BG2 ,8*Interval(),expandFirst );
HH1=TimeFrameExpand( BR2,8*Interval(),expandFirst );
Ch1=TimeFrameExpand( C1,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
H4 = TimeFrameExpand( BG2,16*Interval(),expandFirst );
HH4=TimeFrameExpand( BR2,16*Interval(),expandFirst );
cH4 = TimeFrameExpand( C1,16*Interval(),expandFirst );
Com=("\n "+Name()+ " - Trend in "+Candletype)+"\n "+
EncodeColor(colorLightGrey)+(""+Interval(2)+":")+
WriteIf(Close>BG2a,EncodeColor(colorLime)+" UP",WriteIf(Close<BR2a,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+2*Interval()/60+"m:")+
WriteIf(Cm5>M5,EncodeColor(colorLime)+" UP",WriteIf(Cm5<MM5,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+4*Interval()/60+"m:")+
WriteIf(Cm15>M15,EncodeColor(colorLime)+" UP",WriteIf(Cm15<MM15,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+6*Interval()/60+"m:")+
WriteIf(Cm30>M30,EncodeColor(colorLime)+" UP",WriteIf(Cm30<MM30,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+8*Interval()/60+"m:")+
WriteIf(CH1>H1,EncodeColor(colorLime)+" UP",WriteIf(CH1<HH1,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+16*Interval()/60+"m: ")+
WriteIf(Ch4>H4,EncodeColor(colorLime)+" UP",WriteIf(Ch4<HH4,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));
}
else if(Candletype=="Heinkin")
{
aC =(O+H+L+C)/4;
aO = AMA( Ref( aC, -1 ), 0.5 );
aH = Max( H, Max( aC, aO) );
aL = Min( L, Min( aC, aO) );
BGH=HHV(LLV(aL,4)+ATR(4),8);
BRH=LLV(HHV(aH,4)-ATR(4),8);
co = IIf(ac>BGH ,UpCandle,IIf(ac < BRH,DownCandle,Consolidation));
SetBarFillColor( IIf(aO <aC, colorSeaGreen,colorOrange) );
PlotOHLC(aO,ah,aL,ac ,"Price", Co, styleCandle );
TimeFrameSet( 2*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H5 = TimeFrameExpand(BG2H,2*Interval(),expandFirst );
MH5=TimeFrameExpand( BR2H,2*Interval(),expandFirst );
cH5=TimeFrameExpand( C1, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H15 = TimeFrameExpand(BG2H,4*Interval(),expandFirst );
MH15=TimeFrameExpand(BR2H,4*Interval(),expandFirst );
cH15=TimeFrameExpand( C1,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H30 = TimeFrameExpand(BG2H,6*Interval(),expandFirst );
MH30=TimeFrameExpand(BR2H,6*Interval(),expandFirst );
cH30=TimeFrameExpand( C1,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();

H1A = TimeFrameExpand(BG2H ,8*Interval(),expandFirst );
HH1A=TimeFrameExpand( BR2H,8*Interval(),expandFirst );
Ch1A=TimeFrameExpand( C1,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H4 = TimeFrameExpand( BG2H,16*Interval(),expandFirst );
HH4=TimeFrameExpand( BR2H,16*Interval(),expandFirst );
cH4 = TimeFrameExpand( C1,16*Interval(),expandFirst );
Com=("\n "+Name()+ " - Trend in "+Candletype)+"\n "+
EncodeColor(colorLightGrey)+(""+Interval(2)+":")+
WriteIf(aC>BGH,EncodeColor(colorLime)+" UP",WriteIf(aC<BRH,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+2*Interval()/60+"m:")+
WriteIf(cH5>H5,EncodeColor(colorLime)+" UP",WriteIf(cH5<MH5,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+4*Interval()/60+"m:")+
WriteIf(cH15>H15,EncodeColor(colorLime)+" UP",WriteIf(cH15<MH15,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+6*Interval()/60+"m:")+
WriteIf(cH30>H30,EncodeColor(colorLime)+" UP",WriteIf(cH30<MH30,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+8*Interval()/60+"m:")+
WriteIf(Ch1A>H1A,EncodeColor(colorLime)+" UP",WriteIf(Ch1A<HH1A,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+16*Interval()/60+"m: ")+
WriteIf(Ch4>H4,EncodeColor(colorLime)+" UP",WriteIf(Ch4<HH4,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));
}
//---------------------------------------------------------------------------------------
Vr=ParamList("Index",List = "^NSEI,^NSEBANK,NIFTY_F1,RELIANCE.NS,SBIN.NS", 0);
SetForeign(Vr);
HaC =(O+H+L+C)/4;
HaO = AMA( Ref( HaC, -1 ), 0.5 );
HaH = Max( H, Max( HaC, HaO) );
HaL = Min( L, Min( HaC, HaO) );
HBG=HHV(LLV(HaL,4)+ATR(4),8);
HBR=LLV(HHV(HaH ,4)-ATR(4),8);
co = IIf(Hac>HBG ,colorAqua,IIf(Hac < HBR,colorCustom12,colorGrey50));
if( SetForeign(Vr) )
{Plot(2, "", Co,styleArea+styleOwnScale | styleNoLabel, -1, 100);
}else{
Plot(2, "", 1,styleArea+styleOwnScale | styleNoLabel, -1, 100);}


//================================================== ===================================
TimeFrameSet( 2*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M5H = TimeFrameExpand(BG2H,2*Interval(),expandFirst );
MM5H=TimeFrameExpand( BR2H,2*Interval(),expandFirst );
cM5H=TimeFrameExpand( C1H, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M15H = TimeFrameExpand(BG2H,4*Interval(),expandFirst );
MM15H=TimeFrameExpand(BR2H,4*Interval(),expandFirst );
cM15H=TimeFrameExpand( C1H,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M30H = TimeFrameExpand(BG2H,6*Interval(),expandFirst );
MM30H=TimeFrameExpand(BR2H,6*Interval(),expandFirst );
cM30H=TimeFrameExpand( C1H,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
H1H = TimeFrameExpand(BG2H ,8*Interval(),expandFirst );
HH1H=TimeFrameExpand( BR2H,8*Interval(),expandFirst );
Ch1H=TimeFrameExpand( C1H,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
H4H = TimeFrameExpand( BG2H,16*Interval(),expandFirst );
HH4H=TimeFrameExpand( BR2H,16*Interval(),expandFirst );
cH4H = TimeFrameExpand( C1H,16*Interval(),expandFirst );
RestorePriceArrays();

Comm2=("\n "+VR+ " - Phase in ")+"\n "+
EncodeColor(colorLightYellow)+(""+Interval(2)+":") +
WriteIf(Hac>HBG,EncodeColor(colorLime)+" UP",WriteIf(Hac < HBR,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+2*Interval()/60+"m:")+
WriteIf(cM5H>M5H,EncodeColor(colorLime)+" UP",WriteIf(cM5H<MM5H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+4*Interval()/60+"m:")+
WriteIf(cM15H>M15H,EncodeColor(colorLime)+" UP",WriteIf(cM15H<MM15H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+6*Interval()/60+"m:")+
WriteIf(cM30H>M30H,EncodeColor(colorLime)+" UP",WriteIf(cM30H<MM30H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+8*Interval()/60+"m:")+
WriteIf(Ch1H>H1H,EncodeColor(colorLime)+" UP",WriteIf(Ch1H<HH1H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+16*Interval()/60+"m: ")+
WriteIf(cH4H>H4H,EncodeColor(colorLime)+" UP",WriteIf(cH4H<HH4H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));


//============
//=====Title======================================== ================================================== ======
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorBlack)+ " " + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorBlue) +
" - " + Date() +" - "+ strWeekday +" - "+"\n" +EncodeColor(colorGreen) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n----------------------"+
EncodeColor(colorTan)+ Com+
EncodeColor(colorGreen)+Comm2+"\n---------system-------------"+"\n"+
EncodeColor(colorBlue)+
WriteIf (Buy AND Ref(shrt,-1), " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Buy AND Ref(NOTrade,-1), " GO LONG at "+C+" ","")+EncodeColor(colorRed)+
WriteIf (Sell AND Ref(NOTrade,-1), " GO Short at "+C+" ","")+
WriteIf (Sell AND Ref(Long,-1), " EXIT LONG / Reverse Signal at "+C+" ","")+
WriteIf (Cover, " cover "+C+" ",""));

_SECTION_END();
_SECTION_BEGIN("Background text");
SetChartOptions(0,chartShowArrows|chartShowDates);
C11=ParamColor("up panel",colorDarkOliveGreen );
C12=ParamColor("dn panel",colorDarkGrey );
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");
GfxSetBkMode( 0 );
GfxSetOverlayMode(1);
GfxGradientRect(0,0,pxwidth, pxheight, C11, C12 );
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( "ATR Stop&Reverse", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( " ", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
_SECTION_END();
 
#7
Hi shruti.trader,thanks for posting error free afl which was earlier shared by S kumar. Please have a look at the below mentioned afl against query no.3.

Regards
Debashish

_SECTION_BEGIN("TEMA");
function ZeroLagTEMA( array, period )
{
TMA1 = TEMA( array, period );
TMA2 = TEMA( TMA1, period );
Diff = TMA1 - TMA2;
return TMA1 + Diff ;
}

/////////////////////
// Heikin-Ashi code
HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );

avp = Param("Up TEMA avg", 34, 1, 100 );
avpdn = Param("Dn TEMA avg", 34, 1, 100 );

// Velvoort is using not original, but modified Heikin-Ashi close
HaClose = ( HaClose + HaOpen + Max( H, HaOpen ) + Min( L, HaOpen ) )/4;

// up average
ZlHa = ZeroLagTEMA( HaClose, avp );
ZlCl = ZeroLagTEMA( ( H + L ) / 2, avp );
ZlDif = ZlCl - ZlHa;

keep1 = Hold( HaClose >= HaOpen, 2 );
keep2 = ZlDif >= 0;
keeping = keep1 OR keep2;
keepall = keeping OR ( Ref( keeping, -1 ) AND ( C > O ) OR C >= Ref( C, -1 ) );
keep3 = abs( C - O ) < ( H - L ) * 0.35 AND H >= Ref( L, -1 );
utr = keepall OR ( Ref( keepall, -1 ) AND keep3 );

// dn average
ZlHa = ZeroLagTEMA( HaClose, avpdn );
ZlCl = ZeroLagTEMA( ( H + L ) / 2, avpdn );
ZlDif = ZlCl - ZlHa;

keep1 = Hold( HaClose < HaOpen, 2 );
keep2 = ZlDif < 0;
keeping = keep1 OR keep2;
keepall = keeping OR ( Ref( keeping, -1 ) AND ( C < O ) OR C < Ref( C, -1 ) );
keep3 = abs( C - O ) < ( H - L ) * 0.35 AND L <= Ref( H, -1 );
dtr = keepall OR ( Ref( keepall, -1 ) AND keep3 );

upw = dtr == 0 AND Ref( dtr, -1 ) AND utr;
dnw = utr == 0 AND Ref( utr, -1 ) AND dtr;

Haco = Flip( upw, dnw );


if( ParamToggle("Chart Type", "Price with color back|HACO wave" ) )
{
Plot( Haco, "Haco", colorRed );
}
else
{
Plot( C, "Close", colorBlack,
ParamStyle( "Style", styleCandle, maskPrice ) );
Plot( 1, "", IIf( Haco , colorPaleGreen, colorRose ),
styleArea | styleOwnScale, 0, 1 );
}
_SECTION_END();

_SECTION_BEGIN("graph");
SetChartOptions(0,chartShowArrows|chartShowDates);
gxs=Param("GRAPH spaceing",10,5,50,5);
GraphXSpace = gxs;
strWeekday = StrMid("SunMonTueWedThuFriSat", SelectedValue(DayOfWeek())*3,3);
_SECTION_END();
_SECTION_BEGIN("NMA ");
k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);
j=(O+H+L+C)/4;
nm= (H-L);
rfsctor = WMA(nm, PER);
revers = K * rfsctor;
Trend = 1;
NW[0] = 0;
for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j < NW[i-1])
{
Trend = -1;
NW = j + Revers;
}
else
{
Trend = 1;
if((j - Revers) > NW[i-1])
{
NW = j - Revers;
}
else
{
NW = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j > NW[i-1])
{
Trend = 1;
NW = j - Revers;
}
else
{
Trend = -1;
if((j + Revers) < NW[i-1])
{
NW = j + Revers;
}
else
{
NW = NW[i-1];
}
}
}
}

Plot(NW, "", IIf(Trend == 1, 6, 4), 4);

//---------------trading -------------

Buy=Cross(j,nw);
Short=Cross(nw,j);
Sell=Cross(nw,j);
Cover=Cross(j,nw);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorSkyblue, 0,Low,-15);
PlotShapes(IIf(Sell, shapeHollowDownArrow, shapeNone),colorLightYellow, 0,High,-15);
PlotShapes(IIf(Cover, shapeHollowUpArrow, shapeNone),colorTan, 0,Low,-25);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorGold, 0,High,-25);
//-----------end--------------
Long=Flip(Buy,Sell OR Cover);
Shrt=Flip(Sell,Buy OR Cover);
NOTrade= NOT (Long OR shrt);
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
_SECTION_END();
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
Plot(grid_day,"",colorDarkGrey,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
///--------------------------------------------------------------------------------------------------
Candletype=ParamList("Candle Type","Candle|Heinkin",0);
UpCandle = ParamColor("Up Color", colorBrightGreen );
DownCandle = ParamColor("Down Color", colorDarkRed );
Consolidation = ParamColor("Consolidation", colorBlack );
BG2a=HHV(LLV(L,4)+ATR(4),8);
BR2a=LLV(HHV(H,4)-ATR(4),8);
if(Candletype=="Candle")
{
Candlecolor = IIf(Close>BG2a ,UpCandle,IIf(Close < BR2a,DownCandle,Consolidation));
SetBarFillColor( IIf(O <C, colorSeaGreen,colorOrange) );
Plot( Close, "Price", CandleColor, styleCandle );
TimeFrameSet( 2*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M5 = TimeFrameExpand(BG2,2*Interval(),expandFirst );
MM5=TimeFrameExpand( BR2,2*Interval(),expandFirst );
cM5=TimeFrameExpand( C1, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M15 = TimeFrameExpand(BG2,4*Interval(),expandFirst );
MM15=TimeFrameExpand(BR2,4*Interval(),expandFirst );
cM15=TimeFrameExpand( C1,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M30 = TimeFrameExpand(BG2,6*Interval(),expandFirst );
MM30=TimeFrameExpand(BR2,6*Interval(),expandFirst );
cM30=TimeFrameExpand( C1,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
H1 = TimeFrameExpand(BG2 ,8*Interval(),expandFirst );
HH1=TimeFrameExpand( BR2,8*Interval(),expandFirst );
Ch1=TimeFrameExpand( C1,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
H4 = TimeFrameExpand( BG2,16*Interval(),expandFirst );
HH4=TimeFrameExpand( BR2,16*Interval(),expandFirst );
cH4 = TimeFrameExpand( C1,16*Interval(),expandFirst );
Com=("\n "+Name()+ " - Trend in "+Candletype)+"\n "+
EncodeColor(colorLightGrey)+(""+Interval(2)+":")+
WriteIf(Close>BG2a,EncodeColor(colorLime)+" UP",WriteIf(Close<BR2a,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+2*Interval()/60+"m:")+
WriteIf(Cm5>M5,EncodeColor(colorLime)+" UP",WriteIf(Cm5<MM5,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+4*Interval()/60+"m:")+
WriteIf(Cm15>M15,EncodeColor(colorLime)+" UP",WriteIf(Cm15<MM15,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+6*Interval()/60+"m:")+
WriteIf(Cm30>M30,EncodeColor(colorLime)+" UP",WriteIf(Cm30<MM30,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+8*Interval()/60+"m:")+
WriteIf(CH1>H1,EncodeColor(colorLime)+" UP",WriteIf(CH1<HH1,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+16*Interval()/60+"m: ")+
WriteIf(Ch4>H4,EncodeColor(colorLime)+" UP",WriteIf(Ch4<HH4,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));
}
else if(Candletype=="Heinkin")
{
aC =(O+H+L+C)/4;
aO = AMA( Ref( aC, -1 ), 0.5 );
aH = Max( H, Max( aC, aO) );
aL = Min( L, Min( aC, aO) );
BGH=HHV(LLV(aL,4)+ATR(4),8);
BRH=LLV(HHV(aH,4)-ATR(4),8);
co = IIf(ac>BGH ,UpCandle,IIf(ac < BRH,DownCandle,Consolidation));
SetBarFillColor( IIf(aO <aC, colorSeaGreen,colorOrange) );
PlotOHLC(aO,ah,aL,ac ,"Price", Co, styleCandle );
TimeFrameSet( 2*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H5 = TimeFrameExpand(BG2H,2*Interval(),expandFirst );
MH5=TimeFrameExpand( BR2H,2*Interval(),expandFirst );
cH5=TimeFrameExpand( C1, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H15 = TimeFrameExpand(BG2H,4*Interval(),expandFirst );
MH15=TimeFrameExpand(BR2H,4*Interval(),expandFirst );
cH15=TimeFrameExpand( C1,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H30 = TimeFrameExpand(BG2H,6*Interval(),expandFirst );
MH30=TimeFrameExpand(BR2H,6*Interval(),expandFirst );
cH30=TimeFrameExpand( C1,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();

H1A = TimeFrameExpand(BG2H ,8*Interval(),expandFirst );
HH1A=TimeFrameExpand( BR2H,8*Interval(),expandFirst );
Ch1A=TimeFrameExpand( C1,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H4 = TimeFrameExpand( BG2H,16*Interval(),expandFirst );
HH4=TimeFrameExpand( BR2H,16*Interval(),expandFirst );
cH4 = TimeFrameExpand( C1,16*Interval(),expandFirst );
Com=("\n "+Name()+ " - Trend in "+Candletype)+"\n "+
EncodeColor(colorLightGrey)+(""+Interval(2)+":")+
WriteIf(aC>BGH,EncodeColor(colorLime)+" UP",WriteIf(aC<BRH,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+2*Interval()/60+"m:")+
WriteIf(cH5>H5,EncodeColor(colorLime)+" UP",WriteIf(cH5<MH5,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+4*Interval()/60+"m:")+
WriteIf(cH15>H15,EncodeColor(colorLime)+" UP",WriteIf(cH15<MH15,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+6*Interval()/60+"m:")+
WriteIf(cH30>H30,EncodeColor(colorLime)+" UP",WriteIf(cH30<MH30,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+8*Interval()/60+"m:")+
WriteIf(Ch1A>H1A,EncodeColor(colorLime)+" UP",WriteIf(Ch1A<HH1A,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+16*Interval()/60+"m: ")+
WriteIf(Ch4>H4,EncodeColor(colorLime)+" UP",WriteIf(Ch4<HH4,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));
}
//---------------------------------------------------------------------------------------
Vr=ParamList("Index",List = "^NSEI,^NSEBANK,NIFTY_F1,RELIANCE.NS,SBIN.NS", 0);
SetForeign(Vr);
HaC =(O+H+L+C)/4;
HaO = AMA( Ref( HaC, -1 ), 0.5 );
HaH = Max( H, Max( HaC, HaO) );
HaL = Min( L, Min( HaC, HaO) );
HBG=HHV(LLV(HaL,4)+ATR(4),8);
HBR=LLV(HHV(HaH ,4)-ATR(4),8);
co = IIf(Hac>HBG ,colorAqua,IIf(Hac < HBR,colorCustom12,colorGrey50));
if( SetForeign(Vr) )
{Plot(2, "", Co,styleArea+styleOwnScale | styleNoLabel, -1, 100);
}else{
Plot(2, "", 1,styleArea+styleOwnScale | styleNoLabel, -1, 100);}


//================================================== ===================================
TimeFrameSet( 2*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M5H = TimeFrameExpand(BG2H,2*Interval(),expandFirst );
MM5H=TimeFrameExpand( BR2H,2*Interval(),expandFirst );
cM5H=TimeFrameExpand( C1H, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M15H = TimeFrameExpand(BG2H,4*Interval(),expandFirst );
MM15H=TimeFrameExpand(BR2H,4*Interval(),expandFirst );
cM15H=TimeFrameExpand( C1H,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M30H = TimeFrameExpand(BG2H,6*Interval(),expandFirst );
MM30H=TimeFrameExpand(BR2H,6*Interval(),expandFirst );
cM30H=TimeFrameExpand( C1H,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
H1H = TimeFrameExpand(BG2H ,8*Interval(),expandFirst );
HH1H=TimeFrameExpand( BR2H,8*Interval(),expandFirst );
Ch1H=TimeFrameExpand( C1H,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
H4H = TimeFrameExpand( BG2H,16*Interval(),expandFirst );
HH4H=TimeFrameExpand( BR2H,16*Interval(),expandFirst );
cH4H = TimeFrameExpand( C1H,16*Interval(),expandFirst );
RestorePriceArrays();

Comm2=("\n "+VR+ " - Phase in ")+"\n "+
EncodeColor(colorLightYellow)+(""+Interval(2)+":") +
WriteIf(Hac>HBG,EncodeColor(colorLime)+" UP",WriteIf(Hac < HBR,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+2*Interval()/60+"m:")+
WriteIf(cM5H>M5H,EncodeColor(colorLime)+" UP",WriteIf(cM5H<MM5H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+4*Interval()/60+"m:")+
WriteIf(cM15H>M15H,EncodeColor(colorLime)+" UP",WriteIf(cM15H<MM15H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+6*Interval()/60+"m:")+
WriteIf(cM30H>M30H,EncodeColor(colorLime)+" UP",WriteIf(cM30H<MM30H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+8*Interval()/60+"m:")+
WriteIf(Ch1H>H1H,EncodeColor(colorLime)+" UP",WriteIf(Ch1H<HH1H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+16*Interval()/60+"m: ")+
WriteIf(cH4H>H4H,EncodeColor(colorLime)+" UP",WriteIf(cH4H<HH4H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));


//============
//=====Title======================================== ================================================== ======
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorBlack)+ " " + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorBlue) +
" - " + Date() +" - "+ strWeekday +" - "+"\n" +EncodeColor(colorGreen) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n----------------------"+
EncodeColor(colorTan)+ Com+
EncodeColor(colorGreen)+Comm2+"\n---------system-------------"+"\n"+
EncodeColor(colorBlue)+
WriteIf (Buy AND Ref(shrt,-1), " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Buy AND Ref(NOTrade,-1), " GO LONG at "+C+" ","")+EncodeColor(colorRed)+
WriteIf (Sell AND Ref(NOTrade,-1), " GO Short at "+C+" ","")+
WriteIf (Sell AND Ref(Long,-1), " EXIT LONG / Reverse Signal at "+C+" ","")+
WriteIf (Cover, " cover "+C+" ",""));

_SECTION_END();
_SECTION_BEGIN("Background text");
SetChartOptions(0,chartShowArrows|chartShowDates);
C11=ParamColor("up panel",colorDarkOliveGreen );
C12=ParamColor("dn panel",colorDarkGrey );
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");
GfxSetBkMode( 0 );
GfxSetOverlayMode(1);
GfxGradientRect(0,0,pxwidth, pxheight, C11, C12 );
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( "ATR Stop&Reverse", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( " ", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
_SECTION_END();
 
#9
debashish neogi;804137]
Hi shruti.trader,thanks for posting error free afl which was earlier shared by S kumar. Please have a look at the below mentioned afl against query no.3.


Regards
Debashish






Well hello Debashish..

Above afl posted by you is not the one looking for..

Kindly look at the picture.. once again.


Regards
 

Similar threads