Help needed for AFL

#1
--------------------------------------------------------------------------------

I need help for scanning/exploration. I need the scan to show only the last signals generated on an hourly scan i.e. suppose I run a scan at 1.20 P.M. for 21 period MA cross over for the day for hourly signals, I want the scan to show only the last signal generated, if any at 1 PM, though there may have been 2 or 3 crossovers during the day on the hourly charts at maybe 10 AM and again at 12 noon but I need the scan to show a buy or a sell only if a signal was generated at the end of the last hour of running the scan.
I will be very grateful if somebody can help me on this.
 
#2
Requesting for Help in fixing syntax error in an AFL - Nifty Trading System frm TJ

_SECTION_BEGIN("Advanced Rapid Fire NIFTY Trading System");
T=20;
K=((C-fun_M1(C,T,T+2))/fun_M1(C,T,T*2))*100;
Graph0=K;
Graph0Style=2+4;
//Graph0BarColor=IIf(KMA>0,5,4);
Graph0BarColor=IIf(K>0,colorGreen,colorRed);
GraphXSpace=5;

Title= "Symbol : "+ Name() + "\nThe Close is \n=> "+WriteVal(abs(K),format=1.2)+"%"+WriteIf(K>0, " above"," below")+" the 13 period EMA";

E30=((C-fun_E1(C,30,20))/fun_M1(C,30,15))*100;
Title="=> "+WriteVal(abs(E30),format=1.2)+" %"+WriteIf(E30>0," above"," below")+" 30 period EMA";

E50=((C-fun_E1(C,50,35))/fun_M1(C,50,20))*100;
Title="=> "+WriteVal(abs(E50),format=1.2)+" %"+WriteIf(E50>0," above"," below")+" 50 period EMA";

E200=((C-fun_E1(C,200,114))/fun_M1(C,200,105))*100;
Title="=> "+WriteVal(abs(E200),format=1.2)+" %"+WriteIf(E200>0," above"," below")+" 200 period EMA\n";


_SECTION_END();

_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", colorLightGrey ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

_SECTION_END();


_SECTION_BEGIN("Time Left");

function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}


RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;

if ( NewPeriod ){ Say( "New period" );
Plot( 1, "", colorYellow, styleArea | styleOwnScale, 0, 1 );
}
time = "Current Time: " + Now( 2 ) + "\n" + "Chart Interval: " + NumToStr( TimeFrame, 1.0 ) + " Seconds\n" + "Second Number: " + NumToStr( SecNumber, 1.0, False ) + "\n" + "Seconds Left: " + NumToStr( SecsLeft, 1.0, False ) + "\n" + "Seconds To Go: " + NumToStr( SecsToGo, 1.0, False );
GfxSetTextColor(colorBrown);
GfxSelectFont("Tahoma", 12,1200 );
GfxTextOut("Seconds To Go: " + NumToStr( SecsToGo, 1.0, False ), 35, 200);

printf("\n=====================");

_SECTION_END();


_SECTION_BEGIN("Color Scheme");

priceAxesWidth=0;
dateAxesHeight=0;
TitleHeight=0;

pxwidth = Status("pxwidth");
pxheight = Status("pxheight");

chartwidth = pxwidth-priceAxesWidth;
chartheight = pxheight-dateAxesHeight;

topColor=ParamColor("topColor",colorCustom4 );
centerColor=ParamColor("centerColor", ColorRGB(249,236,164));
botColor=ParamColor("BottomColor", colorCustom4);
priceAxesColor=ParamColor("priceAxesColor", colorWhite );
dateAxesColor=ParamColor("dateAxesColor", colorWhite);

relPos=Param("centerPosition%",50,0,100,1)/100;
centerHeight=chartheight*Param("centerHeight%",10, 0,100,1)/100;
x0=0;
y0=Max(TitleHeight,chartheight*relPos-centerHeight/2);
x1=chartwidth;
y1=Min(chartheight,chartheight*relPos+centerHeight/2);

GfxSetBkMode( 1 );
GfxSetOverlayMode(1);
GfxGradientRect(0,0,chartwidth,TitleHeight, colorWhite ,colorWhite);
GfxGradientRect(chartwidth,0,pxwidth,pxheight, priceAxesColor
,priceAxesColor);
GfxGradientRect(0,chartheight,chartwidth,pxheight, dateAxesColor
,dateAxesColor);
GfxGradientRect(x0,y0,x1,y1, CenterColor ,CenterColor );
GfxGradientRect(0,TitleHeight,chartwidth, y0,topColor, CenterColor );
GfxGradientRect(0,y1,chartwidth, chartheight, CenterColor ,botColor);

_SECTION_END();


_SECTION_BEGIN("Price");
SetChartBkGradientFill( ParamColor("BgTop",colorLightYellow),ParamColor("B gBottom",colorCustom4),ParamColor("Titleblock",col orLightYellow));
SetChartOptions(0,chartShowDates|chartShowArrows|C hartLogarithmic|chartWrapTitle);
GraphXSpace = 5;

_SECTION_END();

_SECTION_BEGIN("Bollinger Bands");
P = ParamField("Price field",-1);
Periods = Param("Bollinger", 10, 2, 100, 1 );
Width = Param("Width",0.55, 0, 10, 0.05 );
Plot(fun_BBTp(P,Periods,Width),"BBTop",colorGreen, styleLine|styleThick|styleDots);
Plot(fun_BBBt(P,Periods,Width),"BBBot",colorBrown, styleLine|styleThick|styleDots);
_SECTION_END();


_SECTION_BEGIN("Deep SL");

bts=ParamToggle("BTS","No|Yes" ,1);
btst=ParamToggle("DOT","No|Yes" ,1);
btsl=ParamToggle("Deep SL","No|Yes" ,1);
period=Param("Period",7,1,20,1);
x1=53;
x2=47;
d=2.3;
f=7;
s=1.5;
range=fun_A1(f,f-d);
Range1 = fun_A1(f,f-s)/d;
Range2 = (fun_A1(f,d-s)*s)/4;
range3=fun_A1(10,s-f);
R = ((fun_H1(H,period,period*s) - C) /(fun_H1 (H,period,period/d) -fun_L1 (L,period,d*s))) *-100;
E1= fun_E1(R,Period,x1+x2);
E2= fun_E1(E1,5,f*s);
Difference= E1 - E2;
ZeroLagE= E1 + Difference;
value2=abs(ZeroLagE);
function PercentR( periods )
{
return -100 * ( fun_H1( H, periods, periods*s) - C )/( fun_H1( H, periods, periods/d ) - fun_L1( L, periods, d*s ) );
}



