Simple Coding Help - No Promise.

@tangotaurian: Hope it helps you. Thanks.

Code:
_SECTION_BEGIN("Buy Sell Level Plots");

//===================Change below conditions to match yours ======================
Buy = Cross(EMA(C,5), C);
Short = Cross(C, EMA(C,5));
//================= Change the above conditions to match yours ================
Buy = ExRem(Buy,Short);
Short = ExRem(Short,Buy);

PlotShapes(Buy*shapeUpArrow,colorGreen,0,L,-25);
PlotShapes(Short*shapedownarrow,colorred,0,H,-25);


SLLimit = Param("SL Abs Points",35,1,100,1);
TP1 = Param("TGT1 Range %",1,0.5,5,0.25);//min is 0.5% and max is 5% with increaments of 0.25%
TP2 = Param("TGT2 Range %",1.5,0.5,5,0.25);//min is 0.5% and max is 5% with increaments of 0.25%
TP3 = Param("TGT3 Range %",2,0.5,5,0.25);//min is 0.5% and max is 5% with increaments of 0.25%
TP4 = Param("TGT4 Range %",2.5,0.5,5,0.25);//min is 0.5% and max is 5% with increaments of 0.25%
TP5 = Param("TGT5 Range %",3,0.5,5,0.25);//min is 0.5% and max is 5% with increaments of 0.25%

ShowBuySell = ParamToggle("Show Buy Sell Levels","Yes|No",1);

entry=0;
sig = Null;
sl = Null;
tar1 = 0;
tar2 = 0;
tar3 = 0;
tar4 = 0;
tar5 = 0;
bars = Null;
Clr = Null;


for(i=BarCount-1;i>1;i--)

{if((Buy[i] == 1) )
{
entry = C[i];
sig = "BUY";
BuyPrice = ValueWhen(entry, C[i]);
BuyPrice = ceil(BuyPrice*20)/20;

sl = BuyPrice-SLlimit;
sl = floor(sl*20)/20;
tar1 = BuyPrice+((entry*TP1)/100);
tar1 = floor(tar1*20)/20;
tar2 = BuyPrice+((entry*TP2)/100);
tar2 = floor(tar2*20)/20;
tar3 = BuyPrice+((entry*TP3)/100);
tar3 = floor(tar3*20)/20;
tar4 = BuyPrice+((entry*TP4)/100);
tar4 = floor(tar4*20)/20;
tar5 = BuyPrice+((entry*TP5)/100);
tar5 = floor(tar5*20)/20;

Clr = colorLime;
TxtClr = colorBlue;
Tgt1Clr = colorLightBlue;
Tgt2Clr = colorGreen;
Tgt3Clr = colorAqua;
Tgt4Clr = colorTurquoise;
Tgt5Clr = colorbluegrey;
bars = i;
i = 0;
}

if((Short[i] == 1))
{
sig = "SELL";
entry = C[i];
SellPrice = ValueWhen(entry, C[i]);
SellPrice = floor(SellPrice*20)/20;

sl = SellPrice+sllimit;
sl = ceil(sl*20)/20;
tar1 = SellPrice-((entry*TP1)/100);
tar1 = ceil(tar1*20)/20;
tar2 = SellPrice-((entry*TP2)/100);
tar2 = ceil(tar2*20)/20;
tar3 = SellPrice-((entry*TP3)/100);
tar3 = ceil(tar3*20)/20;
tar4 = SellPrice-((entry*TP4)/100);
tar4 = ceil(tar4*20)/20;
tar5 = SellPrice-((entry*TP5)/100);
tar5 = ceil(tar5*20)/20;

Clr = colorRed;
TxtClr = colorOrange;
Tgt1Clr = colorViolet;
Tgt2Clr = colorRed;
Tgt3Clr = colorplum;
Tgt4Clr = colorgrey40;
Tgt5Clr = colorcustom12;
bars = i;
i = 0;
}}


Offset = 5;

