AFL not firing orders in automated mode

VBS

New Member
#1
Hi everyone, I'm using zerodha kite as my trading platform and amibroker as charting platform and AutoTrader by stocksdeveloper.com
I have an AFL for long & short trades which gave a decent returns when back-tested in nifty 15min chat. Now when I tried to automate my trade with it the orders are not getting placed into my trading platform after i followed every steps required for it to do it so. I need some help from experts like you guys to resolve this situation. Here in the below I am posting the AFL. THANK YOU in advance.


#include <algotrader-util.afl>


_SECTION_BEGIN("Intraday Strategy");


SetBarsRequired(sbrAll, sbrAll);
SetPositionSize(1, spsShares);

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 ) ) ));
SetBarFillColor(IIf(C>O,colorDarkOliveGreen,IIf(C<=O,colorBrown,colorLightGrey)));
Plot(C,"\nPrice",IIf(C>O,colorBrightGreen,IIf(C<=O,colorRed,colorLightGrey)),64|styleNoTitle,0,0,0,0);

DT = DateTime();
DN = DateNum();
TN = TimeNum();

function Asign(x)
{
y = Null;
for(i = 0; i < BarCount; i++)
{
y = x;
}

return y;
}

Slcalc = Param("Stop Loss %", 1,0, 100, 0.01)/100;
SlType = ParamToggle("StopLoss Type", "Initial|Trailing", 0);

DayStart = DN != Ref(DN, -1);
Dayscalc = Ref(DayStart, -9);
DaysMeas = Flip(DayStart, Dayscalc);
DayEnd = Ref(DayStart, 1);

BY = Asign(False);
SL = Asign(False);
SH = Asign(False);
CV = Asign(False);

HGHcalc = HHV(High, 5);
LVLcalc = LLV(Low, 5);

LVLScalc = Null;
LVLTScalc = Null;

LVLTSArray = Null;
HVLTSArray = Null;

BYPrsV = Null;
SLPrsV = Null;
SHPrsV = Null;
CVPrsV = Null;

LSLV = Null;
SSLV = Null;
LSL = Null;
SSL = Null;

CCntr = 1;

for(i = 1; i < BarCount; i++)
{
if(CCntr == 1 && DayStart == False)
{
LVLScalc = HGHcalc[i-1];
LVLTScalc = LVLcalc[i-1];
}

LVLTSArray = LVLScalc;
HVLTSArray = LVLTScalc;

CCntr--;
if(CCntr <= 0 || DayStart == True)
{
CCntr = 1;
}
}

Buy = High > LVLTSArray;
Short = Low < HVLTSArray;

Sell = Low < HVLTSArray;
Cover = High > LVLTSArray;


Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);

BuyPrice = ValueWhen(Buy, IIf(Open > LVLTSArray, Open, LVLTSArray));
ShortPrice = ValueWhen(Short, IIf(Open < HVLTSArray, Open, HVLTSArray));

SellPrice = IIf(Sell && Open < HVLTSArray, Open, HVLTSArray);
CoverPrice = IIf(Cover && Open > LVLTSArray, Open, LVLTSArray);

LSL = BuyPrice - (BuyPrice * Slcalc);
SSL = ShortPrice + (ShortPrice * Slcalc);

if(SlType == True)
{
HHVBy = HighestSince(Buy, High);
LLVSh = LowestSince(Short, Low);
LSL = IIf(Buy, BuyPrice - (BuyPrice * Slcalc), HHVBy - (HHVBy * Slcalc));
SSL = IIf(Short, ShortPrice + (ShortPrice * Slcalc), LLVSh + (LLVSh * Slcalc));
}

Sell = Sell || Low <= LSL;
Cover = Cover || High >= SSL;


Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);

SellPrice = IIf(Sell && Low <= LSL && Open < LSL, Open, IIf(Sell && Low <= LSL, LSL, SellPrice));
CoverPrice = IIf(Cover && High >= SSL && Open > SSL, Open, IIf(Cover && High >= SSL, SSL, CoverPrice));

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorBrightGreen, 0, Low, -15, 0);
PlotShapes(IIf(Sell, shapeStar, shapeNone), colorRed, 0, High, -15, 0);

PlotShapes(IIf(Short, shapeDownArrow, shapeNone), colorOrange, 0, High, -35, 0);
PlotShapes(IIf(Cover, shapeStar, shapeNone), colorTurquoise, 0, Low, -35, 0);

LongTrue = Flip(Buy, Sell) || Sell;
ShortTrue = Flip(Short, Cover) || Cover;

Plot(LVLTSArray, "LVLTSArray", colorGrey50, styleStaircase|styleDashed);
Plot(HVLTSArray, "HVLTSArray", colorGrey50, styleStaircase|styleDashed);

Plot(IIf(LongTrue, BuyPrice, Null), "BuyPrice", colorYellow, styleDashed|styleStaircase, Null, Null, 0, 1, 1);
Plot(IIf(LongTrue, LSL, Null), "Long Stoploss", colorCustom12, styleDashed|styleStaircase, Null, Null, 0, 1, 1);

Plot(IIf(ShortTrue, ShortPrice, Null), "ShortPrice", colorYellow, styleDashed|styleStaircase, Null, Null, 0, 1, 1);
Plot(IIf(ShortTrue, SSL, Null), "Short Stoploss", colorCustom12, styleDashed|styleStaircase, Null, Null, 0, 1, 1);

if ( LastValue(Buy) == True )
{
tradeType = "BUY";
target = buyPrice * PROFIT_PCT / 100;
stoploss = buyPrice * STOPLOSS_PCT / 100;

placeBracketOrder(AT_EXCHANGE, AT_SYMBOL, tradeType, AT_QUANTITY, buyPrice, target, stoploss, 0, 1);
}

if ( LastValue(Sell) == True )
{
tradeType = "SELL";
target = sellPrice * PROFIT_PCT / 100;
stoploss = sellPrice * STOPLOSS_PCT / 100;

placeBracketOrder(AT_EXCHANGE, AT_SYMBOL, tradeType, AT_QUANTITY, sellPrice, target, stoploss, 0, 1);
}




_SECTION_END();
 

Similar threads