_main_val=fun_MAIN(Range1,Range2,range3,value2,Clo se,H,L, period,BarCount,x1,x2);

tm=fun_return_tm();
bstop=fun_return_bstop();
sstop=fun_return_sstop();



//=============================SYSTEM=============== =======================

PlotShapes( shapeSmallCircle* (bts AND tm==1 AND Ref(tm,-1)==2),colorBlue, 0, bstop, -6 );
PlotShapes( shapeSmallCircle* (bts AND tm==2 AND Ref(tm,-1)==1), colorCustom12, 0, sstop, -6 );

Plot(IIf(btsl AND tm==1,bstop,Null),"",colorDarkGreen,styleLine|styl eThick|styleDots);

Plot(IIf(btsl AND tm==2,sstop,Null),"",colorPink,styleLine|styleThic k|styleDots);
_SECTION_END();

//#include <T3_include.AFL>;

TimeFrameSet(in5Minute*1);

periodsLR = Param("PCurve",2,1,1,0);

x=Param("Default1",14,3,50,1);
x1=fun_C1(x,24);
Y=Param("Default2",7,3,15,1);
Y2=fun_D1(x1,Y,Y-X);
Z=Param("Default3",3,3,9,1);
Z2=fun_M1(Y2,Z,Z-Y);

PCS = fun_PC1(Z2);
TCB = fun_TC1(Z2);


Cond5B = TCB ;

Cond5S = PCS ;

TimeFrameRestore();

Buy = Cond5B ;
Sell = Cond5S ;
Buy =ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Filter = Buy OR Sell;


printf("\nwww.EarnByNifty.com this commentary is automatically generated for information purpose.");

printf("\n=====================");


b=ExRem(Buy,Sell);
s=ExRem(Sell,Buy);


WriteIf(b>0,"\nThe last Automated Signal generated was a Buy @ "+P+"\non "+Date()+"\nLow : "+L,"");

WriteIf(s>0,"The last Automated Signal generated was a Sell @ "+P+"\non "+Date()+"\nHigh : "+H,"");

TimeFrameSet(inHourly);

x1=fun_C1(x,7);
Y2=fun_D1(x1,Y,Y*2);
Z2=fun_M1(Y2,Z,Z*Y);

CondHB = z2>Ref(z2,-1) ;
CondHS = Z2<Ref(Z2,1) ;

PCRH = fun_PC1(Z2);
TCRH = fun_TC1(Z2);


CondSR = TCRH ;

CondBR = PCRH ;

TimeFrameRestore();
WriteIf(CondHB>CondHS,"\nThe Hourly Trend is BULLISH, Buy Signals may be more profitable, Act Cautiously on Sell Signals",WriteIf((CondHB<CondHS),"The Hourly Trend is BEARISH, Sell Signals may be more profitable, Act Cautiously on Buy Signals",""));
WriteIf(CondSR,"\nReversal of Hourly BEARISH Trend","");
WriteIf(CondBR,"Reversal of Hourly BULLISH Trend","");
WriteIf(CondSR OR CondBR,"=====================","");
//printf("=====================");

TimeFrameSet(in15Minute*2);

x1=fun_C1(x,x-10);
Y2=fun_D1(x1,Y,Y+5);
Z2=fun_M1(Y2,Z,Z+2*Y);

CondHB = z2>Ref(z2,-1) ;
CondHS = Z2<Ref(Z2,1) ;

PCR30 = fun_PC1(Z2);
TCR30 = fun_TC1(Z2) ;
CondSR30 = TCR30 ;
CondBR30 = PCR30 ;
TimeFrameRestore();


printf("\nRSI : "+ WriteVal(RSI(14)));

printf("\n=====================");


p=ParamToggle("Support-Resistance ? ","No|Yes",0);
TimeFrameRestore();

//// ----------- Half Hourly - SUPPORT & RESISTANCE -------------
dH1=SelectedValue(TimeFrameGetPrice( "H", 2*in15Minute, -1 ));
dL1=SelectedValue(TimeFrameGetPrice( "L", 2*in15Minute, -1 ));
dC1=SelectedValue(TimeFrameGetPrice( "C", 2*in15Minute, -1 ));

dp = return_p(dH1,dL1,dC1)/3;
ds1 = return_s1_r1(dp,dH1);
dr1 = return_s1_r1(dp,dL1);
ds2 = return_s2_s3(dp,dH1,dL1);
ds3 = return_s2_s3(dS1,dH1,dL1);
dr2 = return_r2_r3(dp,dH1,dL1);
dr3 = return_r2_r3(dR1,dH1,dL1);

printf("\nHalf Hourly Support & Resistance : ");
printf("\nS1 : "+WriteVal(ds1));
printf("\nS2 : "+WriteVal(ds2));
printf("\nS3 : "+WriteVal(ds3));
printf("\nr1 : "+WriteVal(dr1));
printf("\nr2 : "+WriteVal(dr2));
printf("\nr3 : "+WriteVal(dr3));

printf("\n=====================");

if(p)
{

Plot(ds1,"Daily Support 1",colorBrightGreen,styleLine);
Plot(ds2,"Daily Support 2",colorDarkGreen,styleLine);
Plot(ds3,"Daily Support 3",colorDarkGrey,styleLine);

Plot(dr1,"Daily Resistance 1",colorRed,styleLine);
Plot(dr2,"Daily Resistance 2",colorDarkRed,styleLine);
Plot(dr3,"Daily Resistance 3",colorBrown,styleLine);

}

TimeFrameRestore();
//-----------------------------------------------------

//// ----------- Hourly - SUPPORT & RESISTANCE -------------
wH1=SelectedValue(TimeFrameGetPrice( "H", inHourly, -1 ));
wL1=SelectedValue(TimeFrameGetPrice( "L", inHourly, -1 ));
wC1=SelectedValue(TimeFrameGetPrice( "C", inHourly, -1 ));

wp = return_p(wH1,wL1,wC1)/3;
ws1 = return_s1_r1(wp,wH1);
wr1 = return_s1_r1(wp,wL1);
ws2 = return_s2_s3(wp,wH1,wL1);
ws3 = return_s2_s3(wS1,wH1,wL1);
wr2 = return_r2_r3(wp,wH1,wL1);
wr3 = return_r2_r3(wR1,wH1,wL1);

printf("\nHourly Support & Resistance : ");
printf("\nS1 : "+WriteVal(ws1));
printf("\nS2 : "+WriteVal(ws2));
printf("\nS3 : "+WriteVal(ws3));
printf("\nr1 : "+WriteVal(wr1));
printf("\nr2 : "+WriteVal(wr2));
printf("\nr3 : "+WriteVal(wr3));