ssl = IIf(bars == BarCount-1, sl[BarCount-1], Ref(sl, -1));
sl = ssl[BarCount-1];
tar1=tar1[BarCount-1];
tar2=tar2[BarCount-1];
tar3=tar3[BarCount-1];
tar4=tar4[BarCount-1];
tar5=tar5[BarCount-1];



if(ShowBuySell)
{
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "Entry", Clr, styledashed|styleNoTitle|stylenolabel, Null, Null, Offset);
Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "S/L", Clr, styledashed|styleNoTitle|stylenolabel, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "Trgt1", Clr, styledashed|styleNoTitle|stylenolabel, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "Trgt2", Clr, styledashed|styleNoTitle|stylenolabel, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "Trgt3", Clr, styledashed|styleNoTitle|stylenolabel, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar4, BarCount, tar4,1), "Trgt4", Clr, styledashed|styleNoTitle|stylenolabel, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar5, BarCount, tar5,1), "Trgt2", Clr, styledashed|styleNoTitle|stylenolabel, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+Writeval(entry,1.2), BarCount+2,entry,Null,TxtClr);
PlotText("SL@"+WriteVal(sl,1.2), BarCount+2,sl,Null,ColorDarkYellow);
PlotText("T1@"+WriteVal(tar1,1.2), BarCount+2,tar1,Null,Tgt1Clr);
PlotText("T2@"+WriteVal(tar2,1.2), BarCount+2,tar2,Null,Tgt2Clr);
PlotText("T3@"+WriteVal(tar3,1.2), BarCount+2,tar3,Null,Tgt3Clr);
PlotText("T4@"+WriteVal(tar4,1.2), BarCount+2,tar4,Null,Tgt4Clr);
PlotText("T5@"+WriteVal(tar5,1.2), BarCount+2,tar5,Null,Tgt5Clr);
}
}

_SECTION_END();
@ bbhanushali - Sincere apologies Sir, couldn’t reply you on time due to family emergency. I’ve cross checked the code & seem buy/sell signals are generating as per respective tf. Please see below hr tf:
afl.png


However I am looking out for the signals based on 5 day ema as below. Please see below the hr tf with manually marked signals:
5ema.png


I am using below 5ema afl code on intraday chart for buy/sell signals, adding entry signals with SL and TGTs would suffice may be.

_SECTION_BEGIN("Daily EMA");
TimeFrameSet(inDaily);
daema=EMA(C,5);
ddaema=TimeFrameExpand(daema,inDaily,expandFirst);
TimeFrameRestore();
Plot(ddaema,"5 DEMA",colorBlue,styleStaircase|styleDots);
_SECTION_END();

Requesting you to look into the issue and update it.

Thanking you!
TT
 
@ bbhanushali - Sincere apologies Sir, couldn’t reply you on time due to family emergency. I’ve cross checked the code & seem buy/sell signals are generating as per respective tf. Please see below hr tf:
View attachment 33750

However I am looking out for the signals based on 5 day ema as below. Please see below the hr tf with manually marked signals:
View attachment 33752

I am using below 5ema afl code on intraday chart for buy/sell signals, adding entry signals with SL and TGTs would suffice may be.

_SECTION_BEGIN("Daily EMA");
TimeFrameSet(inDaily);
daema=EMA(C,5);
ddaema=TimeFrameExpand(daema,inDaily,expandFirst);
TimeFrameRestore();
Plot(ddaema,"5 DEMA",colorBlue,styleStaircase|styleDots);
_SECTION_END();

Requesting you to look into the issue and update it.

Thanking you!
TT
@tangotaurian: If there is no other condition but just the price cross and close up 5DEMA for Buy and price cross and close down 5DEMA for Short then the attached code if you replace in between the lines where it is said "Change below conditions to match yours" and "Change the above conditions to match yours" should work. You can try out the additional condition by removing the commented lines. Thanks.
Code:
_SECTION_BEGIN("Daily EMA");
TimeFrameSet(inDaily);
daema=EMA(C,5);
TimeFrameRestore();

ddaema=TimeFrameExpand(daema,inDaily,expandFirst);
Plot(ddaema,"5 DEMA",colorBlue,styleStaircase|styleDots);

