Simple Coding Help - No Promise.

lvgandhi

Well-Known Member


see the difference i draw black line.. can we get as thick as i got black.
I saw your PM. I use this AFL for drawing to day's hi, lo and yesterday's hi, lo and close along with price. Trading day's range and BRN and Rn are to be drawn manually only.
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack));
//SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Candle Down Color", colorDarkRed),colorLightGrey)));
_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", IIf(C>O,colorLime,colorRed), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
GraphXSpace = 10;
_SECTION_END();

_SECTION_BEGIN("PreDHLCDayHL");
x=LastVisibleValue(DateNum());
Hor0 = Param("Hor0",900,0,1368,1);
Ver0 = Param("Ver0",30,0,768,1);

Cond=BarsSince(DateNum()<x);
y=Ref(DateNum(),-Cond);
Cond1=BarsSince(DateNum()<LastValue(y));
z=Cond1-Cond;
Hi0=HHV(H,Cond);
Hi0bar=HHVBars(H,Cond);

x20=BarCount-LastValue(Cond);
x21=BarCount-1;
y20=LastVisibleValue(Hi0);
y21=y20;
Line2 = LineArray( x20, y20, x21, y21, 1 );
Plot( Line2, "day high line", colorOrange,styleThick|styleNoTitle);

Li0=LLV(L,Cond);
Li0bar=LLVBars(L,Cond);

x30=BarCount-LastValue(Cond);
x31=BarCount-1;
y30=LastVisibleValue(Li0);
y31=y30;
Line3 = LineArray( x30, y30, x31, y31, 1 );
Plot( Line3, "day low line", colorTurquoise,styleThick|styleNoTitle );

Hi=Ref(HHV(H,z),-Cond);
Hibar=Ref(HHVBars(H,z),-Cond)+Cond;
x0=BarCount-1-LastValue(Hibar);
x1=BarCount-1;
y0=LastValue(Hi);
y1=y0;
Line = LineArray( x0, y0, x1, y1, 1 );
Plot( Line, "high line", ParamColor("high line", colorGreen),styleThick|styleNoTitle );

pc=Ref(Close,-Cond);

x10=BarCount-1-LastValue(Cond);
x11=BarCount-1;
y10=LastValue(pc);
y11=y10;

Line1=LineArray( x10, y10, x11, y11, 1 );
Plot( Line1, "Close line", ParamColor("close line", colorWhite),styleThick|styleNoTitle );

Lo=Ref(LLV(L,z),-Cond);
Lobar=Ref(LLVBars(L,z),-Cond)+Cond;

x00=BarCount-1-LastValue(Lobar);
x01=BarCount-1;
y00=LastValue(Lo);
y01=y00;

Line11=LineArray(x00,y00,x01,y01,1);
Plot(Line11,"Low Line",ParamColor("Low line", colorBlue),styleThick|styleNoTitle);
_SECTION_END();
 

josh1

Well-Known Member
I saw your PM. I use this AFL for drawing to day's hi, lo and yesterday's hi, lo and close along with price. Trading day's range and BRN and Rn are to be drawn manually only.
LVG, I am using another AFL for PDH,PDL,PDC,DH,DL.
but can we have horizontal line for BRN (SAY DIVISIBLE BY HUNDRED)on chart?
We will have to grab Y axis range. Then identify nos. ending 00. Plot line for visible bars for those nos where Y = the no.
 
Last edited:
DEAR SENIOR'S

CAN SOMEONE PLEASE ADD AN AUDIO BEEP WHEN BUY OR SELL SIGNAL IS GENERATED



// Million Dollar Afl //

_SECTION_BEGIN("MAMA");
SetBarsRequired( 10000, 10000 );
SetChartOptions(0,chartShowArrows|chartShowDates);
prc = ( High + Low ) / 2;
fastlimit = 0.5;
slowlimit = 0.05;
pi=4*atan(1);
RTD=180/pi;
DTR=pi/180;

Cyclepart=Param("Alpha",0.5,0.1,1,0.1);

