Simple Coding Help - No Promise.

Hello all,

please do help me in a very simple trading system that can Buy at Close >30% previous close, & Sell at Close> 5% from buy value, plus plotting arrows.
 

ocil

Well-Known Member
buy=ExRem(Buy,Sell);
sell=ExRem(sell,buy);
is command for non repeating of buy and sell arrow /signal.

Hi,
I am just a newbie to Amibroker. I have just bought the trial version and trying to write some afl.
I want a simple condition that if 6-ema crosses 18-ema then buy at next day's open price.
Sell on the open price on the day after buy was executed. for eg. if buy on 1st jan then sell on 2nd jan open price.
I only want to go long and not short.

I wrote the following AFL but it wasn't getting executed properly

fastma = MA(C,6);
slowma = MA(C,18);
SetTradeDelays(1,2,1,1);
BuyPrice=Open;
SellPrice=Open;
Buy=Cross(fastma,slowma);
Sell=Cross(fastma,slowma);
ExRem(Buy,Sell);


Could someone please explain me exrem function. I am not clear on how it works.

Thanks :)
 

Nehal_s143

Well-Known Member
Below code is used to define targets for long and short, but due to bars-Offset used in plotting, chart size becomes small to show t3 level, t3 is far away price from buy/sell signal price.

Please help me to display chart of regular size and let the t3 line plotted if price moves near t3

Code:
for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = H[i];
sig = "BUY";
sl = Ref(NW,-1);
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
 
bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = L[i];
sl = Ref(NW,-1);
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
 
 
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, NW[BarCount-1], Ref(NW, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
 
Below code is used to define targets for long and short, but due to bars-Offset used in plotting, chart size becomes small to show t3 level, t3 is far away price from buy/sell signal price.

Please help me to display chart of regular size and let the t3 line plotted if price moves near t3

Code:
for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = H[i];
sig = "BUY";
sl = Ref(NW,-1);
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
 
bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = L[i];
sl = Ref(NW,-1);
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
 
 
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, NW[BarCount-1], Ref(NW, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);


Easy peasy

Add styleNoRescale to any and all such Plots lines that you are OK to have become visible only if they are within the range and otherwise go off the chart.
 
Last edited:
Can this be another version of Fly candles ???

Code:
_SECTION_BEGIN("HA");
a=20;
GraphXSpace=5;
p=30;
p = Param("p",30,2,100,1);
Om=DEMA(O,p);
hm=DEMA(H,p);
lm=DEMA(L,p);
Cm=DEMA(C,p);
HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1), 1);
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );
slope = Param("slope",2,2,100,1);
Color20= IIf(LinRegSlope(MA(HaClose,a),slope)<0,colorRed,colorBlue);
Color=IIf(Haclose>MA(HaClose,a),colorBlue, colorRed);
PlotOHLC( HaOpen, HaOpen, HaClose, HaClose, "" + Name(), color, styleCandle);

Buy=Cover= Cross(Haclose,MA(HaClose,a));
Sell=Short= Cross(MA(HaClose,a),Haclose);

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


_SECTION_BEGIN("KPL Swing with N&M Swing");
SetBarsRequired(200,0);

GraphXSpace = 5;
SetChartOptions(0,chartShowArrows|chartShowDates);
k = Optimize("K",Param("K",3,0.25,5,0.25),0.25,5,0.25) ;
Per= Optimize("atr",Param("atr",10,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 ) );
j=Haclose;

// set background gradient colours
SetChartBkGradientFill( ParamColor("BgTop", colorDarkGrey),ParamColor("BgBottom", colorLightGrey ),ParamColor("titleblock",colorWhite));
GraphXSpace = 5;

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

rfsctor = WMA(H-L, Per);

revers = k * rfsctor;

Trend = 1;
NW[0] = 0;
NW[BarCount-1] = Null;


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

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

//Plot(NW, "", IIf(Trend == 1, 27, 4), 4);
//Buy=NW<HACLOSE;
//Sell=NW>HACLOSE;
//SellPrice=ValueWhen(Sell,C,1);
//BuyPrice=ValueWhen(Buy,C,1);
//Buy=ExRem(Buy,Sell);
//Sell=ExRem(Sell,Buy );

//Short=Sell;
//Cover=Buy;