printf("\n=====================");

TimeFrameRestore();
//-----------------------------------------------------

//// ----------- Two Hourly - SUPPORT & RESISTANCE -------------
mH1=SelectedValue(TimeFrameGetPrice( "H", 2*inHourly, -1 ));
mL1=SelectedValue(TimeFrameGetPrice( "L", 2*inHourly, -1 ));
mC1=SelectedValue(TimeFrameGetPrice( "C", 2*inHourly, -1 ));


mp = return_p(mH1,mL1,mC1)/3;
ms1 = return_s1_r1(mp,mH1);
mr1 = return_s1_r1(mp,mL1);
ms2 = return_s2_s3(mp,mH1,mL1);
ms3 = return_s2_s3(mS1,mH1,mL1);
mr2 = return_r2_r3(mp,mH1,mL1);
mr3 = return_r2_r3(mR1,mH1,mL1);

printf("\nTwo Hourly Support & Resistance : ");
printf("\nS1 : "+WriteVal(ms1));
printf("\nS2 : "+WriteVal(ms2));
printf("\nS3 : "+WriteVal(ms3));
printf("\nr1 : "+WriteVal(mr1));
printf("\nr2 : "+WriteVal(mr2));
printf("\nr3 : "+WriteVal(mr3));

TimeFrameRestore();


Plot( 2,"\Hourly Trend",IIf( Flip(CondSR,CondBR), colorGreen, IIf( Flip(CondBR,CondSR), colorRed, colorOrange)),styleOwnScale|styleArea|styleNoLabel , -0.75, 100 );
Plot( 3.5,"\30min Trend",IIf( Flip(CondSR30,CondBR30), colorDarkBlue, IIf( Flip(CondBR30,CondSR30), colorTan, colorOrange)),styleOwnScale|styleArea|styleNoLabel , -0.85, 100 );
Plot( 5,"\Buy/Sell Ribbon",IIf( Flip(Buy,Sell), colorBrightGreen, IIf( Flip(Sell,Buy), colorPink, colorOrange )),styleOwnScale|styleArea|styleNoLabel, -0.75, 100 );


TimeFrameSet(in5Minute);
shape = Buy * shapeUpTriangle + Sell * shapeDownTriangle;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), IIf( Buy, Low, High ) );
TimeFrameRestore();
 

preethnfo

Active Member
#3
Re: Help needed for AFL -want to get this picture into AFL

please help to get this pictures into AFL code. it shows some words like v-trend wma,ema, 5.5 min, etc, don't know which are these or anyother things used in this picture. dates of charts are october nifty.


 
#4
_SECTION_BEGIN("MA Diff");
T=26;
KMA=((C-MA(C,T))/MA(C,T))*100;
Graph0=KMA;
Graph0Style=2+4;
Graph0BarColor=IIf(KMA>0,5,4);
GraphXSpace=5;

_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

//------------------------------------------------------------------------------

_SECTION_BEGIN("ZIG-ZAG");
P = ParamField( "Price field" );
change = Param("% change",5,0.1,25,0.1);
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
_SECTION_END();

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


Cond1 = Cross(MACD(r1,r2),Signal(r1,r2,r3));

Cond3 = Zig(C,z)>Ref(Zig(C,z),-4);
Buy = Cond1 AND Cond3;

Cond4 = Cross(Signal(r1,r2,r3),MACD(r1,r2));

Cond6 = Zig(C,z)<Ref(Zig(C,z),-4);
Sell = Cond4 AND Cond6;
Trigger = WriteIf(Buy, "Buy", "") + WriteIf(Sell, "Sell", "");

_N(Title = StrFormat("{{NAME}} {{DATE}} {{INTERVAL}}: O=%1.2f, H=%1.2f, L=%1.2f, C=%1.2f, V=%1.0f\n{{VALUES}}", O, H, L, C, V));

BG = IIf(Buy, colorPaleGreen, IIf(Sell, colorRose, colorDefault));
FG = IIf(Buy, colorDarkGreen, IIf(Sell, colorDarkRed, colorDefault));

if(Status("action") == actionIndicator)
{
Plot(C, "", colorGrey50, styleBar);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-30);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-30);

}

//------------------------------------------------------------------------------------------------
if(Status("action") == actionExplore)

Filter = Buy OR Sell;
SetOption("NoDefaultColumns", True);

AddTextColumn(Name(), "Symbol", 77, FG, BG, 120);
AddColumn(DateTime(), "Date", formatDateTime, FG, BG, 100);
AddColumn(TimeNum() ,"Time",1);
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
AddColumn(V, "Volume");
AddColumn(Ref(V,-1),"P-Vol");
AddColumn(V/Ref(V,-1)*100,"Increase in Vol");
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );

shape = Buy * shapeHollowUpTriangle + Sell * shapeHollowDownTriangle;

PlotShapes( shape, IIf( Buy, colorBlue, colorBlue ), 0, IIf( Buy, Low, High ) );

GraphXSpace = 7;

GraphXSpace = 7;
_SECTION_END();