Smooth[0] = Period = Detrender[0] = I1[0] = Q1[0] = 0;
phase[0]=deltaphase[0]=MAMA[0]=FAMA[0]=0;
for ( i = 6; i < BarCount; i++ )
{
Smooth = ( 4 * prc + 3 * prc[i-1] + 2 * prc[i-2] + prc[i-3] ) / 10;
AmpCorr = 0.075 * Period[i-1] + 0.54;
Detrender = ( 0.0962 * Smooth + 0.5769 * Smooth[i-2] - 0.5769 * Smooth[i-4] - 0.0962 * Smooth[i-6] ) * AmpCorr;
Q1 = ( 0.0962 * Detrender + 0.5769 * Detrender[i-2] - 0.5769 * Detrender[i-4] - 0.0962 * Detrender[i-6] ) * AmpCorr;
I1 = Detrender[i-3];
if (I1 != 0) phase = DTR*360/atan(q1/I1);
deltaphase=phase[i-1]-phase;
if (deltaphase <1) deltaphase=1;
alpha=fastlimit/deltaphase;
if (alpha < slowlimit) alpha=slowlimit;
MAMA=alpha * prc +(1-alpha)*MAMA[i-1];
FAMA=Cyclepart*alpha * prc +(1-Cyclepart*alpha)*FAMA[i-1];
}

Plot( MAMA, "MAMA", colorTurquoise, styleLine|styleThick );
Plot( FAMA, "FAMA", colorYellow, styleLine|styleThick );
PlotOHLC(O,H,L,C,"MAMA",IIf(MAma>fama,colorLime,colorRed),styleBar|styleThick);
_SECTION_END();

_SECTION_BEGIN("SYSTEM");
BuySetupValue=ValueWhen(Cross(MAMA,FAMA),H,1);
SellsetupValue=ValueWhen(Cross(FAMA,MAMA),L,1);
Buysetup =Cross(MAMA,FAMA) ;
Sellsetup = Cross(FAMA,MAMA);
Longa = Flip(Buysetup,Sellsetup);
shrta = Flip(Sellsetup,Buysetup);
Buy=Longa AND Cross(C,BuySetupValue);
Sell=shrta AND Cross(SellsetupValue,C);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
t1= Flip(Buy,Sell);
t2= Flip(Sell,Buy);
BPrice=ValueWhen(t1 AND Ref(t1,-1)==0,C,1);
SPrice=ValueWhen(t2 AND Ref(t2,-1)==0,C,1);
GraphXSpace = 5;
dist = 1.5*ATR(20);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "" + C[ i ], i, L[ i ]-dist, colorLime );
if( Sell ) PlotText( "" + C[ i ], i, H[ i ]+dist, colorYellow );
}
_SECTION_END();
//=================TITLE================================================================================================
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "MAMA Poistional System" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
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-BPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SPrice-C)+"","")+
WriteIf(Longa AND NOT Buy, "Trade : Long - Entry price Rs."+(BPrice),"")+
WriteIf(shrta AND NOT Sell, "Trade : Short - Entry price Rs."+(SPrice),"")+"\n"+
WriteIf(Longa AND NOT Buy, "Current Profit/Loss Rs."+(C-BPrice)+"","")+
WriteIf(shrta AND NOT Sell, "Current Profit/Loss Rs."+(SPrice-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);
_SECTION_END();
WriteVal(BuyPrice);
WriteVal(Longa);
WriteVal(t1);
WriteVal(SellPrice);
WriteVal(shrta);
_SECTION_END();

_SECTION_BEGIN("Magnified Market Price");
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",25,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();


THIS IS NOT MY OWN AFL JUST FOUND IN THE NET AND IT SEEMS GOOD IN 15 MINUTE TF. PLS CODE AUDIO FOR BUY SELL SIGNAL.
 
Last edited:

amsin21

Well-Known Member

function SayNotTooOften( text, Minperiod )
{
elapsed=GetPerformanceCounter()/1000;
Lastelapsed = Nz( StaticVarGet("lastsaytime") );

if( elapsed - Lastelapsed > Minperiod )
{
StaticVarSet("lastsaytime", elapsed );
Say( text );
}
}

/////////////////////////////////////////////////////////
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "MAMA Poistional System" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
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-BPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SPrice-C)+"","")+
WriteIf(Longa AND NOT Buy, "Trade : Long - Entry price Rs."+(BPrice),"")+
WriteIf(shrta AND NOT Sell, "Trade : Short - Entry price Rs."+(SPrice),"")+"\n"+
WriteIf(Longa AND NOT Buy, "Current Profit/Loss Rs."+(C-BPrice)+"","")+
WriteIf(shrta AND NOT Sell, "Current Profit/Loss Rs."+(SPrice-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);

if(LastValue(Buy)) SayNotTooOften(Name()+Interval(2)+"Buy triggered",180);
if(LastValue(Sell)) SayNotTooOften1(Name()+Interval(2)+"Sell triggered",180);

AlertIf( Buy, "SOUND c:\\alert.wav", "Audio alert",0,1+2+4+8);
AlertIf( Sell, "SOUND c:\\alert.wav", "Audio alert",0,1+2+4+8);


_SECTION_END();

Add to AFL as highlighted in red
 
Last edited:
Guys can you modify this code so that it gives audio alerts only after candle completion. Ive tried a lot but something is amiss.

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 ) ) ));
_N( Title = Title +"\n" + _DEFAULT_NAME() );

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