//NMAB= NW<HACLOSE;
//NMAS= NW>HACLOSE;
AlertIf( Buy, "SOUND C:\\Windows\\Media\\buy.wav", "Audio alert", 1,1+1 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\sell.wav", "Audio alert", 2,1+1 );

//NMA_status= WriteIf(NMAB, "BUY MODE", WriteIf(NMAS, "SELL MODE", "NEUTRAL"));
//NMAS_Col=IIf(NMAB, colorGreen, IIf(NMAS, colorRed, colorLightGrey));
Filter=1;
//AddColumn( NW[BarCount-1], "SAR", 1.2 );
//AddColumn( HACLOSE, "HA Close", 1.2 );
//AddColumn( C, "Close", 1.2 );
//AddTextColumn(NMA_status, "MODE", 1, colorWhite, NMAS_Col);
//AddColumn( DateTime(), "Date / Time", formatDateTime );
_SECTION_END();

_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorBlack)+ " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorBlack) +
" - " + Date() +" - "+"\n" +EncodeColor(colorBlack) +"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-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);

GraphXSpace=5;


for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = C[i];
sig = "BUY";
sl = Ref(NW,-1);
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);

bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = C[i];
sl = Ref(NW,-1);
tar1 = entry - (entry * .0060);
tar2 = entry - (entry * .0120);
tar3 = entry - (entry * .0220);


bars = i;
i = 0;
}
}
Offset = 20;
//Clr = IIf(sig == "BUY", colorLime, colorRed);
//ssl = IIf(bars == BarCount-1, NW[BarCount-1], Ref(NW, -1));
//sl = ssl[BarCount-1];

//Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
//Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
//Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);



messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorDarkGreen ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorDarkRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 163, x2, y , 7, 7 ) ;
GfxTextOut( (" Amibroker trading System "),33,y-165);
GfxTextOut( (" "),27,y-160);
GfxTextOut( ("" + WriteIf(sig =="Long",sig + " at ",sig + " @") + " : " + entry), 13, y-120);
//GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-100);
//GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
//GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
//GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);
GfxTextOut( ("Current Profit : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)+" Points"), 13, y-100);;

}
_SECTION_END();




_SECTION_BEGIN("Background text");
C11=ParamColor("up panel",colorBlack );
C12=ParamColor("dn panel",colorBlack );
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",8,1,30,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode( 0 );
GfxSelectFont("Tahoma", 12, 500, False, False, 0);
GfxSetTextColor(colorCustom12);
GfxSetTextAlign( 6 );
GfxSelectFont("Tahoma", 15, 600, False, False, 0);
GfxSetTextColor(colorWhite);
GfxSetTextAlign( 6 );
GfxTextOut( "LTP "+WriteVal(C,1.2), Status("pxwidth")/C14, Status("pxheight")/C15);
GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorBrightGreen);
GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorRed);
GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorYellow);
GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorGreen);

pricechange=(C-Ref(C,-1))*100/Ref(C,-1);
changeponit=C-Ref(C,-1);
Vlp=Param("Volume lookback period",15,10,300,10);
Vrg=MA(V,Vlp);
St = StDev(Vrg,Vlp);
Vp3 = Vrg + 3*st;
Vp2 = Vrg + 2*st;;
Vp1 = Vrg + 1*st;;
Vn1 = Vrg -1*st;
Vn2 = Vrg -2*st;

x=Param("xposn",1,0,1000,1);
y=Param("yposn",1,0,1000,1);

/*GfxGradientRect( 1, 1, 1400, 40, colorGrey50, colorDarkGrey);
GfxSetBkMode(0);
GfxSelectFont( "Tahoma", 16, 800, False );
GfxSetTextColor( colorGold );
GfxTextOut( Name(), x+100, y+10 );
GfxSelectFont( "Century Gothic", 15, 100, False );
GfxSetTextColor( colorWhite );
GfxTextOut( Date(), x+600, y+10 );
GfxSelectFont( "Comic Sans MS", 15, 500, False );
GfxSetTextColor( colorYellow );
GfxTextOut( Interval(2), x+275, y+10 );
GfxSelectFont( "Georgia", 18, 800, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Amibroker Trading System ", x+1000, y+10 );
*/
//------------------------------------------------------------ H, L, O, C----------------------
GfxGradientRect( 1, 40, 1400, 55, colorGrey50, colorDarkGrey );
GfxSetBkMode(0);
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Open:"+WriteVal(O,1.2), x+100, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "High:"+WriteVal(H,1.2), x+200, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Low:"+WriteVal(L,1.2), x+300, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Close:"+WriteVal(C,1.2), x+400, y+40 );
GfxSelectFont( "Script MT Bold", 12, 100, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "By Amibroker Trading System ", x+1000, y+39 );
//-----------------------------------------------------------Valume-------------------------------
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Volume="+WriteVal(V,1.2), x+500, y+40 );
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorLime );
GfxTextOut( WriteIf(V>Vp2,"Very High",""), x+600, y+40 );
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorLime );
GfxTextOut( WriteIf(V>Vp1," High",""), x+600, y+40 );
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorLime );
GfxTextOut( WriteIf(V>Vrg,"Above Average",""), x+600, y+40 );
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorRed );
GfxTextOut( WriteIf(V<Vrg AND V>Vn1,"Less than Average",""), x+600, y+40 );
GfxSelectFont( "Tahoma", 9, 200, False );
GfxSetTextColor( colorRed );
GfxTextOut( WriteIf(V<Vn1,"Low",""), x+600, y+40 );

