Simple Coding Help - No Promise.

Nehal_s143

Well-Known Member
Seniors please help to plot the levels in complete chart instead of only current period

Hi

below afl plot level only for current period, i want to plot level for old period too as shown in snap shot, please help me to plot level on complete data





Code:
_SECTION_BEGIN("Trading");

pShowtradeLines = ParamToggle("Show Trade Lines", "No|Yes", 1);
PerctakeProfit=Param("Take Profit Percent Set",0.6,0.3,30,0.1);
PercStoploss=Param("StopLoss Percent Set",0.25,0.2,5,0.1);

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

Plot_Range = DayOfWeek() > 0;
FH_Range = DayOfWeek() > 1;

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

Num_Bars = 5;

TimeFrameSet(inWeekly);
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 = DayOfWeek() <= 1;  // monday
isdRth = DayOfWeek() > 1; // Tuesday to saturday

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

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

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);
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((NOT BuyTP2),BuyStop2,Null);
BuyTP=IIf(NOT BuyStop,BuyTP2,Null);

Bars = DayOfWeek(); // day of week is equal to bars since new week.

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),"BuyStop",colorBrightGreen,styleDots|styleNoRescale| styleNoLine);
Plot(IIf(pShowtradeLines,SellPriceline,Null),"Short Here",colorRed,styleDots|styleNoRescale);



_SECTION_END();
 

josh1

Well-Known Member
Yes . . .

Code:
_SECTION_BEGIN("HTF Price");
Cl = TimeFrameGetPrice("C",inHourly);
Op = TimeFrameGetPrice("O",inHourly);
Hi = TimeFrameGetPrice("H",inHourly);
Lo = TimeFrameGetPrice("L",inHourly);

Plot(Lo,"Lo",colorBrightGreen,styleStaircase);
Plot(Hi,"Hi",colorBrightGreen,styleStaircase);

PlotOHLC(Lo,Hi,Lo,Hi,"Hourly",IIf(Cl>Op,ColorRGB(40,40,120),ColorRGB(80,20,20)),styleNoLabel|styleCloud);
_SECTION_END();
This one is quite sufficient. Just gave parameters for colors.

Code:
_SECTION_BEGIN("HTF Price");
Cl = TimeFrameGetPrice("C",inHourly);
Op = TimeFrameGetPrice("O",inHourly);
Hi = TimeFrameGetPrice("H",inHourly);
Lo = TimeFrameGetPrice("L",inHourly);

HourlybarClr = ParamColor( "HourlyBaarColor", ColorRGB(120,120,0));
HourlyUpClr = ParamColor( "HourlyUpColor", ColorRGB(40,40,120));
HourlyDnClr = ParamColor( "HourlyDnColor", ColorRGB(80,20,20));

Plot(Lo,"Lo",HourlybarClr,styleStaircase);
Plot(Hi,"Hi",HourlybarClr,styleStaircase);
PlotOHLC(Lo,Hi,Lo,Hi,"Hourly",IIf(Cl>Op,HourlyUpClr,HourlyDnClr),styleNoLabel|styleCloud);

_SECTION_END();
Thanks. Now I just want to set sound alert for crossing Hourly H, L
 
Seniors, please help
I need an afl to draw automatically Fibo retracement levels of 50%, 38.2%, 23.6% based on yesterday's daily high and low
Till now I draw it manually using amibroker's default draw feature.
I have attached an image in support......
Please help......



check this one .Written according to your need.
Code:
_SECTION_BEGIN("FIBO");

dec = (Param("Decimals",2,0,7,1)/10)+1;
SetChartOptions(0,chartShowArrows|chartShowDates);

FibCol= ParamColor("Fib Line Color",colorOrange );//


SetBarFillColor(IIf(C>O,colorWhite ,IIf(C<O,colorCustom4 ,colorYellow)));
Plot(C,"Close",IIf(C>Ref(C,-1),colorWhite ,IIf(C<Ref(C,-1),colorSkyblue ,colorYellow )),64);


YH=TimeFrameGetPrice("H", inDaily, -1);
YL=TimeFrameGetPrice("L", inDaily, -1);

Yo=TimeFrameGetPrice("o", inDaily, -1);
Yc=TimeFrameGetPrice("c", inDaily, -1);

DD=Prec(C-Yc,2);
xx=Prec((DD/Yc)*100,2);


numbars = LastValue(Cum(Status("barvisible")));
hts = -33.5;
Today = LastValue(Day());
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);

Title = EncodeColor(55)+  Title = Name() + "     " + EncodeColor(55) + Date() +
"      " + EncodeColor(5) + "{{INTERVAL}}" +
	EncodeColor(55)+ " Open = "+ EncodeColor(52)+ WriteVal(O,dec) + 
	EncodeColor(55)+ " High = "+ EncodeColor(5) + WriteVal(H,dec) +
	EncodeColor(55)+ " Low = "+ EncodeColor(33)+ WriteVal(L,dec) + 
	EncodeColor(55)+ " Close = "+ EncodeColor(52)+ WriteVal(C,dec);