_SECTION_BEGIN("EMA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
_SECTION_END();


_SECTION_BEGIN("Background text");
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( " ", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
//Second phase starts Here
//File: BHS Chart
_SECTION_BEGIN("BHS1.02");
SetChartBkColor(ParamColor("Outer panel color ",colorLightYellow));
SetChartBkColor(ParamColor("BackGround Color", colorBlack));
pShowtradeLines = ParamToggle("Show Trade Lines", "No|Yes", 1);
pShowMarkers = ParamToggle("Show Markers", "No|Yes", 1);
synch=ParamToggle("Synchronize buy/short with foreign index", "No|Yes", 1);
Volmin=Param("Volume minimum",5000,0,10000000,50);
Volmax=Param("Volume maximum",1000000,0,10000000,50);
priceRL=Param("Price Range Min",150,1,20000,1);
priceRH=Param("Price Range Max",3000,1,20000,1);
PercChangemin=Param("Percentage Change Min set", -25, -100, 100, 0.1);
PercChangemax=Param("Percentage Change Max set", 25, -100, 100, 0.1);
PerctakeProfit=Param("Take Profit Percent Set",0.5,0.3,30,0.1);
PercStoploss=Param("StopLoss Percent Set",1,0.2,5,0.1);

PlotOHLC(Open,High,Low,Close,"",colorWhite,styleCandle);
Bars = 0;
xpdh = 90;

{
Plot_Range = (TimeNum() >= 85500 AND TimeNum()<= 153500) AND (DateNum()==LastValue(DateNum()));
FH_Range = (TimeNum() >= 085500 AND TimeNum()<= 093000) AND (DateNum()==LastValue(DateNum()));

FH_Prices = High * FH_Range;
FH_Marker = BarsSince(FH_Range>0);

Num_Bars = 36000 / Interval(1);

TimeFrameSet(inDaily);
TOP_ = Open;
PDH_ = Ref(High,-1);
PDL_ = Ref(Low,-1);
PDO_ = Ref(Open,-1);
PDC_ = Ref(Close,-1);
PDM_ = (PDH_+PDL_)/2;
TimeFrameRestore();

isAll = True;
isRth = TimeNum() >= 085400 AND TimeNum() <= 093000;
isdRth = TimeNum() >= 085400 AND TimeNum() <= 160000;

aRthL = IIf(isRth, L, 1000000);
aRthH = IIf(isdRth, H, Null);
aRthLd = IIf(isdRth, L, 1000000);

TOP = TimeFrameExpand(TOP_,inDaily,expandFirst);
PDH = TimeFrameExpand(PDH_,inDaily,expandFirst);
PDL = TimeFrameExpand(PDL_,inDaily,expandFirst);
PDO = TimeFrameExpand(PDO_,inDaily,expandFirst);
PDC = TimeFrameExpand(PDC_,inDaily,expandFirst);
PDM = TimeFrameExpand(PDM_,inDaily,expandFirst);
FHH = Ref(HHV(High*FH_Range,Num_Bars),-FH_Marker);
FHL = TimeFrameCompress( aRthL, inDaily, compressLow );
FHL = TimeFrameExpand( FHL, inDaily, expandFirst );
DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
DayL = TimeFrameExpand( DayL, inDaily, expandFirst );


FC1=((PDH-PDL)*0.433);
FC2=((PDH-PDL)*0.7666);
FC3=((PDH-PDL)*1.355);
FC4=(FHH-FHL);

A=IIf((FC4<=FC1+PDH*0.005),FC1,0);
B=IIf((FC4<=FC2+PDH*0.005 AND FC4>FC1+PDH*0.005),FC2,0);
Cl=IIf((FC4<=FC3 AND FC4>FC2+PDH*0.005),FC3,0);
AF=(A+B+Cl);

//foreign
_SECTION_BEGIN ("foreign Index bar graph");
Vr=ParamList("Index",List = "^NSEI,^NSEBANK,^CNXIT,^NSMIDCP,RELIANCE.NS,SB IN.N S",0);
SetForeign(Vr);
HaC =(O+H+L+C)/4;
HaO = AMA( Ref( HaC, -1 ), 0.5 );
HaH = Max( H, Max( HaC, HaO) );
HaL = Min( L, Min( HaC, HaO) );
BG3=HHV(LLV(HaL,4)+ATR(4),8);
BR3=LLV(HHV(HaH ,4)-ATR(4),8);
co = IIf(Hac>BG3 ,colorBrightGreen,IIf(Hac < BR3,colorRed,colorGrey50));
Plot(4, "", Co,styleArea+styleOwnScale | styleNoLabel, -1, 100);
RestorePriceArrays();
_SECTION_END();

BuyPrice=(DayL+AF);
BuyTP1=(BuyPrice+(BuyPrice*(PerctakeProfit/100)));
BuyTP2=(C>=BuyTP1);
SellPrice=(DayH-AF);
SellTP1=(SellPrice-(SellPrice*(PerctakeProfit/100)));
SellTP2=(C<=SellTP1);
percchange=(((C-TOP)/TOP)*100);
Vol=(V>=Volmin AND V<=Volmax);
Percentage=(percchange>=PercChangemin AND percchange<=PercChangemax);
prc=(C>=priceRL AND C<=priceRH);
BuyStop1=(BuyPrice-(BuyPrice*(PercStoploss/100)));
BuyStop2=IIf((BuyStop1<=SellPrice) AND SellPrice<=BuyPrice,SellPrice,BuyStop1);
SellStop1=(SellPrice+(SellPrice*(PercStoploss/100)));
SellStop2=IIf((SellStop1>=BuyPrice) AND SellPrice<=BuyPrice, BuyPrice,SellStop1);

BuyStop=IIf((Buy AND NOT BuyTP2),BuyStop2,Null);
BuyTP=IIf(Buy AND NOT BuyStop,BuyTP2,Null);

Bars = BarsSince(TimeNum() >= 85400 AND TimeNum() < 092900);
x0 = BarCount-LastValue(Bars);
x1 = BarCount-1;
TOP_Line = LineArray(x0,LastValue(TOP),x1,LastValue(TOP),0);
PDH_Line = LineArray(x0,LastValue(PDH),x1,LastValue(PDH),0);
PDL_Line = LineArray(x0,LastValue(PDL),x1,LastValue(PDL),0);
PDC_Line = LineArray(x0,LastValue(PDC),x1,LastValue(PDC),0);
PDM_Line = LineArray(x0,LastValue(PDM),x1,LastValue(PDM),0);
FHH_Line = LineArray(x0,LastValue(FHH),x1,LastValue(FHH),0);
FHL_Line = LineArray(x0,LastValue(FHL),x1,LastValue(FHL),0);
BuyPriceline=LineArray(x0,LastValue(BuyPrice),x1,LastValue(BuyPrice),0);
BuyStopline=LineArray(x0,LastValue(BuyStop2),x1,LastValue(BuyStop2),0);
BuyTPline=LineArray(x0,LastValue(BuyTP1),x1,LastValue(BuyTP1),0);
SellPriceline=LineArray(x0,LastValue(SellPrice),x1 ,LastValue(SellPrice),0);
SellStopline=LineArray(x0,LastValue(SellStop2),x1, LastValue(SellStop2),0);
SellTPline=LineArray(x0,LastValue(SellTP1),x1,LastValue(SellTP1),0);
DayHline=LineArray(x0,LastValue(DayH),x1,LastValue (DayH),0);
DayLline=LineArray(x0,LastValue(DayL),x1,LastValue (DayL),0);


Plot(IIf(pShowtradeLines,BuyStopline,Null),"BuySto p",colorBrightGreen,styleDots|styleNoRescale| styleNoLine);
Plot(IIf(pShowtradeLines,SellPriceline,Null),"Shor t Here",colorRed,styleDots|styleNoRescale);
PlotShapes(IIf(pShowMarkers AND Buy, shapeHollowUpArrow, Null), colorDarkGreen, 0,L,Offset=-30);

if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "BHS_2 System" + " - " + Name() + " - " + EncodeColor(colorYellow)+ Interval(2) + EncodeColor(colorYellow) +
" - " + Date() +" - "+ EncodeColor(colorYellow) + "-Open="+WriteVal(O,1) + EncodeColor(colorYellow) + "- High= "+ WriteVal(H,1)+ EncodeColor(colorYellow) + "- Close= "+ WriteVal(C,1)+ EncodeColor(colorYellow) + "- Vol= "+ WriteVal(V,1)+ WriteIf(Percchange, " % Change = "+(Percchange)+" ","")+("\n")+
" Previous DayHigh="+WriteVal(PDH,1)+", Previous DayLow="+WriteVal(PDL,1)+", Today High="+WriteVal(DayH,1)+", Todays Low="+WriteVal(DayL,1)+
Comm2=("\n "+Vr+" Phase: ")+
WriteIf(Hac>BG3,EncodeColor(colorBrightGreen)+"+Up ",
WriteIf(Hac<BR3,EncodeColor(colorRed)+"-Down",EncodeColor(colorLightYellow)+"< Flat >")));

GfxSetOverlayMode( mode = 0 );
GfxSelectPen( colorLightBlue, 3 );
GfxSelectSolidBrush( colorLightYellow );
GfxRoundRect( 20, 55, 180, 175, 15, 15 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 10, 700, False );
GfxSetTextColor( colorBrown );
GfxSetTextAlign(0);
GfxTextOut( WriteIf(Buystop2, "TRP level: "+(Buystop2),""), 30, 60);
GfxTextOut( WriteIf(BuyPrice, "Buy Above: "+(BuyPrice),""), 30, 75);
GfxTextOut( WriteIf(BuyStop2, "Long SL: "+(BuyStop2),""), 30, 90);
GfxTextOut( WriteIf(BuyTP1 , "Long Target 1: "+(BuyTP1),""), 30, 105);
GfxTextOut( WriteIf(SellPrice, "Sell Below: "+(SellPrice),""), 30, 120);
GfxTextOut( WriteIf(SellStop2, "Short SL: "+(SellStop2),""), 30, 135);
GfxTextOut( WriteIf(SellTP1, "Short Target: "+(SellTP1),""), 30, 150);

AddColumn(V,"Volume",1.0);
AddColumn(Percchange,"Change %",1.2);
AddColumn(BuyPrice,"Buy at",1.2);
AddColumn(BuyStop,"Buy Stop at",1.2);
AddColumn(BuyTP1,"Buy Profit at",1.2);
AddColumn(SellPrice,"Short at",1.2);
AddColumn(SellTP1,"Short profit at",1.2);

}

_SECTION_END();

_SECTION_BEGIN("short signal");
HaClose=(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
BG2=HHV(LLV(Low,4)+ATR(4),8);
BR2=LLV(HHV(High,4)-ATR(4),8);
SetBarFillColor=( IIf(O <C, colorSeaGreen,colorOrange) );
k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);
j=HaClose;
nm= (H-L);
rfsctor = WMA(nm, PER);
revers = K * rfsctor;
Trend = 1;
NW[0] = 0;
for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j < NW[i-1])
{
Trend = -1;
NW = j + Revers;
}
else
{
Trend = 1;
if((j - Revers) > NW[i-1])
{
NW = j - Revers;
}
else
{
NW = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j > NW[i-1])
{
Trend = 1;
NW = j - Revers;
}
else
{
Trend = -1;
if((j + Revers) < NW[i-1])
{
NW = j + Revers;
}
else
{
NW = NW[i-1];
}
}
}
}

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