Title = " ";

//Settings for exploration
Value1 = V;
Value2 = V*(H-L);
Value3 = V/(H-L);

Climax = (Value2 == HHV(Value2,10));

VolumeBlast = V > Ref(V, -1) AND Climax AND V > 2*WMA( V, 8 );
Filter=Buy OR Short;
AddColumn( IIf( Buy, 66 , 83 ), "Signal", formatChar, colorDefault, IIf( Buy , colorGreen, colorRed ) );
AddColumn(Close,"Entry Price",1.4, colorDefault, IIf( Buy , colorGreen, colorRed ));
//AddColumn(dtsl,"Stop Loss",1.4, colorDefault, IIf( Buy , colorGreen, colorRed ));
AddColumn(tar1,"Target 1",1.4, colorDefault, IIf( Buy , colorGreen, colorRed ));
AddColumn(tar2,"Target 2",1.4, colorDefault, IIf( Buy , colorGreen, colorRed ));
AddColumn(tar3,"Target 3",1.4, colorDefault, IIf( Buy , colorGreen, colorRed ));

Seniors,
Please guide me
In this the Messaage Board is located at left side Bottom
Please guide me how to place the message board at the top of left side (instead of Bottom)
PriyaRamesh
 
I need some coding help urgently in Two AFLs.I will be very obliged for any help or helpful suggestions.
I need help to show only the latest/last/most recent Shapes like buy/sell arrow or IDNR7 etc. The idea is to have a cleaner chart so that it doesn't look clattered with shapes. Is there a way to do it? I tried barcount or lastvalue, but for want of expertise I couldn't achieve the desired result. I will be very thanksful for expert's help.
This is the code for IDNRs :

_SECTION_BEGIN("IDNRs");
ShowINRs = ParamToggle("Show INRs", "No|Yes", 0);
R = H - L;
NR7 = False;
NR4 = False;
m7 = m4 = idm7 = idm4 = idm = 0;
for(i = 7; i < BarCount; i++)
{
if( R < R[i - 1] AND R < R[i -2] AND R < R[i - 3] AND R < R[i - 4] AND R < R[i - 5] AND R < R[i - 6])
{
NR7 = True;
m7 = 1;
}
}
for(i = 4; i < BarCount; i++)
{
if((R < R[i - 1] AND R < R[i -2] AND R < R[i - 3] ) AND NOT NR7)
{
NR4 = True;
m4 = 1;
}
}
IDNR7 = Inside() * NR7;
IDNR4 = Inside() * NR4;
ID = Inside();
idm7 = IIf(IDNR7, 1, 0);
idm4 = IIf(IDNR4, 1, 0);
idm = IIf(ID, 1, 0);

for(i = 1; i < BarCount; i++)
{
if(IDNR7 == IDNR7[i - 1]) idm7 = idm7 + idm7[i - 1];
if(IDNR4 == IDNR4[i - 1]) idm4 = idm4 + idm4[i - 1];
if(NR7 == NR7[i - 1]) m7 = m7 + m7[i - 1];
if(NR4 == NR4[i - 1]) m4 = m4 + m4[i - 1];
if(ID == ID[i - 1]) idm = idm + idm[i - 1];
}

MarkerIDNR7 = MarkerIDNR4 = shapeStar ;

Marker7 = shapeDigit7;
NR7Color = colorGreen;

Marker4 = shapeDigit4;
NR4Color = colorOrange;

MarkerID = shapeCircle;
IDColor = colorRed;

