orders not firing to trading platform

VBS

New Member
#1
hi everyone, I'm using Zerodha kite for trading and Amibroker for charts and after knowing about the algo tradind I subscribed to AutoTrader by Stocksdevelepor.com. I got an AFL from online searching and back-tested it and got very decent results in 15min chat of nifty and decided to use it for my auto trading. Now when I run the Autotrader as guided it is still not placing the orders in the kite but when i tried with demo AFL by Autotrader it is working, I guess the issue is in the AFL and please it is my kind request to the members to help me resolving this situation. Here below I am posting the AFL code which I am trying to implement. And thank you in advance.



#include <algotrader-util.afl>

_SECTION_BEGIN("my 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