Simple Coding Help - No Promise.

Nehal_s143

Well-Known Member
this is similar to my post http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-66.html#post917608

only difference is code posted by me show less no. of swing high lows compare to the code posted here :) basically requirement is same

to plot daily signal/levels in 5 min chart

pls help me to plot the daily timeframe signals in 5 min time frame

_SECTION_BEGIN("Tops-Bottoms-2-3's");
xx=BarIndex();x=xx;Lx=LastValue(x);
nbar=3;
fc=2;
frat=3;
t=H>Ref(HHV(H,frat),-1) AND Ref(HHV(H,frat),frat)<H;
PHighPrice0=ValueWhen(t,H);
b=L<Ref(LLV(L,frat),-1) AND Ref(LLV(L,frat),frat)>L;
PLowPrice0=ValueWhen(b,L);
p=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
d=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
pk=t OR p; tr=b OR d;

px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);

Disp2=ParamToggle("Display 2-3's Labels","Show|Hide",1);

Disp3=ParamToggle("Color Labels Behind 2-3's","Show|Hide",1);
if(Disp3){
PlotShapes(shapeSquare*tr,IIf(Lx-ValueWhen(tr,x)>nbar,colorLime,colorCustom1),0,L,-10);
PlotShapes(shapeSquare*pk,IIf(Lx-ValueWhen(pk,x)>nbar,ColorRGB(255,160,122),colorCu stom1),0,H,10);}

dxhm=14; dxlm=10;dxh=3;dxl=2;dyhm=5;
dylm=3;dyh=5;dyl=15;hm=30;lm=30;
function GetVisibleBarCount()
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
return Min(lvb-fvb,BarCount-fvb);
}
function GfxConvertPixelsToBarX(Pixels)
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
pxchartleft=Status("pxchartleft");
pxchartwidth=Status("pxchartwidth");
fac=pxchartwidth/Pixels;
bar=(lvb-fvb)/fac;
return bar;
}
function GfxConvertPixelToValueY(Pixels)
{
local Miny,Maxy,pxchartbottom,pxchartheight;
Miny=Status("axisminy");
Maxy=Status("axismaxy");
pxchartbottom=Status("pxchartbottom");
pxchartheight=Status("pxchartheight");
fac=pxchartheight/Pixels;
Value=(Maxy-Miny)/fac;
return Value;}