Line0=YL;
Line100=YH;

Line1 = Line0 + abs(Line100-Line0)*0.236; 
Line2 = Line0 + abs(Line100-Line0)*0.382; 
Line3 = Line0 + abs(Line100-Line0)*0.5; 
Line4 = Line0 + abs(Line100-Line0)*0.618; 
Line5= Line0 + abs(Line100-Line0)*0.786; 


Plot(C,"Price",IIf(C>O,colorGreen,colorRed),styleCandle);

Plot(IIf(Today == Day(),YL,Null), "0%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(IIf(Today == Day(),Line1,Null), "23.6%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(IIf(Today == Day(),Line2,Null), "38.2%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(IIf(Today == Day(),Line3,Null), "50%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(IIf(Today == Day(),Line4,Null), "61.8%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(IIf(Today == Day(),Line5,Null), "78.6%",FibCol,styleDashed |styleNoRescale|styleNoTitle);
Plot(IIf(Today == Day(),YH,Null), "100%",FibCol,styleDashed |styleNoRescale|styleNoTitle);

PlotText("0%= " + WriteVal(Line1,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (YL,1) , FibCol);
PlotText("23.6%= " + WriteVal(Line1,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line1,1) , FibCol);
PlotText("38.2%" + WriteVal(Line2,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line2,1) , FibCol);
PlotText("50%= " + WriteVal(Line3,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line3,1) , FibCol);
PlotText("61.8%= " + WriteVal(Line4,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line4,1) , FibCol);
PlotText("78.6%= " + WriteVal(Line5,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (Line5,1) , FibCol);
PlotText("100%= " + WriteVal(Line1,fraction),LastValue(BarIndex())-(numbars/hts),LastValue (YH,1) , FibCol);



_SECTION_END();
 

amitrandive

Well-Known Member
hi @amit

the 1st afl however looks like it should ,but its more like a trading system giving buy and sells and so the ATR is not a true ATR in this , as you can see in chart even on 5 minute chart with 13 period and 2 multiple the ATR line is more then 100 points away , but that should not be the case here , the ATR is near 16 in one candle on 8 july near closing so maximum 32 point stop loss should be drawn ..............so its actually not what i was looking for , i need a true ATR which draws exactly like this(with actual ATR stop line drawn) bro and goes above and below candles as per the trend..............kindly help :thumb::thumb:
toocool

As per my limited knowledge , I am not able to plot the ATR on a price chart.
Mostly all systems calculate the stop loss based on the ATR.

You can use the 2nd AFL , I have posted or something like Supertrend.

Experts please feel free to advice.
 
This one is quite sufficient. Just gave parameters for colors.
parameters for colors, in place of predefined colors use

Code:
ParamColor("UpColor",colorBlue), ParamColor("DNColor",colorRed)

Thanks. Now I just want to set sound alert for crossing Hourly H, L
For that you will have to use the Hi/Low of previous bar on hourly, as current bar will not give the cross . . .

use

Code:
H1 = TimeFrameGetPrice("H",inHourly,-1);
L1 = TimeFrameGetPrice("L",inHourly,-1);
UP = Cross(H,H1);		DN = Cross(L1,L);
if (SelectedValue(UP))	Say( "JOSH Please WAKE-UP . . . , We need to look for  Long trades now . . ." );
if (SelectedValue(DN))	Say( "JOSH Please WAKE-UP . . . , We need to look for Short trades now . . ." );
Happy :)
 
Last edited:

toocool

Well-Known Member
Code:
_SECTION_BEGIN("Daily Levels");


// week

WO=  TimeFrameGetPrice("O",inWeekly,-1); 
WH=  TimeFrameGetPrice("H",inWeekly,-1); 
WL=  TimeFrameGetPrice("L",inWeekly,-1);
WC=  TimeFrameGetPrice("C",inWeekly,-1);

// WEEK PIVOT Calculation
pw = ( WH+ WL + WC )/3;
sw1 = (2*pw)-WH;
sw2 = pw -(WH - WL);
sw3 = Sw1 - (WH-WL); 
rw1 = (2*pw)-WL;
rw2 = pw +(WH -WL);
rw3 = rw1 +(WH-WL);

Plot(C,"",31,64);

Plot(rw3,"WR3:",10,1|styleNoRescale);PlotText( "WR3 : "+rw3+"", BarCount+2, LastValue(rw3), 10,1);
Plot(rw2,"WR2:",10,1|styleNoRescale);PlotText( "WR2 : "+rw2+"", BarCount+2, LastValue(rw2), 10,1);
Plot(rw1,"WR1:",10,1|styleNoRescale);PlotText( "WR1 : "+rw1+"", BarCount+2, LastValue(rw1), 10,1);
Plot(pw,"PW",6,8|styleNoRescale);PlotText( "WP : "+pw+"", BarCount+3, LastValue(pw), 6,1);
Plot(sw1,"WS1:",11,1|styleNoRescale);PlotText( "WS1 : "+sw1+"", BarCount+2, LastValue(sw1), 10,1);
Plot(sw2,"WS1:",11,1|styleNoRescale);PlotText( "WS2 : "+sw2+"", BarCount+2, LastValue(sw2), 10,1);
Plot(sw3,"WS1:",11,1|styleNoRescale);PlotText( "WS3 : "+sw3+"", BarCount+2, LastValue(sw3), 10,1);

//month

MO=  TimeFrameGetPrice("O",inMonthly,-1); 
MH=  TimeFrameGetPrice("H",inMonthly,-1); 
ML=  TimeFrameGetPrice("L",inMonthly,-1);
MC=  TimeFrameGetPrice("C",inMonthly,-1);

// MONTH PIVOT Calculation
pm = ( MH+ ML + MC )/3;
sm1 = (2*pm)-MH;
sm2 = pm -(MH - ML);
sm3 = Sm1 - (MH-ML); 
rm1 = (2*pm)-ML;
rm2 = pm +(MH -ML);
rm3 = rm1 +(MH-ML);

Plot(rm3,"MR3:",10,1|styleNoRescale);PlotText( "MR3 : "+rm3+"", BarCount+2, LastValue(rm3), 10,1);
Plot(rm2,"MR2:",10,1|styleNoRescale);PlotText( "MR2 : "+rm2+"", BarCount+2, LastValue(rm2), 10,1);
Plot(rm1,"MR1:",10,1|styleNoRescale);PlotText( "MR1 : "+rm1+"", BarCount+2, LastValue(rm1), 10,1);
Plot(pm,"PM",6,8|styleNoRescale);PlotText( "MP : "+pm+"", BarCount+3, LastValue(pm), 6,1);
Plot(sm1,"MS1:",11,1|styleNoRescale);PlotText( "MS1 : "+sm1+"", BarCount+2, LastValue(sm1), 10,1);
Plot(sm2,"MS2:",11,1|styleNoRescale);PlotText( "MS2 : "+sm2+"", BarCount+2, LastValue(sm2), 10,1);
Plot(sm3,"MS3:",11,1|styleNoRescale);PlotText( "MS3 : "+sm3+"", BarCount+2, LastValue(sm3), 10,1);


_SECTION_END();


_SECTION_BEGIN("Daily Levels");


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
Dayz = TimeFrameGetPrice("C", inDaily, -6);		//		six days close


if ( True )
{
PP = (DayH + DayL + Dayc)/3;
R1  =  (2*PP) - DayL;
S1  =  (2*PP) - DayH;
R2  =  PP + (DayH - DayL);
S2  =  PP - (DayH - DayL);
R3  =  R1 + (DayH - DayL);
S3  =  S1 - (DayH - DayL);
}


// PARAMETERS
SHALD = ParamList("daily Pivots", "selected only|all|hide" );

//day
PDP = ParamList("PP",   "SHOW|HIDE" ); 
PDR1 = ParamList("R1", "SHOW|HIDE" ); 
PDR2 = ParamList("R2", "HIDE|SHOW"  ); 
PDR3 = ParamList("R3", "HIDE|SHOW" ); 

PDS1 = ParamList("S1", "SHOW|HIDE" ); 
PDS2 = ParamList("S2", "HIDE|SHOW" ); 
PDS3 = ParamList("S3", "HIDE|SHOW" ); 

DayCOLOR = 34;

/*--------------------------------------*/
// PLOTS
 style = IIf(ParamList("Chart style",
"styleCandle|styleBar")=="styleCandle",64,128);
 Plot (C,Date ()+" close",11,style);
 //day
 if ((PDP=="SHOW" OR SHALD=="all")  && SHALD!="hide") Plot (pp,"daily Pivot
",DayCOLOR,1);
 if ((PDR1=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (r1,"daily R1
",DayCOLOR,32);
 if ((PDR2=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (r2,"daily R2
",DayCOLOR,32);
 if ((PDR3=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (r3,"daily R3
",DayCOLOR,32);

 if ((PDS1=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (s1,"daily S1
",DayCOLOR,32);
 if ((PDS2=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (S2,"daily S2
",DayCOLOR,32);
 if ((PDS3=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (S3,"daily S3
",DayCOLOR,32);




_SECTION_END();
its not working as needed friend , thanks a ton though:thumb:
 

josh1

Well-Known Member
parameters for colors, in place of predefined colors use

Code:
ParamColor("UpColor",colorBlue), ParamColor("DNColor",colorRed)



For that you will have to use the Hi/Low of previous bar on hourly, as current bar will not give the cross . . .

use

Code:
H1 = TimeFrameGetPrice("H",inHourly,-1);
L1 = TimeFrameGetPrice("L",inHourly,-1);
UP = Cross(H,Hi);		DN = Cross(L1,L);
if (SelectedValue(UP))	Say( "JOSH Please WAKE-UP . . . , We need to look for  Long trades now . . ." );
if (SelectedValue(DN))	Say( "JOSH Please WAKE-UP . . . , We need to look for Short trades now . . ." );
Happy :)
Great .. If I want to add less 5 points, can I give like this ->
UP = Cross(H,Hi+5); DN = Cross(L1,L-5);
 

Similar threads