Trading NR7 setup

Status
Not open for further replies.
Hi,

I have tried and coded an AFL for Cubt's 200 DMA trading system. I have mentioned the afl at the end of this post since I am unable to upload afl files directly as an attachment, get error invalide file. I hope Cubt can have a look and backtest it in Amibroker to verify if it is producing the correct results. I checked the trades with those of Tatasteel listed in the earlier post and they came correct.
I have also incorporated impact cost in my afl, because in practicality, trades are never going to get filled at the open and close price exactly.

I think the problem with this strategy is when the price retraces towards the 200 DMA but does not cross it in the opposite direction. This is when we get a series of losing trades and I hope Cubt can come out with some way to avoid such situations.

Thanks and Happy New Year to all.


//AFL Starts Here
//Copy and paste all text from here till end in text file and save as .afl
SetBarsRequired(sbrAll,0);
function rounddec(Number, decimal)
{
pwr = 10^decimal;
result = round(Number * pwr) / pwr;
return result;
}

ma1_period=Param("MA Period",200,2,1000,1);
ma1=MA(Close,ma1_period);
impact_cost = 0;
bar_start = ma1_period;

trigb=0;
trigs=0;
Buy=0;
Sell=0;
Short=0;
Cover=0;
netqty=0;
daysintrade=0;
SetPositionSize(1,4);

trigb=iif(Close>ma1,1,0);
trigs=iif(Close<ma1,1,0);

for ( i = bar_start; i < BarCount; i++ )
{
netqty=netqty[i-1];
daysintrade=daysintrade[i-1];

Buy=0;
Sell=0;
Short=0;
Cover=0;

//Check for New Trade
if(netqty==0)
{
if(trigb==1)
{
Buy=1;
BuyPrice=Open+impact_cost;
netqty=1;
daysintrade=0;

}
if(trigs==1)
{
Short=1;
ShortPrice=Open-impact_cost;
netqty=-1;
daysintrade=0;
}
}
else
{
daysintrade=daysintrade+1;
}

//Check for Exit Trade
if(daysintrade==1)
{
if(netqty==1)
{
Sell=1;
SellPrice=Close-impact_cost;
netqty=0;
daysintrade=0;
}
if(netqty==-1)
{
Cover=1;
CoverPrice=Close+impact_cost;
netqty=0;
daysintrade=0;
}
}

}

barcolor = colorBlack;
barcolor = IIf(netqty > 0, colorBlue, IIf(netqty < 0, colorRed, colorBlack));
up = IIf(Cross(netqty,0), 1, 0);
dn = IIf(Cross(0,netqty), 1, 0);

SetChartOptions(0,chartShowArrows|chartShowDates|chartWrapTitle);
Plot(C,"Daily Chart", barcolor, styleBar | styleThick);
PlotShapes(up* shapeUpArrow, colorGreen, 0,Low);
PlotShapes(dn* shapeDownArrow, colorRed,0,High);

Title = Name() + " {" + Date() + "} CUBT 200 DMA: " + Open + ", H: " + High + ", L: " + Low + ", C: " + Close
+ ", TrigB: " + trigb + ", TrigS: " + trigs + ", NetQty: " + netqty;
 
Status
Not open for further replies.

Similar threads