Simple Coding Help - No Promise.

hi,
I am a commodity trader. der are different expiry of different commo.
If i backtest using "all quots" it gives the result with the rollover contract. (i.e the gaps which forms on the last day of expiry and nxt day of the new contract).
Currently i am inputting the manually date range in AA window. But as the commodity has different expiry, it becomes a time consuming job to input different dats all the timefor different system.

My query is:
Can we input the expiry date in the parameter section, so that it finishes the trade on expiry dat and wait for the fresh call from the next day?
 
hi,
I am a commodity trader. der are different expiry of different commo.
If i backtest using "all quots" it gives the result with the rollover contract. (i.e the gaps which forms on the last day of expiry and nxt day of the new contract).
Currently i am inputting the manually date range in AA window. But as the commodity has different expiry, it becomes a time consuming job to input different dats all the timefor different system.

My query is:
Can we input the expiry date in the parameter section, so that it finishes the trade on expiry dat and wait for the fresh call from the next day?
mehtaka

Answer is most certainly yes!!!

Code:
expiryDate = ParamDate( "Commodity expiry Date", "2013-12-31" );
Next, you need condition in your Sell or Cover variable

Code:
OR (DateNum() >= expiryDate);
But you will still need to enter dates in parameter.

Better approach for you would be to figure out the exact conditions upon which the commodity contracts expire and then extract the formulas based on which you can calculate future expiry dates for any and each commodity.

For e.g. NSE expiry is on last Thursday of month and on this link, you will find AFL code that can determine last thursday of any month, any year.

Some commodities expire on last day of month. Some expire on 5th. There is also some confusion about trade expiry and delivery expiry. I don't trade commodities extensively so I have no idea on what goes on there.

Once you have proper formula to compute any expiry date for any commodity, it can be coded in AFL and you can include them in Buy/Sell Variables to handle them correctly.

You can even simulate the rollover by Selling expiring contract and buying newer ones.
 
Last edited:

cellclinic

Well-Known Member
SENIORS ... kindly look & reply into this post ...

if its possible can create this afl :-

Can try this setup for intraday play....

This strategy is for purely intraday.It has given me 600 points gain in last 6 days after brokerage.

STRATEGY
1) Time frame 3-min for EMA CROSSOVER and 5- min for PSAR (PARABOLIC STOP AND REVERSE)

2)In 3min tf, EMA3 and EMA15 cross over to be taken for buy and sell

3) if we get a buy signal from ema cross over, then look at psar for confirmation as follow

4)make time frame 5-min,select PSAR, add 20-ema.
if psar is below the cmp and cmp is above 20-ema, then it is a CONFIRMED BUY.(After step 3 then step 4)

5)Always buy 2 lots.Book 1 lot at +15 point , 2nd lot at +30 points.
If CONFIRMED SELL SIGN is generated, then reverse position.




need to add condition 4 using time frame expand for 20 ema & SAR, which only senior can help out

_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - " + SectorID( 1 ) + " - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " + WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", colorRose, styleCandle | styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("EMA CROSSOVER CHART");
LongPer = Param("Long Period", 3, 30, 100, 5);
ShortPer = Param("Short Period", 15, 30, 100, 5);
LongMA = EMA(C, LongPer);
ShortMA = EMA(C, ShortPer);
LastHigh = HHV(H, LongPer);
GraphXSpace = 10;
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorBrightGreen, styleLine);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorRed, styleLine);
Buy = Cross(LongMA, ShortMA);
Sell = Cross(ShortMA, LongMA);
PlotShapes(shapeUpArrow * Buy, colorBrightGreen, 0, L, - 10);
PlotShapes(shapeDownArrow * Sell, colorRed, 0, H, - 10);
_SECTION_END();
 
mehtaka

Answer is most certainly yes!!!

Code:
expiryDate = ParamDate( "Commodity expiry Date", "2013-12-31" );
Next, you need condition in your Sell or Cover variable

Code:
OR (DateNum() >= expiryDate);
But you will still need to enter dates in parameter.

Better approach for you would be to figure out the exact conditions upon which the commodity contracts expire and then extract the formulas based on which you can calculate future expiry dates for any and each commodity.

For e.g. NSE expiry is on last Thursday of month and on this link, you will find AFL code that can determine last thursday of any month, any year.

Some commodities expire on last day of month. Some expire on 5th. There is also some confusion about trade expiry and delivery expiry. I don't trade commodities extensively so I have no idea on what goes on there.

Once you have proper formula to compute any expiry date for any commodity, it can be coded in AFL and you can include them in Buy/Sell Variables to handle them correctly.

You can even simulate the rollover by Selling expiring contract and buying newer ones.
hi,
What i want is, the trade to exit on the expiry dat and strt a fresh trade on the nxt day. Is the code you have provided will do the same?
suppose:
Expiry date is :
1 ) 31st oct 2013
2) 30th nov 2013
3) 31st dec 2013

I am looking out is the trade to finish on 31st oct and than strat a fresh trade from 1st nov 2013.
So how to input these multiple expirys in the afl?
 
Dear seniors,
pls help me write below condition

buy = if 5 candle close above 200ema and after that cross its highr high
sell = if 5 candle close below 200ema and after that cross its lower low

Thanks
Abhishek
 
Dear seniors,
pls help me write below condition

buy = if 5 candle close above 200ema and after that cross its highr high
sell = if 5 candle close below 200ema and after that cross its lower low

Thanks
Abhishek
Code:
	ema200 = EMA(Close, 200);
	hhv6 = HHV(High, 6);
	llv6 = LLV(Low, 6);

	XBuy = Ref(Close, -5) < Ref(ema200, -5) AND
	Ref(Close, -4) > Ref(ema200, -4) AND
	Ref(Close, -3) > Ref(ema200, -3) AND
	Ref(Close, -2) > Ref(ema200, -2) AND
	Ref(Close, -1) > Ref(ema200, -1) AND
	    Close      >     ema200;

	XSell = Ref(Close, -5) > Ref(ema200, -5) AND
	Ref(Close, -4) < Ref(ema200, -4) AND
	Ref(Close, -3) < Ref(ema200, -3) AND
	Ref(Close, -2) < Ref(ema200, -2) AND
	Ref(Close, -1) < Ref(ema200, -1) AND
	    Close      <     ema200;

	BuyStop = ValueWhen(XBuy, hhv6);
	Buy = Close > BuyStop;
	SellStop = ValueWhen(XSell, llv6);
	Sell = Close < SellStop;
You will still need to add the signal filtering, plotting and all such code
 
For once, Congress did not lie

It said this

"Congress ka Haath, Aam Aadmi ke Saath"

long before the all the tube-lights across the country switched on!!
 
hi,
What i want is, the trade to exit on the expiry dat and strt a fresh trade on the nxt day. Is the code you have provided will do the same?
suppose:
Expiry date is :
1 ) 31st oct 2013
2) 30th nov 2013
3) 31st dec 2013

I am looking out is the trade to finish on 31st oct and than strat a fresh trade from 1st nov 2013.
So how to input these multiple expirys in the afl?
mastermind, help me out with this..
 

Similar threads