Buy=Cross(j,nw);
Short=Cross(nw,j);
Sell=Cross(nw,j);
Cover=Cross(j,nw);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,halow,-30);
PlotShapes(IIf(Sell, shapeHollowDownTriangle, shapeNone),colorWhite, 0,hahigh,-15);
PlotShapes(IIf(Cover, shapeHollowUpTriangle, shapeNone),colorWhite, 0,halow,-15);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,hahigh,-30);
//-----------end--------------

//ADDED PIVOTS LINES LATER

//---- pivot points
DayH = TimeFrameGetPrice("H", inDaily, -1);// yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1);//low
DayC = TimeFrameGetPrice("C", inDaily, -1);//close
DayO = TimeFrameGetPrice("O", inDaily);// current day open
HiDay = TimeFrameGetPrice("H", inDaily);
LoDay = TimeFrameGetPrice("L", inDaily);
PP = (DayH + DayL + DayO + DayO) / 4 ;
R1 = (2 * PP) - DayL;
S1 = (2 * PP) - DayH;
R2 = PP + R1 - S1;
S2 = PP + S1 - R1;
R3 = R2 + (R1 - PP);
S3 = S2 - (PP - S1);
style = styleLine | styleThick + styleNoRescale;
rcolor = colorBlue;
scolor = colorRed;
pcolor = colorWhite;
Plot(R1, "R1",rcolor,style);
Plot(S1, "S1",scolor,style);
Plot(R2, "R2",rcolor,style);
Plot(S2, "S2",scolor,style);
Plot(PP, "PP",pcolor,style);
Plot(s3, "S3", scolor, style);
Plot(R3, "R3", rcolor, style);
RangeTitle = EncodeColor(colorWhite) + "Day Range= " + EncodeColor(colorWhite);


// added later

////////////////////////////////////
// CCI Price Panel For Amibroker
// Coded by Crasher_FL
// Modified by Dennis
///////////////////////////////
// Tic/PIP values: YM=1.0, ER2=0.10, NQ=0.25, EUR/USD=.0001, USD/JPY=0.01, Stocks=0.01
///////////////////////////////

// Background color
//SetChartBkColor(ParamColor("Panel color ",colorPaleBlue));

TicDiv= Param("Tic or PIP value",1,0,1000000);
Titledisplay= ParamToggle("Display pivot stats","No|Yes",1);

//barcolor = IIf(C > Open, colorWhite, IIf(C == Open, colorWhite, colorWhite));
//Plot( C, "Close", barcolor,styleCandle | styleNoLabel);