Buy = Cross(C,ddaema) ;//AND C>O;//additional condition commented out
Short = Cross(ddaema,C);// AND C<O;//additional condition commented out


_SECTION_END();
 

kumudhan

Well-Known Member
Screenshot_1.png

RESPECTED SENIORS, NEED HELP..
1.in the chart im postingit shows yesterday hi lo close is plotted as dotted lines.i want these lelels are given in price axis too, like the today hi low levels are showing.
2.i want todays open too show like today hi and low.
3.today hih low lines are extended in yesterday chart area too.i want them to show in today chart area only...
i tried many times and unable to do this..giving the afl herewith..pl help.thanks in advance.
_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("PreDay HLC");
function CDL( array )
{
doy = DayOfYear();
Lastdoy = doy == LastValue( doy );
Dayline = array * Lastdoy;
return IIf( Dayline, Dayline, Null );
}
//TIME FRAME CALCULATION
H1 = TimeFrameGetPrice( "H", inDaily, -1 ); // yesterdays high
L1 = TimeFrameGetPrice( "L", inDaily, -1 ); // low
C1 = TimeFrameGetPrice( "C", inDaily, -1 ); // close
DayO = TimeFrameGetPrice( "-1", inDaily ); // current day open
//PLOTS
Plot( cdl( H1 ), "", colorRed, styleLine + styleNoRescale + styleNoLabel+ styleDashed );
Plot( cdl( L1 ), "", colorBrightGreen, styleLine + styleNoRescale + styleNoLabel + styleDashed );
Plot( cdl( C1 ), "", colorLightGrey, styleLine + styleNoRescale + styleNoLabel + styleDashed );
Plot (LastValue(TimeFrameGetPrice("High", inDaily, 1)), "Prev H", colorGreen);
Plot (LastValue(TimeFrameGetPrice("Low", inDaily, 1)), "Prev L", colorOrange);
_SECTION_END();
 
View attachment 33779
RESPECTED SENIORS, NEED HELP..
1.in the chart im postingit shows yesterday hi lo close is plotted as dotted lines.i want these lelels are given in price axis too, like the today hi low levels are showing.
2.i want todays open too show like today hi and low.
3.today hih low lines are extended in yesterday chart area too.i want them to show in today chart area only...
i tried many times and unable to do this..giving the afl herewith..pl help.thanks in advance.
_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("PreDay HLC");
function CDL( array )
{
doy = DayOfYear();
Lastdoy = doy == LastValue( doy );
Dayline = array * Lastdoy;
return IIf( Dayline, Dayline, Null );
}
//TIME FRAME CALCULATION
H1 = TimeFrameGetPrice( "H", inDaily, -1 ); // yesterdays high
L1 = TimeFrameGetPrice( "L", inDaily, -1 ); // low
C1 = TimeFrameGetPrice( "C", inDaily, -1 ); // close
DayO = TimeFrameGetPrice( "-1", inDaily ); // current day open
//PLOTS
Plot( cdl( H1 ), "", colorRed, styleLine + styleNoRescale + styleNoLabel+ styleDashed );
Plot( cdl( L1 ), "", colorBrightGreen, styleLine + styleNoRescale + styleNoLabel + styleDashed );
Plot( cdl( C1 ), "", colorLightGrey, styleLine + styleNoRescale + styleNoLabel + styleDashed );
Plot (LastValue(TimeFrameGetPrice("High", inDaily, 1)), "Prev H", colorGreen);
Plot (LastValue(TimeFrameGetPrice("Low", inDaily, 1)), "Prev L", colorOrange);
_SECTION_END();

@kumudhan: Hope this is what you are looking for. Hope it helps.