IDNR7Color = colorBrightGreen;
IDNR4Color = colorLightOrange;

MarkerDist = L * 0.995;
IDNRDist = H * 1.03;

if(ShowINRs)
{
PlotShapes(IIf(IDNR7, MarkerIDNR7, shapeNone), IDNR7Color, 0, IDNRDist);
PlotShapes(IIf(IDNR4 AND NOT IDNR7, MarkerIDNR4, shapeNone), IDNR4Color, 0, IDNRDist);
PlotShapes(IIf(NR7 AND NOT ID, Marker7, shapeNone), NR7Color, 0, MarkerDist);
PlotShapes(IIf(NR4 AND NOT NR7 AND NOT ID, Marker4, shapeNone), NR4Color, 0, MarkerDist);
PlotShapes(IIf(ID AND NOT NR7 AND NOT NR4, MarkerID, shapeNone), IDColor, 0, IDNRDist);
}
_SECTION_END();


(2) Is there a way to avoid For Loop in the following code as it is too memory intensive and Ami hangs because of this.
_SECTION_BEGIN("Demark Trend lines");
pc = Param("Perbent", 0.05, 0.01, 10 );
percent = pc * 1; /* Adjust this percent as necessary, I use .01 because FOREX is a 0.0000 number */
ShowTrLines = ParamToggle("Show TrLines", "No|Yes", 1);
firstpointL = 2;
firstpointH = 2;
y0=LastValue(Trough(L,percent,firstpointL));
y1=LastValue(Trough(Ref(L,-1),percent,1));

for( i = 1; i < BarCount AND y0 >= y1; i++ )
{

firstpointL++;
y0=LastValue(Trough(L,percent,firstpointL));
}
if(ShowTrLines)
{
x0=BarCount - 1 - LastValue(TroughBars(L,percent,firstpointL));
x1=BarCount - 1 - LastValue(TroughBars(Ref(L,-1),percent,1));
LineL = LineArray( x0, y0, x1, y1, 1 );
Plot( LineL, " Support", colorBrown,1 +8 + 4096);

yt0=LastValue(Peak(H,percent,firstpointH));
yt1=LastValue(Peak(Ref(H,-1),percent,1));

for(i = 1; i < BarCount AND yt0 <= yt1; i++ )
{

firstpointH++;
yt0=LastValue(Peak(H,percent,firstpointH));
}
xt0=BarCount - 1 - LastValue(PeakBars(H,percent,firstpointH));
xt1=BarCount - 1 - LastValue(PeakBars(Ref(H,-1),percent,1));
LineH = LineArray( xt0, yt0, xt1, yt1, 1 );

Plot( LineH, "Resistance", colorGreen,1 + 8 + 4096);
}
_SECTION_END();
 

trash

Well-Known Member
I need some coding help urgently in Two AFLs.I will be very obliged for any help or helpful suggestions.
I need help to show only the latest/last/most recent Shapes like buy/sell arrow or IDNR7 etc. The idea is to have a cleaner chart so that it doesn't look clattered with shapes. Is there a way to do it? I tried barcount or lastvalue, but for want of expertise I couldn't achieve the desired result. I will be very thanksful for expert's help.
This is the code for IDNRs :

The first code can be written much shorter (included shapes at last bar only and toggle option showing historical ones).

Code:
_SECTION_BEGIN("IDNRs");
// mods by trash 
// http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-348.html#post1086940
ShowINRs = ParamToggle( "Inside Bar (NR1,NR4,NR7)", "OFF|ON", 1 );
Showhistory = ParamToggle( "Show historical inside bars", "OFF|ON", 0);

R = H - L;
NR7 = R == LLV( R, 7 );
NR4 = R == LLV( R, 4 ) AND NOT NR7;

IDNR7 = Inside() * NR7;
IDNR4 = Inside() * NR4;
ID = Inside();

MarkerIDNR7 = MarkerIDNR4 = shapeStar;

Marker7 = shapeDigit7;
NR7Color = colorGreen;

Marker4 = shapeDigit4;
NR4Color = colorOrange;

MarkerID = shapeCircle;
IDColor = colorRed;

IDNR7Color = colorBrightGreen;
IDNR4Color = colorLightOrange;

Plot( C, "", colorDefault, GetPriceStyle() );

bi = BarIndex();
if( Showhistory )
    lastbicond = 1;
else
    lastbicond = bi == LastValue( bi );

