Simple Coding Help - No Promise.



Hi Seniors,

I have an Afl with Arrows for buy sell signal can somebody add the Rate Value above/Below the Arrows.


I am not a programmer but have collected different Afls & made a cocktail for my own style of Trading

// Advance Buy Sell Arrow Afl //

SetChartOptions(2, chartWrapTitle);
// Calculate Moving Average
MAPeriod = Param("MA Period", 12, 1, 100);
MAOpen = EMA(Open, MAPeriod);
MAHigh = EMA(High, MAPeriod);
MALow = EMA(Low, MAPeriod);
MAClose = EMA(Close, MAPeriod);
HaClose = (MAOpen + MAHigh + MALow + MAClose) / 4;
HaOpen = AMA(Ref(HaClose, - 1), 0.5);
// for 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;

/* **********************************
Code to automatically identify pivots
********************************** */
// -- what will be our lookback range for the hh and ll?
farback = Param("How Far back to go", 100, 50, 5000, 10);
nBars = Param("Number of bars", 12, 5, 40);
// -- Title.
Title = Name() + " (" + StrLeft(FullName(), 15) + ") O: " + Open + ", H: " + High + ", L: " + Low + ", C: " + Close;
// -- Create 0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs = L - L;
// -- More for future use, not necessary for basic plotting
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;
// -- looking back from the current bar, how many bars
// back were the hhv and llv values of the previous
// n bars, etc.?
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
// -- Would like to set this up so pivots are calculated back from
// last visible bar to make it easy to "go back" and see the pivots
// this code would find. However, the first instance of
// _Trace output will show a value of 0
aVisBars = Status("barvisible");
nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
_TRACE("Last visible bar: " + nLastVisBar);
// -- Initialize value of curTrend
curBar = (BarCount - 1);
curTrend = "";
if (aLLVBars[curBar] <
aHHVBars[curBar])
{
curTrend = "D";
}
else
{
curTrend = "U";
}
// -- Loop through bars. Search for
// entirely array-based approach
// in future version
for (i = 0; i < farback; i++)
{
curBar = (BarCount - 1) - i;
// -- Have we identified a pivot? If trend is down...
if (aLLVBars[curBar] < aHHVBars[curBar])
{
// ... and had been up, this is a trend change
if (curTrend == "U")
{
curTrend = "D";
// -- Capture pivot information
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}
// -- or current trend is up
}
else
{
if (curTrend == "D")
{
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}
// -- If curTrend is up...else...
}
// -- loop through bars
}
// -- Basic attempt to add a pivot this logic may have missed
// -- OK, now I want to look at last two pivots. If the most
// recent low pivot is after the last high, I could
// still have a high pivot that I didn't catch
// -- Start at last bar
curBar = (BarCount - 1);
candIdx = 0;
candPrc = 0;
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
if (lastLPIdx > lastHPIdx)
{
// -- Bar and price info for candidate pivot
candIdx = curBar - aHHVBars[curBar];
candPrc = aHHV[curBar];
if (
lastHPH < candPrc AND
candIdx > lastLPIdx AND
candIdx < curBar)
{
// -- OK, we'll add this as a pivot...
aHPivs[candIdx] = 1;
// ...and then rearrange elements in the
// pivot information arrays
for (j = 0; j < nHPivs; j++)
{
aHPivHighs[nHPivs - j] = aHPivHighs[nHPivs -
(j + 1)];
aHPivIdxs[nHPivs - j] = aHPivIdxs[nHPivs - (j + 1)];
}
aHPivHighs[0] = candPrc;
aHPivIdxs[0] = candIdx;
nHPivs++;
}
}

