Correct the AFL

#1
showing error 32 in this afl ...



_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));
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();
//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
 

manojborle

Well-Known Member
#2
showing error 32 in this afl ...



_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));
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();
//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

Just remove the spaces and it should be okay
 
#4
/* 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

Ln:914,col:2 :Error 32. Syntax error, unexpected $end.Is there semicolon missing at the end of the previous line
 

manojborle

Well-Known Member
#5
/* 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

Ln:914,col:2 :Error 32. Syntax error, unexpected $end.Is there semicolon missing at the end of the previous line[/QUOTE
Just remove these lines if they are bit required.
As you can see // means it is a comment and not included in code.
 

hmsanil

Active Member
#6
here is the code

Code:
_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[i] = Null;
/*
// same
// HaOpen = (Ref(HaOpen, -1) + Ref(HaClose, -1)) / 2;
HaOpen[ 0 ] = HaClose[ 0 ];
for(i = 1; i < BarCount; i++) {
HaOpen[i] = (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));
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[i] = Null;
/*
// same
// HaOpen = (Ref(HaOpen, -1) + Ref(HaClose, -1)) / 2;
HaOpen[ 0 ] = HaClose[ 0 ];
for(i = 1; i < BarCount; i++) {
HaOpen[i] = (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[i])
pointer[i] = 1;
if (Cond2[i])
pointer[i] = 2;
if (Cond3[i])
pointer[i] = 3;
if (Cond4[i])
pointer[i] = 4;
if (Cond5[i])
pointer[i] = 5;
if (Cond6[i])
pointer[i] = 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;
}
 

Similar threads