if(Disp2)
{
ll=tr AND tl1<tl2; hl=tr AND tl1>tl2; hh=pk AND ph1>ph2;
lh=pk AND ph1<ph2; dt=pk AND ph1==ph2; db=tr AND tl1==tl2;

miny=Status("axisminy");
maxy=Status("axismaxy");
AllVisibleBars=GetVisibleBarCount();
fvb=Status("firstvisiblebar");
LowMargin=Miny+GfxConvertPixelToValueY(lm);
HighMargin=Maxy-GfxConvertPixelToValueY(hm);
dyllm=GfxConvertPixelToValueY(dylm);
dyhhm=GfxConvertPixelToValueY(dyhm);
dyll=GfxConvertPixelToValueY(dyl);
dyhh=GfxConvertPixelToValueY(dyh);
dxllm=GfxConvertPixelsToBarX(dxlm);
dxhhm=GfxConvertPixelsToBarX(dxhm);
dxll=GfxConvertPixelsToBarX(dxl);
dxhh=GfxConvertPixelsToBarX(dxh);

for(i=0;i<AllVisibleBars;i++)
{
if(ll[i+fvb] AND L[i+fvb]>LowMargin) PlotText("Buy",i+fvb+dxll,L[i+fvb]-dyll,colorBlack);
if(ll[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("Buy",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorBlack);
if(hl[i+fvb] AND L[i+fvb]>LowMargin) PlotText("Buy",i+fvb+dxll,L[i+fvb]-dyll,colorBlack);
if(hl[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("Buy",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorBlack);
if(db[i+fvb] AND L[i+fvb]>LowMargin) PlotText("Buy",i+fvb+dxll,L[i+fvb]-dyll,colorBlack);
if(db[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("Buy",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorBlack);
if(hh[i+fvb] AND H[i+fvb]<HighMargin) PlotText("Sell",i+fvb+dxhh,H[i+fvb]+dyhh,colorBlack);
if(hh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("Sell",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorBlack);
if(lh[i+fvb] AND H[i+fvb]<HighMargin) PlotText("Sell",i+fvb+dxhh,H[i+fvb]+dyhh,colorBlack);
if(lh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("Sell",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorBlack);
if(dt[i+fvb] AND H[i+fvb]<HighMargin) PlotText("Sell",i+fvb+dxhh,H[i+fvb]+dyhh,colorBlack);
if(dt[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("Sell",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorBlack);
}}

_SECTION_END();

_SECTION_BEGIN("Price1");
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();
 
Dear all I have found nr afl can we change it in parameters like if i need nr4/7/21 as per requirement at per the afl provide by pratap sir AFL SRSARTFtj here is the code of afl
kindly covert if possible. and can the gap between bar and number decreases as in this it is quite far will be good if it comes just above the bar..
_SECTION_BEGIN("NR7");

/*********** NR7 System for Chart and Exploration ***********************/

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 = colorBrightGreen;

Marker4 = shapeDigit4;
NR4Color = colorLightOrange;

MarkerID = shapeHollowCircle;
IDColor = colorYellow;

IDNR7Color = colorBrightGreen;
IDNR4Color = colorLightOrange;

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

if(Status("action") == actionIndicator)
{
_N(Title = StrFormat("{{NAME}}, {{DATE}} ({{INTERVAL}}): {{VALUES}}") + ", Range=" + Prec(R + 0.00001, 2) + ","
+ WriteIf(IDNR7, EncodeColor(colorBrightGreen) + WriteIf(idm7 > 1, StrLeft(NumToStr(idm7), 4), "") + " IDNR7 ", "")
+ WriteIf(IDNR4, EncodeColor(colorLightOrange) + WriteIf(idm4 > 1, StrLeft(NumToStr(idm4), 4), "") + " IDNR4 ", "")
+ WriteIf(NR7 AND NOT ID, EncodeColor(colorBrightGreen) + WriteIf(m7 > 1, StrLeft(NumToStr(m7), 4), "") + " NR7 ", "")
+ WriteIf(NR4 AND NOT ID, EncodeColor(colorLightOrange) + WriteIf(m4 > 1, StrLeft(NumToStr(m4), 4), "") + " NR4 ", "")
+ WriteIf(ID AND NOT NR7 AND NOT NR4, EncodeColor(colorTurquoise) + WriteIf(idm > 1, StrLeft(NumToStr(idm), 4), "") + " Inside Day ", ""));

PlotOHLC(O, H, L, C, "Close", colorLightGrey, styleBar);
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);
}

if(Status("action") == actionExplore)
{
Filter = (m7 > 0) OR (m4 > 0) OR (idm > 0);

SetOption("NoDefaultColumns", True);

AddColumn(DateTime(), "DATE", formatDateTime, colorDefault, colorDefault, 96);
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 120);
AddColumn(R, "Range", 6.2, colorDefault, colorDefault, 84);
AddColumn(IIf(idm, 48 + idm, 32), "INSIDE", formatChar, colorYellow, IIf(idm, colorLightBlue, colorDefault));
AddColumn(IIf(m4, 48 + m4, 32), "NR4", formatChar, colorYellow, IIf(m4, colorBlue, colorDefault));
AddColumn(IIf(m7, 48 + m7, 32), "NR7", formatChar, colorYellow, IIf(m7, colorGreen, colorDefault));
}

/************************** END OF AFL CODE *****************************/

_SECTION_END();
 

VJAY

Well-Known Member
Dear Happy singh/pratap,
What code could include for on/off one afl by parameter....ex..i use TDST lines in my chart...but I want to use it only when it need so I need to on/off by parameter window as like your VWAP afl :)
 

Nehal_s143

Well-Known Member
Dear Happy singh/pratap,
What code could include for on/off one afl by parameter....ex..i use TDST lines in my chart...but I want to use it only when it need so I need to on/off by parameter window as like your VWAP afl :)
use

if (ParamToggle("SNR","NONE|YES",1))
{
Plot(r3,"",10,1|styleNoRescale);PlotText( "R3 : "+r3+"", BarCount+2, LastValue(r3), 10,1);
Plot(r2,"",10,1|styleNoRescale);PlotText( "R2 : "+r2+"", BarCount+2, LastValue(r2), 10,1);
Plot(r1,"",10,1|styleNoRescale);PlotText( "R1 : "+r1+"", BarCount+2, LastValue(r1), 10,1);
Plot(pp,"",6,8|styleNoRescale);PlotText( "Pivot : "+pp+"", BarCount+3, LastValue(pp), 6,1);
Plot(s1,"",11,1|styleNoRescale);PlotText( "S1 : "+s1+"", BarCount+2, LastValue(s1), 10,1);
Plot(s2,"",11,1|styleNoRescale);PlotText( "S2 : "+s2+"", BarCount+2, LastValue(s2), 10,1);
Plot(s3,"",11,1|styleNoRescale);PlotText( "S3 : "+s3+"", BarCount+2, LastValue(s3), 10,1);
}

use TDST lines instead of Support & Resi
 
mehtaka

Code:
	md = IIf((Month()==9 OR Month()==4 OR Month()==6 OR Month()==11), 30, IIf(Month()==2, 28 + (Year()%4 == 0 AND Year()%100!=0), 31));
	expiry = ((md == Day()) AND (DayOfWeek() >= 1) AND (DayOfWeek() <= 5)) OR ((md - Day() <= 2) AND (DayOfWeek() == 5));
	PlotShapes(expiry * shapeDigit1, colorBlack);
The expiry variable identifies the last working day of a month (assuming Mon-Friday week). It does not factor in Holidays. Shape is only for verification purposes; Use this expiry variable to adjust your buy / sell / short / cover signals
hi
Did tried the codes you have wrote, but no sucess
I have done coding this way...posting my afl
but stil its not completing trade on expiry and strting new trade on next day

SD1 = ParamDate( "Start Date 1", "2013-04-01" );
ED1 = ParamDate( "Expiry Date 1", "2013-04-30" );

SD2 = ParamDate( "Start Date 2", "2013-05-01" );
ED2 = ParamDate( "Expiry Date 2", "2013-05-31" );

SD3 = ParamDate( "Start Date 3", "2013-06-01" );
ED3 = ParamDate( "Expiry Date 3", "2013-06-28" );

SD4 = ParamDate( "Start Date 4", "2013-07-01" );
ED4 = ParamDate( "Expiry Date 4", "2013-07-31" );

SD5 = ParamDate( "Start Date 5", "2013-08-01" );
ED5 = ParamDate( "Expiry Date 5", "2013-08-30" );

SD6 = ParamDate( "Start Date 6", "2013-09-01" );
ED6 = ParamDate( "Expiry Date 6", "2013-09-30" );

SD7 = ParamDate( "Start Date 7", "2013-10-01" );
ED7 = ParamDate( "Expiry Date 7", "2013-10-31" );

SD8 = ParamDate( "Start Date 8", "2013-11-01" );
ED8 = ParamDate( "Expiry Date 8", "2013-11-29" );

SD9 = ParamDate( "Start Date 9", "2013-12-01" );
ED9 = ParamDate( "Expiry Date 9", "2013-12-31" );

//OR (DateNum() >= expiryDate);
Buy = EMA(C,13) > EMA(C,34) AND Close > EMA(C,100)
AND ((DateNum() <= SD1) OR
(DateNum() <= SD2 ) OR (DateNum() <= SD3) OR (DateNum() <= SD4 ) OR
(DateNum() <= SD5 ) OR (DateNum() <= SD6) OR (DateNum() <= SD7 ) OR
(DateNum() <= SD8 ) OR (DateNum() <= SD9 ));


Sell = EMA(C,13) < EMA(C,34) OR Close < EMA(C,100) AND ((DateNum() >= ED1) OR
(DateNum() >= ED2) OR (DateNum() >= ED3) OR (DateNum() >= ED4) OR
( DateNum() >= ED5) OR (DateNum() >= ED6) OR (DateNum() >= ED7) OR
( DateNum() >= ED8) OR (DateNum() >= ED9));

Short = EMA(C,13) < EMA(C,34) AND Close < EMA(C,100)
AND ((DateNum() <= SD1) OR
(DateNum() <= SD2 ) OR (DateNum() <= SD3) OR (DateNum() <= SD4 ) OR
(DateNum() <= SD5 ) OR (DateNum() <= SD6) OR (DateNum() <= SD7 ) OR
(DateNum() <= SD8 ) OR (DateNum() <= SD9 ));


Cover = EMA(C,13) > EMA(C,34) OR Close > EMA(C,100) AND ((DateNum() >= ED1) OR
(DateNum() >= ED2) OR (DateNum() >= ED3) OR (DateNum() >= ED4) OR
( DateNum() >= ED5) OR (DateNum() >= ED6) OR (DateNum() >= ED7) OR
( DateNum() >= ED8) OR (DateNum() >= ED9));
 

Nehal_s143

Well-Known Member
hi

I want to add this condition for buy and sell, tried many ways but not able ot write correct code, please help to write below condition

buy if todays low price is lowest in last 6 days
or
buy if current candle low price is lowest in last 6 candel

sell if todays high price is highest in last 6 days
of
sell if current candle high price is highest in last 6 candles


this buy/sell is for trend reversal.
 

mastermind007

Well-Known Member
use

if (ParamToggle("SNR","NONE|YES",1))
{
....
}

use TDST lines instead of Support & Resi
Good Work, Nehal!

Only a small improvement; Its better to use comparison in line with Param Toggle like this

if (ParamToggle("SNR","NONE|YES",1) == 1)

OR

if (ParamToggle("SNR","NONE|YES",1) == 0)

Another AFL function that can be used to turn On or turn Off anything selectively is ParamList where the selected choice is returned as string and you have to compare result with strings.
 

mastermind007

Well-Known Member
hi

I want to add this condition for buy and sell, tried many ways but not able ot write correct code, please help to write below condition

buy if todays low price is lowest in last 6 days
or
buy if current candle low price is lowest in last 6 candel

sell if todays high price is highest in last 6 days
of
sell if current candle high price is highest in last 6 candles

this buy/sell is for trend reversal.
Nehal

Both are exactly same conditions. In EOD chart, it will compare 6 days, In Intraday chart of 5 mins, it will span 30 minutes (5 x 6)
Code:
Buy = Low == LLV(Low, 6);
Short = High == HHV(High, 6);
Spend some time defining Sell and Cover. Do not automatically resort to
Code:
Cover = Buy; Sell = Short;
 

mastermind007

Well-Known Member
hi
Did tried the codes you have wrote, but no sucess
I have done coding this way...posting my afl
but stil its not completing trade on expiry and strting new trade on next day

SD1 = ParamDate( "Start Date 1", "2013-04-01" );
ED1 = ParamDate( "Expiry Date 1", "2013-04-30" );

SD2 = ParamDate( "Start Date 2", "2013-05-01" );
ED2 = ParamDate( "Expiry Date 2", "2013-05-31" );

SD3 = ParamDate( "Start Date 3", "2013-06-01" );
ED3 = ParamDate( "Expiry Date 3", "2013-06-28" );

SD4 = ParamDate( "Start Date 4", "2013-07-01" );
ED4 = ParamDate( "Expiry Date 4", "2013-07-31" );

SD5 = ParamDate( "Start Date 5", "2013-08-01" );
ED5 = ParamDate( "Expiry Date 5", "2013-08-30" );

SD6 = ParamDate( "Start Date 6", "2013-09-01" );
ED6 = ParamDate( "Expiry Date 6", "2013-09-30" );

SD7 = ParamDate( "Start Date 7", "2013-10-01" );
ED7 = ParamDate( "Expiry Date 7", "2013-10-31" );

SD8 = ParamDate( "Start Date 8", "2013-11-01" );
ED8 = ParamDate( "Expiry Date 8", "2013-11-29" );

SD9 = ParamDate( "Start Date 9", "2013-12-01" );
ED9 = ParamDate( "Expiry Date 9", "2013-12-31" );

//OR (DateNum() >= expiryDate);
Buy = EMA(C,13) > EMA(C,34) AND Close > EMA(C,100)
AND ((DateNum() <= SD1) OR
(DateNum() <= SD2 ) OR (DateNum() <= SD3) OR (DateNum() <= SD4 ) OR
(DateNum() <= SD5 ) OR (DateNum() <= SD6) OR (DateNum() <= SD7 ) OR
(DateNum() <= SD8 ) OR (DateNum() <= SD9 ));


Sell = EMA(C,13) < EMA(C,34) OR Close < EMA(C,100) AND ((DateNum() >= ED1) OR
(DateNum() >= ED2) OR (DateNum() >= ED3) OR (DateNum() >= ED4) OR
( DateNum() >= ED5) OR (DateNum() >= ED6) OR (DateNum() >= ED7) OR
( DateNum() >= ED8) OR (DateNum() >= ED9));

Short = EMA(C,13) < EMA(C,34) AND Close < EMA(C,100)
AND ((DateNum() <= SD1) OR
(DateNum() <= SD2 ) OR (DateNum() <= SD3) OR (DateNum() <= SD4 ) OR
(DateNum() <= SD5 ) OR (DateNum() <= SD6) OR (DateNum() <= SD7 ) OR
(DateNum() <= SD8 ) OR (DateNum() <= SD9 ));


Cover = EMA(C,13) > EMA(C,34) OR Close > EMA(C,100) AND ((DateNum() >= ED1) OR
(DateNum() >= ED2) OR (DateNum() >= ED3) OR (DateNum() >= ED4) OR
( DateNum() >= ED5) OR (DateNum() >= ED6) OR (DateNum() >= ED7) OR
( DateNum() >= ED8) OR (DateNum() >= ED9));
mehtaka

Isme mera waala Code kahan hai?

The approach you are adopting in the above code is brute force.
 

Similar threads