else
{
// -- Bar and price info for candidate pivot
candIdx = curBar - aLLVBars[curBar];
candPrc = aLLV[curBar];
if (
lastLPL > candPrc AND
candIdx > lastHPIdx AND
candIdx < curBar)
{
// -- OK, we'll add this as a pivot...
aLPivs[candIdx] = 1;
// ...and then rearrange elements in the
// pivot information arrays
for (j = 0; j < nLPivs; j++)
{
aLPivLows[nLPivs - j] = aLPivLows[nLPivs - (j + 1)];
aLPivIdxs[nLPivs - j] = aLPivIdxs[nLPivs - (j + 1)];
}
aLPivLows[0] = candPrc;
aLPivIdxs[0] = candIdx;
nLPivs++;
}
}
// -- Dump inventory of high pivots for debugging
/*
for (k=0; k<nHPivs; k++) {
_TRACE("High pivot no. " + k
+ " at barindex: " + aHPivIdxs[k] + ", "
+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],
DateTime(), 1), formatDateTime)
+ ", " + aHPivHighs[k]);
}
*/
// -- OK, let's plot the pivots using arrows
PlotShapes(IIf(aHPivs == 1, shapeDownArrow, shapeNone), colorRed, 0, High, Offset = - 15);
PlotShapes(IIf(aLPivs == 1, shapeUpArrow, shapeNone), colorBrightGreen, 0, Low, Offset = - 15);

//THANKS TO : WWW.JACKPOTOPTION.COM

_SECTION_BEGIN("Price Chart");
bgTop = ParamColor("BgTop", colorBlack);
bgBot = ParamColor("BgBottom", colorDarkGrey);
SetChartBkGradientFill( bgTop ,bgBot, colorBlack);

pStyle = ParamList("Price Style", "Candle|Solid Candle|Bar|Line|Heikin-Ashi",2);
cBull = ParamColor("Price Bull", colorGreen);
CBear = ParamColor("Price Bear", colorRed);
cLine = ParamColor("Price Line", colorWhite);


ThisStyle = styleCandle;
ThisTitle = "";

_O=O; _C=C; _H=H; _L=L;

ThisColor = IIf( _C>_O, cBull, IIf(_C<_O, CBear, CLine));

switch (pStyle )
{
case "Solid Candle":
SetBarFillColor( ThisColor );
break;case "Bar":
ThisStyle = styleBar;break;
case "Line": ThisStyle = styleLine;
ThisColor = cLine;break;case "Heikin-Ashi":
_C = (O+H+L+C)/4;
_O = AMA( Ref( _C, -1 ), 0.5 );
_H = Max( H, Max( _C, _O ) );
_L = Min( L, Min( _C, _O ) );
ThisColor = IIf(_C >= _O,CBull, CBear);
SetBarFillColor( ThisColor );
ThisColor = IIf(_C >= _O,cLine, cLine);
ThisTitle = "Heikin-Ashi";break;

default:SetBarFillColor( ThisColor );
ThisColor = cLine;break;

}
PlotOHLC( _O, _H, _L, _C, ThisTitle, ThisColor, ThisStyle);
GraphXSpace = 8;

_SECTION_END();


SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;
Plot(C,"",colorBlack,styleBar);

_SECTION_BEGIN("Magnified Market Price");
//by Vidyasagar, [email protected]//
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorYellow) );
Hor=Param("Horizontal Position",1200,1,1200,1);
Ver=Param("Vertical Position",1,1,830,1);
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorGreen) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor , Ver+45 );
_SECTION_END();