Code:
_SECTION_BEGIN("PreDay HLC and Today OHL");
function CDL( array )
{
doy = DayOfYear();
Lastdoy = doy == LastValue( doy );
Dayline = array * Lastdoy;
return IIf( Dayline, Dayline, Null );
}
//TIME FRAME CALCULATION
H1 = TimeFrameGetPrice( "H", inDaily, -1 ); // yesterdays high
L1 = TimeFrameGetPrice( "L", inDaily, -1 ); // low
C1 = TimeFrameGetPrice( "C", inDaily, -1 ); // close
DayO = TimeFrameGetPrice( "O", inDaily,0 ); // current day open
DayH = TimeFrameGetPrice("H", inDaily,0);// current day high
DayL = TimeFrameGetPrice("L", inDaily,0);// current day low
//PLOTS
Plot( cdl( H1 ), "", colorRed, styleLine + styleNoLabel+ styleDashed );
Plot( cdl( L1 ), "", colorBrightGreen, styleLine  + styleNoLabel + styleDashed );
Plot( cdl( C1 ), "", colorLightGrey, styleLine  + styleNoLabel + styleDashed );
Plot( cdl( DayH ), "", colorgreen, styleLine  + styleNoLabel + styleDashed );
Plot( cdl( DayL ), "", colorOrange, styleLine + styleNoLabel + styleDashed );
Plot( cdl( DayO ), "", colorwhite, styleLine  + styleNoLabel + styleDashed );

PlotText("PDH = "+NumToStr(H1[BarCount-1],1.2), BarCount+2, (H1[BarCount-1]), colorred) ;
PlotText("PDL = "+NumToStr(L1[BarCount-1],1.2), BarCount+2, (L1[BarCount-1]), colorbrightgreen) ;
PlotText("PDC = "+NumToStr(C1[BarCount-1],1.2), BarCount+2, (C1[BarCount-1]), colorlightGrey) ;

PlotText("DayH = "+NumToStr(DayH[BarCount-1],1.2), BarCount+2, (DayH[BarCount-1]), colorgreen) ;
PlotText("DayL = "+NumToStr(DayL[BarCount-1],1.2), BarCount+2, (DayL[BarCount-1]), colorOrange) ;
PlotText("DayO = "+NumToStr(DayO[BarCount-1],1.2), BarCount+2, (DayO[BarCount-1]), colorwhite) ;

//Plot (LastValue(TimeFrameGetPrice("High", inDaily, 1)), "Prev H", colorGreen);
//Plot (LastValue(TimeFrameGetPrice("Low", inDaily, 1)), "Prev L", colorOrange);

_SECTION_END();
 

ethan hunt

Well-Known Member
@Happy_Singh

Hi,

Looking for AFL with following conditions:

Several AFLs on web but none suits my requirement. Tried to tweak but failed.

ORB

15min

Buy at break of HIGH of first candle of the day, no entry after 2.15pm.
Target 30 points profit or if Target not met exit at 3.00pm.
SL=Low of first candle.
Entry / Exit at open of next candle.


Short at break of LOW of first candle of the day, no entry after 2.15pm.
Target 30 points profit or if Target not met exit at 3.00pm.
SL=High of first candle.
Entry / Exit at open of next candle.


Brokerage = 0.02% (can be set in back test settings)
Leverage = 4x (Futures) (can be set = 25 in back test settings)


Changeable parameters:
Chart duration - 15min to 5m, 30m, Hourly etc.
Target - can be changed from fixed to fixed (30 to say 50) and also can be changed from fixed to %.
Stoploss - can be changed from High/Low to fixed and %.
Time of exit
Margin (can be set in back test settings)
Minimum number of shares 20 (can be set in back test settings)
Maximum number of shares 1000

Should be Backtestable , Scannable , Explorable.

AFL experts kindly help.

Thanks

Bump-up !

Thanks
 

kumudhan

Well-Known Member
@kumudhan: remove the "+ styleNoLabel" from the plot part and you will get values in the axis. However, if you have tried the given afl (since you have posted your old chart) you will see that the text is also given with values e.g. PDH =Value (i.e. Previous Day High = xValue). Chose what you want.
yes ji i tried that..but in tick chart the text goes to extream right..thanj you again.
 
I don't know if this is simple or not, but!
could you help me write this efl formula, please
search for:
-find stocks that trade above $5.00
-find stocks that have average volume of 200000 shares in last 90 days
-stochastic in oversold - under 20
-bulish engulfing signal

thank you very much
 

Similar threads