Buy = Close > Open
AND MACD( 12, 26 ) > MACD( 6, 13 );

Sell = Close < Open
AND MACD( 12, 26 ) < MACD( 6, 13 );

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,Low,Offset=-15);

PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),coloryellow,0,Low,Offset=-50);
 

lvgandhi

Well-Known Member
LVG, I am using another AFL for PDH,PDL,PDC,DH,DL.
but can we have horizontal line for BRN (SAY DIVISIBLE BY HUNDRED)on chart?
We will have to grab Y axis range. Then identify nos. ending 00. Plot line for visible bars for those nos where Y = the no.
I was also using that AFL previously. But if you want to check for some intermediate days, you will not get those lines. Now with this AFL, you will get those lines. For example, if you are looking for, say, 2nd dec, this AFL will draw lines of 2nd Dec Hi, Lo and 1st dec hi, lo and close.
I do not find ways to grab Y axis range in AFL so far. If we can get that, then we can draw lines for 00 and 50s.
 

function SayNotTooOften( text, Minperiod )
{
elapsed=GetPerformanceCounter()/1000;
Lastelapsed = Nz( StaticVarGet("lastsaytime") );

if( elapsed - Lastelapsed > Minperiod )
{
StaticVarSet("lastsaytime", elapsed );
Say( text );
}
}

/////////////////////////////////////////////////////////
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "MAMA Poistional System" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
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-BPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SPrice-C)+"","")+
WriteIf(Longa AND NOT Buy, "Trade : Long - Entry price Rs."+(BPrice),"")+
WriteIf(shrta AND NOT Sell, "Trade : Short - Entry price Rs."+(SPrice),"")+"\n"+
WriteIf(Longa AND NOT Buy, "Current Profit/Loss Rs."+(C-BPrice)+"","")+
WriteIf(shrta AND NOT Sell, "Current Profit/Loss Rs."+(SPrice-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);

if(LastValue(Buy)) SayNotTooOften(Name()+Interval(2)+"Buy triggered",180);
if(LastValue(Sell)) SayNotTooOften1(Name()+Interval(2)+"Sell triggered",180);

AlertIf( Buy, "SOUND c:\\alert.wav", "Audio alert",0,1+2+4+8);
AlertIf( Sell, "SOUND c:\\alert.wav", "Audio alert",0,1+2+4+8);


_SECTION_END();

Add to AFL as highlighted in red[/QUOTE]

Dear Amsin21,

Thankyou For your prompt reply, But after adding the Highlighted Coding in RED I find errors as attached can u pls rectify the same

 
change SayNotTooOften1 as SayNotTooOften



thats the only error




function SayNotTooOften( text, Minperiod )
{
elapsed=GetPerformanceCounter()/1000;
Lastelapsed = Nz( StaticVarGet("lastsaytime") );

if( elapsed - Lastelapsed > Minperiod )
{
StaticVarSet("lastsaytime", elapsed );
Say( text );
}
}

/////////////////////////////////////////////////////////
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "MAMA Poistional System" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
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-BPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SPrice-C)+"","")+
WriteIf(Longa AND NOT Buy, "Trade : Long - Entry price Rs."+(BPrice),"")+
WriteIf(shrta AND NOT Sell, "Trade : Short - Entry price Rs."+(SPrice),"")+"\n"+
WriteIf(Longa AND NOT Buy, "Current Profit/Loss Rs."+(C-BPrice)+"","")+
WriteIf(shrta AND NOT Sell, "Current Profit/Loss Rs."+(SPrice-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);

if(LastValue(Buy)) SayNotTooOften(Name()+Interval(2)+"Buy triggered",180);
if(LastValue(Sell)) SayNotTooOften1(Name()+Interval(2)+"Sell triggered",180);

AlertIf( Buy, "SOUND c:\\alert.wav", "Audio alert",0,1+2+4+8);
AlertIf( Sell, "SOUND c:\\alert.wav", "Audio alert",0,1+2+4+8);


_SECTION_END();

Add to AFL as highlighted in red
Dear Amsin21,

Thankyou For your prompt reply, But after adding the Highlighted Coding in RED I find errors as attached can u pls rectify the same

[/QUOTE]
 

amsin21

Well-Known Member

Similar threads