Simple Coding Help - No Promise.

Hello frnds,
Can anyone guide me how to backtest the futures market?
As the futures market have certain expiry and its not practically possible to keep inputting "From and to dates" in backtest setting, can anyone guide how to incorporate this "from and to dates in afl itself and we can add as many dates as possible in it, so that the contract ends on the particular dats and fresh entry can be taken on the from dates.

plz guide me
Hello mehtaka!!!

Glad to see you here on traderji. I've seen many posts of yours on ***********.

If you dig around internet, you will find an AFL function that detects Last Thursday of month but using this function has its limitations. This is your first starting point. However, the problem is that if you use this in AFL and plot the AFL on a Cash Stock, the AFL will still assume that your stock is going to rollover on Last thursday.

The better (simplest) approach I have found is to create a text file (CSV file) in which I place name of amibroker symbol and full contract expiry date. With this approach, I can have symbols such as NIFTY16OCTFUT and NIFTY_F1 and NIFTY_F2 and NIFTYBEES all in same database. With the date coming from flat file (read and absorbed by symbol), rolling the contract becomes a very trivial task.
 
Hello mehtaka!!!

Glad to see you here on traderji. I've seen many posts of yours on ***********.

If you dig around internet, you will find an AFL function that detects Last Thursday of month but using this function has its limitations. This is your first starting point. However, the problem is that if you use this in AFL and plot the AFL on a Cash Stock, the AFL will still assume that your stock is going to rollover on Last thursday.

The better (simplest) approach I have found is to create a text file (CSV file) in which I place name of amibroker symbol and full contract expiry date. With this approach, I can have symbols such as NIFTY16OCTFUT and NIFTY_F1 and NIFTY_F2 and NIFTYBEES all in same database. With the date coming from flat file (read and absorbed by symbol), rolling the contract becomes a very trivial task.
Hello mastermind,
thanks for your reply, i have seen the afl you are referring. I would like to enter the dates rather than the day , basically i am into commodity mkts, where the expiry dates are different.
Any other way out , than the CSV file, i am bad with excel.
 
Apologies Mastermind. I have tried to modify using your provided AFL to have last 3 candle avg along with current candle buy/sell volume.

I am not very good at 2nd point. Please find the code that i have tried to modified like imgur posted earlier. Awaiting for your help.

PHP:
_SECTION_BEGIN("Unnamed 2");
SetBarsRequired(sbrAll,sbrAll);
 
// BUYING VOLUME AND SELLING VOLUME //
 //*VALUE BELOW ZERO IS BEARISH, ABOVE ZERO IS BULLISH**//
 
MYINDI=(((C-Ref(C,-1))/(HHV(H,2)-LLV(L,2)))*(V+Ref(V,-1))/2);
 
Plot(EMA(MYINDI,10),"A.N.KUMAR INDICATOR",colorBlack,style=styleDots,Min(0,0),Max(0,0),xshift=0,zorder=0,width=1);
 
 
BV = IIf( (H==L), 0, V*(C-L)/(H-L) );
SV = IIf( (H==L), 0, V*(H-C)/(H-L) );

BV1 = IIf( (H==L), 0, Ref(MA(V*(C-L)/(H-L),3),-1) );
SV1= IIf( (H==L), 0, Ref(MA(V*(H-C)/(H-L),3),-1) );
 
PlotOHLC(SV,SV,0,0,"SellVolume",colorRed,styleCandle|styleNoTitle|styleNoLabel );
PlotOHLC(SV,BV+SV,SV,BV+SV,"BuyVolume",colorBrightGreen ,styleCandle|styleNoTitle|styleNoLabel );
 
Va = MA(V,30);
 
PlotOHLC( Va, Va, 0, 0, "", ColorBlend( colorWhite , GetChartBkColor(), 0.4 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
Plot(Va,"Average Volume",colorRose,styleNoLine|styleNoLabel );
 
VI = V/Va;
 
Title = Date() + "SellVolume:"+WriteVal(SV/100,5.0)+"   "+"BuyVolume:"+WriteVal(BV/100,5.0 )+  "LAST3SellVolume:"+WriteVal(SV1/100,5.0)+"   "+"LAST3BuyVolume:"+WriteVal(BV1/100,5.0 )+"   "+"VolumeIndex:"+WriteVal(VI,1.2)+"   "+
"BuyVolume:"+WriteVal(100*BV/(BV+SV),2.0)+"%"+"   "+"SellVolume:"+WriteVal(100*SV/(BV+SV),2.0)+"%"+ "   "+
"LAST3BuyVolume:"+WriteVal(100*BV1/(BV1+SV1),2.0)+"%"+"   "+"LAST3SellVolume:"+WriteVal(100*SV1/(BV1+SV1),2.0)+"%";
_SECTION_END();
Mastermind Bro,

Can you please help me to convert this afl work correctly to show last 3 avg buy/sell numbers correctly when you have free time.

Thanks in advance.:thumb::thumb:
 
I need AFL to Scan / Explore Stocks which were below 200 SMA but have closed today above 200 SMA, 50 SMA is above 200 SMA & 20 SMA is above 50 SMA with 14 days RSI is above 50.

Kindly help

Thanks & Regards
 
Hello mastermind,
thanks for your reply, i have seen the afl you are referring. I would like to enter the dates rather than the day , basically i am into commodity mkts, where the expiry dates are different.
Any other way out , than the CSV file, i am bad with excel.
I never recommeneded entering Day instead of Date.
In CSV file, you have full liberty to enter the contract ending date in any format as long as date format that can be parsed by Amibroker.
In fact, if you are willing to write the parser code yourself, there is no limitation on what you can place in contract end date.

Another idea is that you could place the contract ending date in any of the symbol information field but uploading that will also force you to deal with CSV.
OR you could use symbol-wise NoteGet/NoteSet function.
 

trash

Well-Known Member
I would like to enter the dates rather than the day , basically i am into commodity mkts, where the expiry dates are different.
Any other way out , than the CSV file, i am bad with excel.
Go to Symbol Information window, then scroll down to the bottom and enter Delisting date.

Then code wise

Code:
dt = DateTime();
expiryday = GetFnData("DelistingDate");
IsExpired = dt >= expiryday;
 
I need AFL to Scan / Explore Stocks which were below 200 SMA but have closed today above 200 SMA, 50 SMA is above 200 SMA & 20 SMA is above 50 SMA with 14 days RSI is above 50.

Kindly help

Thanks & Regards
 
I never recommeneded entering Day instead of Date.
In CSV file, you have full liberty to enter the contract ending date in any format as long as date format that can be parsed by Amibroker.
In fact, if you are willing to write the parser code yourself, there is no limitation on what you can place in contract end date.

Another idea is that you could place the contract ending date in any of the symbol information field but uploading that will also force you to deal with CSV.
OR you could use symbol-wise NoteGet/NoteSet function.
I am quite week with excel/ csv file. if possible, can you share such file ?
I would be greatful to u.
 

Similar threads