Simple Coding Help - No Promise.

Hello Sir,
we can add time delay between trades like this

Code:
// time when last buy was triggered
t1 = ValueWhen(Buy,TimeNum());

// last buy time + additional time
t2 = t1 + 000002;

// check if current time is more than or equal to t2
t3 =  Now(4) >= t2;

Buy =  t3  AND " buy condition " ;
For the 1st buy signal t1 will always be 0, so t3 will always be true and buy will be triggered, then from second buy onwards t1 will get time of previous buy.
I have not tested this in live trading :)
Best of Luck :)
Thank you so much.. But the problem is that buy is being generated on different instruments through the scanner option in amibroker,hence valuewhen(buy,timenum()) will not be generated as that chart may not have a buy existing. Any views on how to solve this?
 
Hello Sir,
we can add time delay between trades like this

Code:
// time when last buy was triggered
t1 = ValueWhen(Buy,TimeNum());

// last buy time + additional time
t2 = t1 + 000002;

// check if current time is more than or equal to t2
t3 =  Now(4) >= t2;

Buy =  t3  AND " buy condition " ;
For the 1st buy signal t1 will always be 0, so t3 will always be true and buy will be triggered, then from second buy onwards t1 will get time of previous buy.
I have not tested this in live trading :)
Best of Luck :)
I had tried this code - but this one got activated not only when short or buy was generated but on every scan making the whole process slow. I incorporated this code by kelvin hand found on TJ itself.


barcomplete = BarIndex() < LastValue(BarIndex());
GetPerformanceCounter( True );

//--- Kelvinhand: Use this part
EnableScript("jscript");


elapsed =GetPerformanceCounter();

_TRACE("elapsed = " + elapsed);

for( i = 0; i < BarCount; i++ )
{

//--- Kelvinhand -----
if( BARCOMPLETE AND Short[ i ] > 0 ) //
AlertIf( barcomplete AND Short, "EXEC C:\\calc.exe, 3);
<%
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
sleep(500);
//_TRACE(Now());

%>
 
Hello :)
This indicator is quite nice, but if anywhere volume is missing, then indicator gets messed up :)
This is what is giving problems ---- C-Ref(C,-1)
if previous close is 55 and current close is 54, 54-55 = -1, if this difference is very small, it will give problems because it is later divided then mutiplied and then its ema is taken :)
@Romeo1998
So what could be the solution ?
Sometimes on higher timeframe it is working ok but in lower timeframe it gets messed up and doesn't show anything :confused:
 
Respected seniors,i need help. plz plot buy sell signal on afl

_SECTION_BEGIN("Heiken Ashi Smoothed");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorBlack ));
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;

p=Param("Period",6,2,30,1);
Om=MA(O,p);
hm=MA(H,p);
lm=MA(L,p);
Cm=MA(C,p);

HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );

res=HHV(Hm,4);
sup=LLV(Lm,4);
tsl=IIf(ValueWhen(IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0))!=0,IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0)),1)==1,sup,res);

Plot(tsl, _DEFAULT_NAME(), colorWhite, styleStaircase);
Buy = Cross(C,res) ;
Sell = Cross(sup,C) ;
_SECTION_END();


Candlecolor=IIf(Haclose>Haopen,colorGreen,colorRed);
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), candlecolor, styleCandle | styleNoLabel );
 
Respected seniors,i need help.pla plot buy sell signal on afl code.signal generate when candle close.


_SECTION_BEGIN("Heiken Ashi Smoothed");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorBlack ));
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;

p=Param("Period",6,2,30,1);
Om=MA(O,p);
hm=MA(H,p);
lm=MA(L,p);
Cm=MA(C,p);

HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );

res=HHV(Hm,4);
sup=LLV(Lm,4);
tsl=IIf(ValueWhen(IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0))!=0,IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0)),1)==1,sup,res);

Plot(tsl, _DEFAULT_NAME(), colorWhite, styleStaircase);
Buy = Cross(C,res) ;
Sell = Cross(sup,C) ;
_SECTION_END();

_SECTION_BEGIN("");
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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
 
Here's one with the Buy/Sell Plotted. Trades go @ Close.

Code:
_SECTION_BEGIN("Heiken Ashi Smoothed");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorBlack ));
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;

p=Param("Period",6,2,30,1);
Om=MA(O,p);
hm=MA(H,p);
lm=MA(L,p);
Cm=MA(C,p);

HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );

res=HHV(Hm,4);
sup=LLV(Lm,4);
tsl=IIf(ValueWhen(IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0))!=0,IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0)),1)==1,sup,res);

Plot(tsl, _DEFAULT_NAME(), colorWhite, styleStaircase);
Buy = Cross(C,res) ;
Sell = Cross(sup,C) ;
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorGreen, colorRed ) );
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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
 

manny.here

Well-Known Member
Hi guys ,

I just started looking into AFL in last 2 days . So if you find my question as silly , please point me in the correct direction.

I am trying to backtest a simple ema crossover strategy during a range of period . Added buy condition along with the day range . However when I am backtesting this, the last open position it is calculating till current date. How can I resolve this.

e.g. if I test during 2018 jan 1st and dec 31st and a buy activated on 31st Dec 2018 , Profit/loss is calculated from 31st Dec 2018 to current date.

start_dt = _DT( "2018-01-01" );
end_dt = _DT( "2018-12-31" );

dt = DateTime();
datewindow = dt >= start_dt AND dt <= end_dt;

Buy = Cross(EMA1 , EMA2 ) AND datewindow;
Sell = Cross(EMA2 , EMA1) AND datewindow;
 

jallanankit

Well-Known Member
Anyone able to code AFL for options..
Looking for something like this..

BUY Condition= conditionA
SELL Condition= conditionB
Short Condition = conditionC
Cover Condition = conditionD

When BNF futures triggers conditionA, it should signal a BUY in CE.
CE to be above 100 points of BNF level (rounded off to near 100)

When BNF futures triggers conditionB, it should signal a BUY in PE.
PE to be 100 points lower of BNF level (rounded off to near 100)

Any help would be appreciated
 

Similar threads