EMA34 = EMA(C,34);
LSMA = LinearReg(C,25);
PI = atan(1.00) * 4;
periods = 30;
HighHigh = HHV(H, periods);
LowLow = LLV(L, periods);
range = 25 / (HighHigh - LowLow) * LowLow;
x1_EMA34 = 0;
x2_EMA34 = 2;
y1_EMA34 = 0;
y2_EMA34 = (Ref(EMA34, -2) - EMA34) / Avg * range;
c_EMA34 = sqrt((x2_EMA34 - x1_EMA34)*(x2_EMA34 - x1_EMA34) + (y2_EMA34 -
y1_EMA34)*(y2_EMA34 - y1_EMA34));
angle_EMA34 = round(180 * acos((x2_EMA34 - x1_EMA34)/c_EMA34) / PI);
TitleAngleEMA34 = EncodeColor(colorWhite) + "\nEMA34 angle = ";
angle_EMA34 = IIf(y2_EMA34 > 0, - angle_EMA34, angle_EMA34);
ColorANGLE_EMA = IIf(angle_EMA34 >=5,colorTurquoise,
IIf(angle_EMA34 <5 AND angle_EMA34 >=3.57,colorDarkGreen,
IIf(angle_EMA34 <3.57 AND angle_EMA34 >=2.14,colorPaleGreen,
IIf(angle_EMA34 <2.14 AND angle_EMA34 >=.71,colorLime,
IIf(angle_EMA34 <=-1*5,colorDarkRed,
IIf(angle_EMA34 >-1*5 AND angle_EMA34 <=-1*3.57,colorRed,
IIf(angle_EMA34 >-1*3.57 AND angle_EMA34 <=-1*2.14,colorOrange,
IIf(angle_EMA34 >-1*2.14 AND angle_EMA34 <=-1*.71,colorLightOrange,colorYellow))))))));
Plot(EMA34,"EMA 34",ColorANGLE_EMA, styleLine | styleThick | styleNoLabel );
Plot(lsma,"LSMA 25",IIf(C > lsma,colorBrightGreen,
IIf(C == lsma,colorTeal,colorRed)), styleLine | styleThick |styleNoLabel);


/*Gann HiLo*/

Hld = IIf(C > Ref(MA(H, 7), -1), 1, IIf(C < Ref(MA(L, 7), -1), -1, 0));
Hlv = ValueWhen(Hld != 0, Hld, 1);
Hilo = IIf(Hlv == -1, MA(H, 7), MA(L, 7));
Trigger = IIf(C>Hilo, colorBlue, colorPink);
//Plot(Hilo,"HiLo",Trigger,styleStaircase);


Title = EncodeColor(colorWhite)+ Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorTan) +
" - " + Date() +" - "+"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+ "Cl-"+C+" "+ "\n"+ "Vol= "+ WriteVal(V)+",
Today High="+WriteVal(DayH,2)+", Todays Low="+WriteVal(DayL,2);
/////////////Reply With Quote



//R2=> Heinkin Ashi Price Action
//R1=> Decorative Works
_SECTION_BEGIN("Chart Settings");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("Outer Panel",colorPaleBlue));
SetChartBkGradientFill(ParamColor("Upper Chart",1),ParamColor("Lower Chart",23));
GraphXSpace=Param("GraphXSpace",10,0,100,1);
dec = (Param("Decimals",2,0,7,1)/10)+1;
bi = BarIndex();
Lbi = LastValue(BarIndex());
sbi = SelectedValue(bi);
x1= BarCount-1;
Title = EncodeColor(55)+ Title = Name() + " " + EncodeColor(32) + Date() +
" " + EncodeColor(5) + "{{INTERVAL}} " +
EncodeColor(55)+ " Open = "+ EncodeColor(52)+ WriteVal(O,dec) +
EncodeColor(55)+ " High = "+ EncodeColor(5) + WriteVal(H,dec) +
EncodeColor(55)+ " Low = "+ EncodeColor(32)+ WriteVal(L,dec) +
EncodeColor(55)+ " Close = "+ EncodeColor(52)+ WriteVal(C,dec)+
EncodeColor(55)+ " Volume = "+ EncodeColor(52)+ WriteVal(V,1);
_SECTION_END();

_SECTION_BEGIN("MPLite Kaka");
//PlotOHLC(O,H,L,C,"Price",IIf(C>O,colorGreen,colorR ed),styleCandle);

function Lastthursday()
{
Daysinmonth=IIf(Month()==1 OR Month()==3 OR Month()==5 OR Month()==7 OR Month()==8 OR Month()==10 OR Month()==12,31,30);
Daysinmonthfeb=IIf(Year()%4 == 0 AND Year()%100!=0,29,28);
Daysinmonthfinal=IIf(Month()==2,Daysinmonthfeb,Daysinmonth);
returnvalue=IIf(Daysinmonthfinal-Day()<7 AND DayOfWeek()==4,1,IIf(Daysinmonthfinal-Day()<8 AND DayOfWeek()==3 AND Ref(DayOfWeek(),1)!=4,1,0));
return returnvalue;
}

FirstVisibleBar = Status( "FirstVisibleBar" );
Lastvisiblebar = Status( "LastVisibleBar" );

totalVisible=Lastvisiblebar-FirstVisibleBar;
//if(totalVisible<1500){

//Den = Param("Density", 1, 0.1, 10, 0.1);
percent=Param("Value Area", 70, 1, 100, 1);
Type=ParamList("Type","Price Profile|Volume Profile");
Period= ParamList("Base","Hourly|Daily|Weekly|Monthly|Last thursday|Yearly",1);
x_scale=Param("Horizontal_scale", 2, 0, 10, 0.1);
EnMP2= ParamStyle("Style",styleLine|styleNoLabel,maskAll) ;
styleLines=styleDots;
ViewYvalues= ParamToggle("Show Yesterdays Values", "No|Yes",1);
ViewVlines= ParamToggle("Show Vertical Base Lines", "No|Yes",1);
Viewvalues= ParamToggle("Show Values", "No|Yes",0);
ViewVpoc= ParamToggle("Show Virgin POC", "No|Yes",1);
ViewTPO=ParamToggle("Show TPO Count", "No|Yes",0);

if(Period=="Hourly"){
BarsInDay = BarsSince(Hour() != Ref(Hour(), -1));Bot = TimeFrameGetPrice("L", inHourly, 0);Top = TimeFrameGetPrice("H", inHourly, 0);Vol = TimeFrameGetPrice("V", inHourly, 0);
}
if(Period=="Daily" ){//OR Interval()==3600
BarsInDay = BarsSince(Day() != Ref(Day(), -1));Bot = TimeFrameGetPrice("L", inDaily, 0);Top = TimeFrameGetPrice("H", inDaily, 0);Vol = TimeFrameGetPrice("V", inDaily, 0);
}
if(Period=="Weekly" OR Interval()==24 * 3600 ){
BarsInDay = BarsSince(DayOfWeek() < Ref( DayOfWeek(), -1 ));Bot = ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2 ,LLV(L,BarsInDay),0);Top =ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2,HHV(H,BarsInDay),0);Vol = TimeFrameGetPrice("V", inWeekly, 0);
}
if(Period=="Monthly" ){
BarsInDay = BarsSince(Month() != Ref(Month(), -1));Bot = TimeFrameGetPrice("L", inMonthly, 0);Top = TimeFrameGetPrice("H", inMonthly, 0);Vol = TimeFrameGetPrice("V", inMonthly, 0);
}