if( ShowINRs ) {
    PlotShapes( IIf( IDNR7 AND lastbicond, MarkerIDNR7, shapeNone ), IDNR7Color, 0, H, MarkerDist = 15 );
    PlotShapes( IIf( IDNR4 AND NOT IDNR7 AND lastbicond, MarkerIDNR4, shapeNone ), IDNR4Color, 0, H, MarkerDist );
    PlotShapes( IIf( NR7 AND NOT ID, Marker7 AND lastbicond, shapeNone ), NR7Color, 0, L, -MarkerDist  );
    PlotShapes( IIf( NR4 AND NOT NR7 AND NOT ID AND lastbicond, Marker4, shapeNone ), NR4Color, 0, L, -MarkerDist );
    PlotShapes( IIf( ID AND NOT NR7 AND NOT NR4 AND lastbicond, MarkerID, shapeNone ), IDColor, 0, H, MarkerDist );
}
_SECTION_END();
 
Can any seniors help me out for writing AFL for following condition.

1. Setting standard parameters for finding Buy and sell signal for SBI. (No problem here)
2. Based on above signal, I would like to buy and Sell HDFC bank.

Thanking in advance,

Sahen.
 

Nehal_s143

Well-Known Member
This is intraday and monthly pivot afl, i want to plot pivot levels from extreme right hand side and plot only colored part, please remove extended white line plotted with colored part

seniors please help, thanks in advance

Code:
_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

TimeFrameSet(inDaily);
DayH= LastValue(Ref(H,-1));
DayL= LastValue(Ref(L,-1));
DayC= LastValue(Ref(C,-1));
TimeFrameRestore();

//Daily 
PP = (DayL + DayH + DayC)/3;
R1  =  (2 * PP) - DayL;
S1  =  (2 * PP)  - DayH;
R2  =  PP + (DayH - DayL);
S2  =  PP - (DayH - DayL);
R3 = DayH + 2*(PP - DayL);
S3 = DayL - 2*(DayH - PP);

TimeFrameSet(inMonthly);
MonthH= LastValue(Ref(H,-1));
MonthL= LastValue(Ref(L,-1));
MonthC= LastValue(Ref(C,-1));
TimeFrameRestore();

//Monthly 
MPP = (MonthL + MonthH + MonthC)/3;
MR1  =  (2 * MPP) - MonthL;
MS1  =  (2 * MPP)  - MonthH;
MR2  =  MPP + (MonthH- MonthL);
MS2  =  MPP - (MonthH- MonthL);
MR3  =  MonthH + 2*(MPP - MonthL);
MS3 =   MonthL - 2*(MonthH- MPP);

SHOWDPIVOTS = ParamToggle("Daily Pivots", "No|Yes",1);
SHOWMPIVOTS = ParamToggle("Monthly Pivots","No|Yes",0); 
SHOW3 = ParamToggle("3rd Line", "No|Yes",0); 

	
for (i=BarCount-2;i>(BarCount-13);i--)//set the last bars to the final PP value
{
	PP[i] = PP[BarCount-1];
	R1[i] = R1[BarCount-1];
	R2[i] = R2[BarCount-1];
	S1[i] = S1[BarCount-1];
	S2[i] = S2[BarCount-1];

	ColorG[i] = colorLime;
	ColorB[i] = colorSkyblue;
	ColorR[i] = colorPink;
}

//
// Conceal all but the trailing portion of the line

for (i=0;i<BarCount-15;i++) //hide the line except most recent 15 bars
{
	ColorR[i] = ColorG[i] = ColorB[i] = Null;
}


if (SHOWDPIVOTS) {
Plot(R2, "R2",ColorG);
Plot(R1, "R1",ColorG);
Plot(PP, "PP",ColorB);
Plot(S1, "S1",ColorR);
Plot(S2, "S2",ColorR);
}

if (SHOWDPIVOTS & SHOW3)
{
		Plot(S3, "S3",ColorR);
		Plot(R3, "R3",ColorG);
}



if (SHOWMPIVOTS) {
Plot(MPP, "MPP",ColorB);
Plot(MR1, "MR1",ColorG);
Plot(MS1, "MS1",ColorR);
Plot(MS2, "MS2",ColorR);
Plot(MR2, "MR2",ColorG);
}

if (SHOWMPIVOTS & SHOW3)
{
		Plot(MR3, "MR3",ColorG);
		Plot(MS3, "MS3",ColorR);
}
 

Similar threads