_SECTION_BEGIN("Day Divider");
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
Plot(grid_Day,"",colorYellow,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
_SECTION_END();

_SECTION_BEGIN("Price Line");

PriceLineColor=ParamColor("PriceLineColor",ColorRGB(255,255,0));
PriceLevel = ParamField("PriceField", field = 3 );
Daysback = Param("Bars Back",100,10,500,1);
FirstBar = BarCount - DaysBack;
YY = IIf(BarIndex() >= Firstbar,EndValue(PriceLevel),Null);
Plot(YY,"Current Price",PriceLineColor,ParamStyle("LineStyle",styleLine|styleDashed|styleNoTitle|styleNoLabel|styleThick,maskAll));
side = Param("side",1,0,1000,1);
dist = 0;
for( i = 0; i < BarCount; i++ )
{
if(i+side== BarCount) PlotText( "\n " + PriceLevel[ i ], i, YY[ i ]-dist, colorYellow );
}
_SECTION_END();

_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
 
Last edited:

xsis

Active Member
dear boarders

i need a simple scanner for stocks for 52 week (or n=no. of days) high & low VOLUMES.

i tried but, its easier to do for price with HHV/LLV. but how to do for volumes?
 
hi rsathish07 i found afl like that in your attach

_SECTION_BEGIN("New formula 75");
SetChartOptions(0,chartShowArrows|chartShowDates);
bk=ParamColor( "Bk col",ColorRGB(85,90,60));
SetChartBkColor(bk);

amount = Param("Sensitivity", 0.5, 0.1, 2, 0.1 );

array = C ;
zz0 = Zig( array, amount );
zz1 = Ref( zz0, -1 );
zz2 = Ref( zz0, -2 );

tr = ValueWhen(zz0 > zz1 AND zz1 < zz2, zz1);
pk = ValueWhen(zz0 < zz1 AND zz1 > zz2, zz1);
PU = tr + 0.01 * abs(tr)*amount;
PD = pk - 0.01 * abs(pk)*amount;

ZZT = IIf( array >= PU AND zz0 > zz1, 1,
IIf( array <= PD AND zz0 < zz1, -1, 0 ) );

ZZT = ValueWhen( ZZT != 0, ZZT );

Buy_Valid_=zzt>0;
Sell_Valid_=zzt<0;
Buy_Valid = ExRem(Buy_Valid_,Sell_Valid_);
Sell_Valid = ExRem(Sell_Valid_,Buy_Valid_);
Plot(Ref(Buy_valid,0),"",ColorRGB(0,0,100),styleHistogram|styleDashed|styleOwnScale|styleNoLabel,0,0,0,-1);
Plot(Ref(Sell_valid,0),"",ColorRGB(100,0,0),styleHistogram|styleDashed|styleOwnScale|styleNoLabel,0,0,0,-1);

Candlecol=IIf(BarsSince(Buy_Valid)<BarsSince(Sell_Valid) AND BarsSince(Buy_Valid)!=0,5,
IIf(BarsSince(Buy_Valid)>BarsSince(Sell_Valid) AND BarsSince(Sell_Valid)!=0,4,1));
cc1=IIf(Buy_valid,colorYellow,IIf(Sell_valid,colorBlack,Candlecol));
SetBarFillColor(Cc1);
Plot(C,"Cas-S_D-Zone",Cc1,64,0,0,0,0);

pk=BarsSince(Buy_Valid)<BarsSince(Sell_Valid) ;//AND BarsSince(Buy_Valid)!=0;//Zz>Ref(zz,-1);
tr=BarsSince(Buy_Valid)>BarsSince(Sell_Valid) ;//AND BarsSince(Sell_Valid)!=0;//Zz<Ref(zz,-1);

Ll=LowestSince(sell_valid,L,1);
hH=HighestSince(Buy_Valid,H,1);
Llm=LowestSince(sell_valid,Min(O,C),1);
hHm=HighestSince(Buy_Valid,Max(O,C),1);

xx=Cum(1);
NoLines = Param("No of Lines",5,1,10,1);

Col2=ParamColor( "Res Color", colorRed );
Col1=ParamColor( "Sup Color", colorGreen );

for( i = 1; i < NoLines+1 ; i++ )
{
scol=ColorBlend(Col1,2,0.1*i);
rcol=ColorBlend(Col2,2,0.1*i);

px1 = LastValue(ValueWhen(Buy_valid,Cum(1),i)) ;
py1 = LastValue(ValueWhen(Buy_valid,Ll,i)) ;
pz1 = LineArray(px1, py1, (BarCount-1), py1);
Plot(pz1,"",scol,32);

tx1 = LastValue(ValueWhen(sell_valid,Cum(1),i)) ;
ty1 = LastValue(ValueWhen(sell_valid,Hh,i)) ;
tz1 = LineArray(tx1, ty1, (BarCount-1), ty1);
Plot(tz1,"",rcol,32);

px1m = LastValue(ValueWhen(Buy_valid,Cum(1),i)) ;
py1m = LastValue(ValueWhen(Buy_valid,Llm,i)) ;
pz1m = LineArray(px1m, py1m, (BarCount-1), py1m);
PlotOHLC(pz1,pz1,pz1m,pz1m,"",scol,styleCloud|styleNoLabel,0,0,0,-i-nolines);

tx1m = LastValue(ValueWhen(sell_valid,Cum(1),i)) ;
ty1m = LastValue(ValueWhen(sell_valid,Hhm,i)) ;
tz1m = LineArray(tx1m, ty1m, (BarCount-1), ty1m);
PlotOHLC(tz1,tz1,tz1m,tz1m,"",rcol,styleCloud|styleNoLabel,0,0,0,-i-nolines);
}

for( j = 0; j < BarCount; j++ )
{
if( Buy_valid [j]) PlotText( "Tr\n"+Ll[ j ], j, Ll[j], colorPaleGreen );
if( Sell_valid[j] ) PlotText( "Pk\n"+Hh[ j ], j, Hh[j], colorRose);
}
_SECTION_END();
 
hi friends.one of the best RSI that i found

_SECTION_BEGIN("RSI TRENDLINE");
// RSI TRENDLINE formula ver 1.0

SetBarsRequired(sbrAll, sbrAll);
TP = Param("Trend Per", 300,2,1000);
per_RSI= Param("RSI Per", 9, 7, 35,1);
IND = RSI(per_RSI);
Center = 50 ;

Plot( RSI(per_RSI), "", 4, 4);
Plot(50,"",1,1) ;

// CALCULATE UPTREND

startvalue = LastValue( LLV( IND, TP ) );
startbar = LastValue( ValueWhen( IND == startvalue, BarIndex(), 1) );
BP = BarCount - Startbar;

secondvalue = LastValue( LLV( IND, BP - 5 ) );
secondbar = LastValue( ValueWhen( IND == secondvalue, BarIndex(), 1) );
BP2 = BarCount - secondbar;

thirdvalue = LastValue( LLV( IND, BP2 - 5 ) );
thirdbar = LastValue( ValueWhen( IND == thirdvalue, BarIndex(), 1) );
BP3 = BarCount - thirdbar;

fourthvalue = LastValue( LLV( IND, BP3 - 5 ) );
fourthbar = LastValue( ValueWhen( IND ==fourthvalue, BarIndex(), 1) );
BP4 = BarCount - fourthbar;

fifthvalue = LastValue( LLV( IND, BP4 - 5 ) );
fifthbar = LastValue( ValueWhen( IND ==fifthvalue, BarIndex(), 1) );
BP5 = BarCount - fifthbar;

sixthvalue = LastValue( LLV( IND, BP5 - 5 ) );
sixthbar = LastValue( ValueWhen( IND ==sixthvalue, BarIndex(), 1) );

Low_1= IIf( BarIndex() == startbar, 80, Null);
Low_2= IIf( BarIndex() == secondbar, 80, Null);
Low_3= IIf( BarIndex() == thirdbar, 80, Null);
Low_4= IIf( BarIndex() == fourthbar, 80, Null);
Low_5= IIf( BarIndex() == fifthbar, 80, Null);
Low_6= IIf( BarIndex() == sixthbar, 80, Null);

b = startvalue ;
FirstSlope = (secondvalue - b) / (secondbar - startbar) ;
FirstTrendline = FirstSlope * ( BarIndex() - startbar ) + b;
// Plot( IIf( BarIndex() >= startbar AND FirstTrendline <= 90 , FirstTrendline, Null ) , "FirstTrendline", colorGreen, styleThick +2048 );

SecondSlope = (thirdvalue - b) / (thirdbar - startbar) ;
SecondTrendline = SecondSlope * ( BarIndex() - startbar ) + b;

ThirdSlope = (fourthvalue - b) / (fourthbar - startbar) ;
ThirdTrendline = ThirdSlope * ( BarIndex() - startbar ) + b;

FourthSlope = (fifthvalue - b) / (fifthbar - startbar) ;
FourthTrendline = FourthSlope * ( BarIndex() - startbar ) + b;

FifthSlope = (sixthvalue - b) / (sixthbar - startbar) ;
FifthTrendline = FifthSlope * ( BarIndex() - startbar ) + b;

MainSlope = IIf( FirstSlope > SecondSlope, IIf( SecondSlope > ThirdSlope, IIf( ThirdSlope > FourthSlope,
IIf( FourthSlope > FifthSlope, FifthSlope, FourthSlope),ThirdSlope), SecondSlope), FirstSlope) ;

MainLine = MainSlope * ( BarIndex() - startbar ) + b;
Plot( IIf( BarIndex() >= startbar, MainLine, Null ) , "MainLine", colorDarkGreen, styleThick ) ;


IND_Diff = IIf( BarIndex() >= startbar, abs( IND - MainLine), Null) ;
MainTrendLine_Diff = Param("Difference IND from MainTrendLine", 2.5, 0.5,5, 0.5);

Cond_Buy = IIf( BarIndex() >= Thirdbar AND IND_Diff <= MainTrendLine_Diff, IND, 0) AND MainLine < 55 ;

PlotShapes( IIf( Cond_Buy, shapeUpArrow , shapeNone ), colorGreen );



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

// CALCULATE DOWNTREND

starthigh = LastValue( HHV( IND, TP ) );
starthighbar = LastValue( ValueWhen( IND == starthigh, BarIndex(), 1) );
HBP = BarCount - starthighbar;

secondhigh = LastValue( HHV( IND, HBP - 5 ) );
secondhighbar = LastValue( ValueWhen( IND == secondhigh, BarIndex(), 1) );
HBP2 = BarCount - secondhighbar;

thirdhigh = LastValue( HHV( IND, HBP2 - 5 ) );
thirdhighbar = LastValue( ValueWhen( IND == thirdhigh, BarIndex(), 1) );
HBP3 = BarCount - thirdhighbar;

fourthhigh = LastValue( HHV( IND, HBP3 - 5 ) );
fourthhighbar = LastValue( ValueWhen( IND ==fourthhigh, BarIndex(), 1) );
HBP4 = BarCount - fourthhighbar;

fifthhigh = LastValue( HHV( IND, HBP4 - 5 ) );
fifthhighbar = LastValue( ValueWhen( IND ==fifthhigh, BarIndex(), 1) );
HBP5 = BarCount - fifthhighbar;

sixthhigh = LastValue( HHV( IND, HBP5 - 5 ) );
sixthhighbar = LastValue( ValueWhen( IND ==sixthhigh, BarIndex(), 1) );

High_1= IIf( BarIndex() == starthighbar, 90, Null);
High_2= IIf( BarIndex() == secondhighbar, 90, Null);
High_3= IIf( BarIndex() == thirdhighbar, 90, Null);
High_4= IIf( BarIndex() == fourthhighbar, 90, Null);
High_5= IIf( BarIndex() == fifthhighbar, 90, Null);
High_6= IIf( BarIndex() == sixthhighbar, 90, Null);

MainTrendLine_Diff = Param("Difference IND from MainTrendLine", 2.5, 0.5,7, 0.5);

d = starthigh ;
FirstDownSlope = (secondhigh - d) / (secondhighbar - starthighbar) ;
FirstDownTrendline = FirstDownSlope * ( BarIndex() - starthighbar ) + d;

SecondDownSlope = (thirdhigh - d) / (thirdhighbar - starthighbar) ;
SecondDownTrendline = SecondDownSlope * ( BarIndex() - starthighbar ) + d;

ThirdDownSlope = (fourthhigh - d) / (fourthhighbar - starthighbar) ;
ThirdDownTrendline = ThirdDownSlope * ( BarIndex() - starthighbar ) + d;

FourthDownSlope = (fifthhigh - d) / (fifthhighbar - starthighbar) ;
FourthDownTrendline = FourthDownSlope * ( BarIndex() - starthighbar ) + d;

FifthDownSlope = (sixthhigh - d) / (sixthhighbar - starthighbar) ;
FifthDownTrendline = FifthDownSlope * ( BarIndex() - starthighbar ) + d;

MainDownSlope = IIf( FirstDownSlope < SecondDownSlope, IIf( SecondDownSlope < ThirdDownSlope,
IIf( ThirdDownSlope < FourthDownSlope, IIf( FourthDownSlope < FifthDownSlope, FifthDownSlope, FourthDownSlope),ThirdDownSlope), SecondDownSlope), FirstDownSlope) ;

MainDownLine = IIf( MainDownSlope == 0, Null, MainDownSlope * ( BarIndex() - starthighbar ) + d ) ;
Plot( IIf( BarIndex() >= starthighbar, MainDownLine, Null ) , "Main_DOWN_Line", colorViolet, styleThick ) ;

IND_Diff = IIf( BarIndex() >= starthighbar, abs( IND - MainDownLine), Null) ;

Cond_Sell = IIf( BarIndex() >= Thirdbar AND IND_Diff <= MainTrendLine_Diff, IND, 0) AND MainDownLine > 45 ;

PlotShapes( IIf( Cond_Sell, shapeDownArrow , shapeNone ), colorRed );


Title = Name() + "\\c17" + " " +"\\c12" + "RSI" + " " + per_RSI ;
_SECTION_END();
 

Similar threads