if(Period=="Lastthursday" ){
BarsInDay = BarsSince(Lastthursday()==1 AND Ref(Lastthursday(), -1)==0);Bot = ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2 ,LLV(L,BarsInDay),0);Top =ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2,HHV(H,BarsInDay),0);Vol = TimeFrameGetPrice("V", inMonthly, 0);
}

if(Period=="Yearly" ){
BarsInDay = BarsSince(Year() != Ref(Year(), -1));Bot = TimeFrameGetPrice("L", inYearly, 0);Top = TimeFrameGetPrice("H", inYearly, 0);Vol = TimeFrameGetPrice("V", inYearly, 0);
}

Range = Top-Bot;
coverage=LastValue(ATR(10));

den=(coverage/10);

//multiplier=IIf(round(totalVisible)>500,IIf(round(t otalVisible)>1000,3,2),1);

HaClose = (O + H + L + C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
xDiff = (HaHigh - Halow) * 10000;
barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle );

multiplier=IIf(round(totalVisible)/300<1,1,round(totalVisible)/300);


if(ViewVlines==1)
{
Plot(BarsInDay==0, "", ParamColor("Base Line Color",colorDarkGrey), styleHistogram | styleOwnScale | styleLine | styleNoLabel);
}


relTodayRange = 0;
x=0;
basey=0;
basex=0;
newday=0;
total=0;
shiftup=0;
shiftdn=0;
Line=Null;
Voloumeunit=0;


for ( i = FirstVisibleBar; i <Lastvisiblebar AND i<BarCount-1 ; i++ )
{
if(BarsInDay==0)
{t=BarsInDay[i-1];



//////////////////////////////////
poc=0;pocj=0;
midrange = int(relTodayRange/2)+1;


for (j=1; j<= relTodayRange+1 ; j++)
{
if(poc < x[j])
{
poc=x[j]; pocj=j;}
else if(poc == x[j])
{
if (abs(midrange-j)< abs(midrange-pocj)){
poc = x[j]; pocj = j;
}
}

}

for ( n = 1; n <= relTodayRange; n++ )
{
total[n]=x[n]+total[n-1];
}

Value_area=(total[relTodayRange]*percent)/100;


for ( a = 1; a <= relTodayRange; a++ )
{
if(pocj-a>0 AND pocj+a<relTodayRange)
{
if(poc+total[pocj+a]-total[pocj]+(total[pocj]-poc)-total[pocj-(a+1)]>=Value_area) {shiftup=a; shiftdn=a; break;}
}
else if(pocj-a<1 )
{
if(poc+total[pocj+a]-total[pocj]+(total[pocj]-poc)>=Value_area){shiftup=a; shiftdn=pocj; break;}
}
else if(pocj+a>relTodayRange )
{
if(poc+total[relTodayRange]-total[pocj]+(total[pocj]-poc)-total[pocj-(a+1)] >=Value_area){shiftup=floor(relTodayRange)-pocj; shiftdn=a+1; break;}
}
}


if(ViewVpoc==1)
{
Virginpoc=basey+pocj*den;
newi=0;
for( j = i+1; j <= (BarCount - 1) ; j++ )
if( L[j] < Virginpoc AND H[j]>Virginpoc )
{newi=j;break;}
else{newi=BarCount;}
vishycolor=IIf(BarCount%2==0,colorRed,colorBlue);
Plot(LineArray(basex,basey+pocj*den,newi,basey+pocj*den),"",vishycolor ,styleLine|styleNoRescale);
//Plot(LineArray(basex,basey+pocj*den,newi,basey+pocj*den),"",colorYello w,styleLine|styleNoRescale);
}

Vah = LineArray(baseX, baseY+(pocj+shiftup)*den, i, baseY+(pocj+shiftup)*den);
Val = LineArray(baseX, baseY+(pocj-shiftdn)*den, i, baseY+(pocj-shiftdn)*den);
pocline=LineArray(basex,basey+pocj*den,basex+poc,basey+pocj*den);

//Plot(Vah,"",ParamColor("Color_VAH_Line", colorBlueGrey),styleLine|styleNoRescale);
//Plot(Val,"",ParamColor("Color_VAL_Line", colorBlueGrey),styleLine|styleNoRescale);

Vahn = LineArray(i, baseY+(pocj+shiftup)*den, i+t, baseY+(pocj+shiftup)*den);
pocn = LineArray(i, baseY+(pocj)*den, i+t, baseY+(pocj)*den);
Valn = LineArray(i, baseY+(pocj-shiftdn)*den, i+t, baseY+(pocj-shiftdn)*den);

Plot(pocline,"",ParamColor("Color_POC_Line",colorDarkBlue),styleLine|styleNoRescale|styleNoLabel);

if(ViewYvalues==1)
{
Plot(Vahn,"",ParamColor("YVAH",colorBrightGreen),styleDashed|styleNoRescale);
Plot(Valn,"",ParamColor("YVAL",colorYellow),styleDashed|styleNoRescale);
Plot(pocn,"",ParamColor("YPOC",colorDarkRed),styleDashed|styleNoRescale);

}
//PlotOHLC(Vahn,Vahn,Valn,Valn,"",colorPink,styleClo ud|styleOwnScale);


if(ViewTPO==1)
{
nnn=HHV(H,BarsInDay);
PlotText(""+(total[relTodayRange]-total[pocj]),basex,nnn,colorLightGrey);
PlotText(""+(total[pocj-1]),basex,basey-den,colorLightGrey);
}

if(Viewvalues==1)
{
PlotText(""+((basey+pocj*den)),baseX,basey+pocj*den,colorWhite,colorDarkGrey);
PlotText(""+((baseY+(pocj+shiftup)*den)),baseX,baseY+(pocj+shiftup)*den,colorWhite,colorDarkGrey );
PlotText(""+((baseY+(pocj-shiftdn)*den)),baseX,baseY+(pocj-shiftdn)*den,colorWhite,colorDarkGrey);
}


for (p = 0; p <= relTodayRange+1; p=p+multiplier)
{
if(P>0){
line = LineArray(baseX, baseY+(p)*Den, baseX+x[p], baseY+(p)*Den);

}

Plot(line,"",IIf(p>(pocj+shiftup),ParamColor("Colo r_Above_VA", colorDarkRed),IIf(p<=(pocj+shiftup)AND p>=(pocj-shiftdn),ParamColor("Color_VA", colorDarkBlue),ParamColor("Color_Below_VA", colorDarkRed))) , EnMP2);


}

Plot(pocline,"",ParamColor("Color_POC_Line",colorDarkRed),styleLine|styleNoRescale);

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

basex=0;
x=0;
Basex=i;
baseY=Bot;
relTodayRange=Range/Den;
Voloumeunit=Vol/LastValue(BarsInDay);

}

for (j=0; j<= relTodayRange ; j++)
{
if (L <= Bot+j*Den AND H >= Bot+j*Den )
{
if(Type=="Price Profile"){x[j]=(x[j])+x_scale;}
else if(Type=="Volume Profile"){x[j]=x[j]+round(V/Voloumeunit)+1;}
}
}
}


//////////////////////////////////
poc=0;pocj=0;
midrange = int(relTodayRange/2)+1;

for (j=1; j<= relTodayRange+1 ; j++)
{
if(poc < x[j])
{
poc=x[j]; pocj=j;}
else if(poc == x[j])
{
if (abs(midrange-j)< abs(midrange-pocj)){
poc = x[j]; pocj = j;
}
}

}

for ( n = 1; n <= relTodayRange; n++ )
{
total[n]=x[n]+total[n-1];
}

Value_area=(total[relTodayRange]*percent)/100;


for ( a = 1; a <= relTodayRange; a++ )
{
if(pocj-a>0 AND pocj+a<relTodayRange)
{
if(poc+total[pocj+a]-total[pocj]+(total[pocj]-poc)-total[pocj-(a+1)]>=Value_area) {shiftup=a; shiftdn=a; break;}
}
else if(pocj-a<1 )
{
if(poc+total[pocj+a]-total[pocj]+(total[pocj]-poc)>=Value_area){shiftup=a; shiftdn=pocj; break;}
}
else if(pocj+a>relTodayRange )
{
if(poc+total[relTodayRange]-total[pocj]+(total[pocj]-poc)-total[pocj-(a+1)] >=Value_area){shiftup=floor(relTodayRange)-pocj; shiftdn=a+1; break;}
}
}

Vah = LineArray(baseX, baseY+(pocj+shiftup)*den, i, baseY+(pocj+shiftup)*den);
Val = LineArray(baseX, baseY+(pocj-shiftdn)*den, i, baseY+(pocj-shiftdn)*den);
pocline=LineArray(basex,basey+pocj*den,basex+poc,basey+pocj*den);

if(ViewTPO==1)
{
PlotText(""+(total[relTodayRange]-total[pocj]),basex,top,colorLightGrey);
PlotText(""+(total[pocj-1]+x_scale),basex,basey-den,colorLightGrey);
}

if(Viewvalues==1)
{
PlotText(""+((basey+pocj*den)),baseX,basey+pocj*den,colorWhite,colorDarkGrey);
PlotText(""+((baseY+(pocj+shiftup)*den)),baseX,baseY+(pocj+shiftup)*den,colorWhite,colorDarkGrey );
PlotText(""+((baseY+(pocj-shiftdn)*den)),baseX,baseY+(pocj-shiftdn)*den,colorWhite,colorDarkGrey);
}

for (p = 0; p <= relTodayRange+1; p=p+multiplier)
{
line = LineArray(baseX, baseY+p*Den, baseX+x[p], baseY+p*Den);

Plot(line,"",IIf(p>(pocj+shiftup),ParamColor("Colo r_Above_VA", colorGrey40),IIf(p<=(pocj+shiftup)AND p>=(pocj-shiftdn),ParamColor("Color_VA", colorBlueGrey),ParamColor("Color_Below_VA",colorGrey40))),EnMP2);

Plot(pocline,"",ParamColor("Color_POC_Line",colorYellow),styleLine|styleNoRescale|styleNoLabel);
}
_SECTION_END();

_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorDarkGreen), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram ), 2 );
_SECTION_END();
//SetChartOptions(0,chartShowArrows | chartShowDates);
_SECTION_BEGIN("Heikin Ashi");

_SECTION_END();

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

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

//================================================== ================================================== ===================
//=========================Indicator================ ================================================== ============================
f=ATR(14);

rfsctor = WMA(H-L, Per);

revers = k * rfsctor;

Trend = 1;
NW[0] = 0;


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

//===============system================


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

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

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

_SECTION_BEGIN("Long MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 200, 2, 400, 1 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") | styleNoRescale );
_SECTION_END();
 
#5
@Tipss Bse Nse, thanks for providing the afl and sorry to say, this above afl showing some space that is rectified and after that also it showing some errors like setbarfill etc.

please have a look into it and give the added/modified code. This is not like nma or nakshatra afl as I assume,
it might be some zigzag or any new indicator v-t r nd or some manipulations with ema,wma etc lines afl.

(just the lines indicators afl is enough for the above charts given , if candles or bars afl not working we can add it from anywhere. so please provide the lines afl which we can see blue,ash lines in these charts)
your & others support is appreciated.
 
Last edited:
#6
Good Morning.
I want to get this type of afl if any experts please give their helping hand in making a AFL with the following features.
or if it already exists anywhere similar pls provide it.
I am not familiar with language in writing such codes.

The AFL is to scan the selected stocks and to give result in a box.

first this afl should take few scrip names from individual. any fixed number of stocks should be selected by names in a list upto 20 or 50 or 100. from that list only it do calculations.

all scrip names should be arranged in column in a corner box with scrolling, if colors given to them is better, like dark green-light green-light red-dark red and it arranges them in the same sequence of color.

beside the stocks another column given for a indicator and it's values in digits.

indicator one or two selected by individual from the list contains macd, stocastic, rsi, adx, cci, pivot, fib, gann, ema, wma, PE, volatility, pcr etc.

the indicator parameters & time frame also selected by individual, like 10 min, 30 min, 60 min, daily, weekly, monthly.
parameters means for e.g: stocastic one want 8-3-3 other want 15-5-3 or 20-10-5 etc.

whenever clicked scan button with parameters(any time), it should calculate realtime and arrange the passout stocks(from the above) in ascending order in the corner box.

parameters for e.g: want to see the passedout stocks in hourly timeframe show the stocks which stocastic( 8-3-3) crossed 20 and in between 20-30 range the stocastic is moving at present. like wise selected indicator and parameters(<, <=, >, >=, in between, near + or - 1% of nth no, crossover, ) taken for calculations and show the passout stocks list in that box.

that's all the afl should do.

if possible it should display the RT chart of the selected stock from corner box with the same selected indicator.
Thanks in advance.
 

Similar threads