Dissecting the Nest Plus Auto Trading API

GuluGulu

Well-Known Member
#72
Hi Sandip,

Me too have subscribed to N+ API today for 295/- pm. Can you please give me an example how to start, take an example, the following NMA Swing System:

Code:
_SECTION_BEGIN("NICK MA Swing");
SetBarsRequired(200,0);

GraphXSpace = 5;
SetChartOptions(0,chartShowArrows|chartShowDates);
k =  Optimize("K",Param("K",2,0.25,5,0.25),0.25,5,0.25);
Per= Optimize("atr",Param("atr",20,3,20,1),3,20,1);
HACLOSE=(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose,  -1 ),  0.5 );
HaHigh = Max( H,  Max( HaClose,  HaOpen ) );
HaLow = Min( L,  Min( HaClose,  HaOpen ) );
PlotOHLC( Open, High, Low, Close, "" + Name(), colorBlack, styleCandle );
j=Haclose;

//=======================================================================================================================
//=========================Indicator==============================================================================================
f=ATR(15);

rfsctor = WMA(H-L, Per);

revers = k * rfsctor;

Trend = 1;  
NW[0] = 0;  


for(i = 1; i < BarCount; i++)
{
 if(Trend[i-1] == 1)                
 {
  if(j[i] < NW[i-1])                 
  {
   Trend[i] = -1;                   
   NW[i] = j[i] + Revers[i];        
  }
  else                              
  {
   Trend[i] = 1;
   if((j[i] - Revers[i]) > NW[i-1])
   {
    NW[i] = j[i] - Revers[i]; 
   }
   else
   {
    NW[i] = NW[i-1];
   }
  } 
 }
 if(Trend[i-1] == -1)               
 {
  if(j[i] > NW[i-1])                
  {
   Trend[i] = 1;                    
   NW[i] = j[i] - Revers[i];        
  }
  else                              
  {
   Trend[i] = -1;
   if((j[i] + Revers[i]) < NW[i-1]) 
   {
    NW[i] = j[i] + Revers[i]; 
   }
   else
   {
    NW[i] = NW[i-1];
   }
  }
 }
}

//===============system================

Plot(NW, "", IIf(Trend == 1, 27, 4), 4);
Buy=Cover=Cross(j,nw);
Sell=Short=Cross(nw,j);
SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );
NMAB= NW<HACLOSE;
NMAS= NW>HACLOSE;

NMA_status= WriteIf(NMAB, "BUY MODE", WriteIf(NMAS, "SELL MODE", "NEUTRAL"));
NMAS_Col=IIf(NMAB, colorGreen, IIf(NMAS, colorRed, colorLightGrey));
Filter=1;
AddColumn( NW[BarCount-1], "SAR", 1.2 );
AddColumn( HACLOSE, "HA Close", 1.2 );
AddColumn( C, "Close", 1.2 );
AddTextColumn(NMA_status, "MODE", 1, colorBlack, NMAS_Col);
AddColumn( DateTime(), "Date / Time", formatDateTime ); 
_SECTION_END();
//=================TITLE================================================================================================
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator ) 
(
Title = EncodeColor(colorBlue)+ "Symbol - " + " - " +  Name() + " - " + EncodeColor(colorBlue)+ Interval(2) + EncodeColor(colorBlue) +
 "  -  " + Date() +" - "+"\n" +EncodeColor(colorBlue) +"Open-"+O+"  "+"High-"+H+"  "+"Low-"+L+"  "+
"Close-"+C+"  "+ "Vol= "+ WriteVal(V)+"\n"+ 
EncodeColor(colorGreen)+
WriteIf (Buy , "Reverse and Go LONG at Signal Bar Close at "+C+"  ","")+EncodeColor(colorRed)+
WriteIf (Sell , "Reverse and Go SHORT at Signal Bar Close at "+C+"  ","")+"\n"+EncodeColor(colorLime)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy  , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+"\n"+EncodeColor(colorGreen)+
WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+EncodeColor(colorRed)+
WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+EncodeColor(colorOrange)+
WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
_SECTION_END();




//=================MagnifiedMarketPrice================================================================================================
_SECTION_BEGIN("Magfied Market Price");

//Magfied Market Price
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True ); 
GfxSetBkMode( colorWhite );  
GfxSetTextColor( ParamColor("Color",colorGreen) ); 
Hor=Param("Horizontal Position",800,1,1200,1);
Ver=Param("Vertical Position",12,1,830,1); 
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True ); 
GfxSetBkMode( colorBlack );  
GfxSetTextColor(ParamColor("Color",colorYellow) ); 
GfxTextOut(""+DD+"  ("+xx+"%)", Hor , Ver+45 );
 


_SECTION_END();
 
#73
Hi,
Copy this below plugin at the end of your strategy to place orders in only nifty future.
Test your strategy live and back test,bar replay at least for 2-3 days before trading with real money, try with 1min time frame.

Best of luck.




ClientID = ParamStr("ClientId","000000");
Symbol= ParamStr("Symbol","NIFTY13AUGFUT");
Price=NumToStr(C,8.3,True);
Quantity=Param("Quantity",1,1,100,1);
OE = ParamList("Order Execution","Immediate,On Candle Completion",1);
AT = ParamToggle("AutoTrade","No,Yes");

if(OE=="On Candle Completion")
{
Buy=Ref(Buy,-1);
Short=Ref(Short,-1);
Sell=Ref(Sell,-1);
Cover=Ref(Cover,-1);
}

AplliedQuantity=IIf(LastValue(Buy) AND LastValue(Cover) OR LastValue(Short) AND LastValue(Sell),Quantity*2,Quantity);
RefNumber = Nz(StaticVarGet("RefNumber"));
Checkdt=Nz(StaticVarGet("lastdt"));
dt = LastValue( DateTime() );
Cond=LastValue(Buy) OR LastValue(Short) OR LastValue(Sell) OR LastValue(Cover);

if(AT)
{
plus = CreateStaticObject("Nest.PlusApi");
if(plus)
{
plus.SetObjectName(ClientID);
if(Cond AND Checkdt != dt )
{
if(LastValue(Buy) OR LastValue(Cover)){plus.PlaceOrder("BUY",RefNumber,"NFO",Symbol,"DAY","LIMIT",AplliedQuantity,Price,0,1,"NRML",ClientID);}
if(LastValue(Short) OR LastValue(Sell)){plus.PlaceOrder("SELL",RefNumber,"NFO",Symbol,"DAY","LIMIT",AplliedQuantity,Price,0,1,"NRML",ClientID);}
StaticVarSet("RefNumber",RefNumber+1);
StaticVarSet("lastdt",dt );
}
}
}
 
#74
Paste this massage board afl after your strategy before pasting auto trading plugin and check weather your strategy will work for auto trading or not. after pasting this afl if it gives error in amibroker it means your strategy wont work for auto trading,
even you can check how much profit/loss you will make with your strategy by back testing (bar replay) in amibroker


_SECTION_BEGIN("MASSAGE BOARD");

for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);

messageboard =1;// ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorGreen ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 10;
x = 0;
x2 = 130;

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 45, x2, y , 7, 7 ) ;
GfxTextOut( ( "PROFIT TREND"),2,y-47);
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 1, y-33);
GfxTextOut( ("Cur P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 1, y-19);;
}
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorYellow, styleLine|styleLine, Null, Null, Offset);

_SECTION_END();
 
#75
Dear niftyjack and gulu gulu

extremely sorry that i didn't check your replies. saw them just now.

i said that in order to trade semi auto you need to have the Trading Plugin tool @Rs. 295/-. without it you can run your afl but it will not trade.


the auto part looks like this and was published in TJ by somebody. if the rest of the afl is ok it should do semi auto.

//ats param and ats operation
_SECTION_BEGIN("ATS");
ClientID = ParamStr("ENTER CLIENT ID","000000");
Symbol= ParamStr("Symbol to trade","NIFTY13SEPFUT");
Price=NumToStr(C,1.2,True);
Quantity=Param("Quantity",1,1,100,1);
OE = ParamList("Order Execution","Immediate,On Candle Completion",1);
AT = ParamToggle("Start Trading ? ","No,Yes");
ATS_EX= ParamList( "Exchange traded on?", "NFO,NSE" );
AT_PT = ParamList( "Omnesys Product Type?", "NRML,MIS,CNC" );
AT_BOT = ParamList( "Order Type?", "MARKET,LIMIT" );


if(OE=="On Candle Completion")
{
Buy=Ref(Buy,-1);
Short=Ref(Short,-1);
Sell=Ref(Sell,-1);
Cover=Ref(Cover,-1);
}

AplliedQuantity=IIf(LastValue(Buy) AND LastValue(Cover) OR LastValue(Short) AND LastValue(Sell),Quantity*1,Quantity);

RefNumber = Nz(StaticVarGet("RefNumber"));
Checkdt=Nz(StaticVarGet("lastdt"));
dt = LastValue( DateTime() );
Cond=LastValue(Buy) OR LastValue(Short) OR LastValue(Sell) OR LastValue(Cover);

if(AT)
{
plus = CreateStaticObject("Nest.PlusApi");
if(plus)
{
plus.SetObjectName(ClientID);
if(Cond AND Checkdt != dt )
{
if(LastValue(Buy)OR LastValue(Cover) )
{plus.PlaceOrder("BUY",RefNumber,ATS_EX,Symbol,"DAY","LIMIT",AplliedQuantity,Price,0,1,AT_PT,ClientID);}

if(LastValue(Sell) OR LastValue(Short))
{plus.PlaceOrder("SELL",RefNumber,ATS_EX,Symbol,"DAY","LIMIT",AplliedQuantity,Price,0,1,AT_PT,ClientID);}
StaticVarSet("RefNumber",RefNumber+1);
StaticVarSet("lastdt",dt );
}
}
}

one caveat however: I am having errors in price mismatch. hopefully it would be over by this week.
 
#76
The mismatch I was having in my afl seems to have gone after the Price criteria was modified and gfdl code was used. But here are the new bugs. Can you please help?

1) some signals show in the chart but does not go to API and vice versa
2) AMI back test showing trades not in chart and vice versa
3) will someone tell me the full explanation and syntax of StrToNum function?

Expert help is sought again.
 
#77
Glad to learn that you have a grip on the problem.

If I may say so, the folks that support AFL related requests here in TJ are some of the most selfless, active and finest coders you will find anywhere. If you can use their services, and offer more than electronic thanks, it is certainly a great idea. They may, or may not, have integrated AFLs on the GDFL offering earlier, but trust me, a little elbow space and they will be on top.
The only point of worry, and this applies to everybody, is that there is no simulation server; you cannot do dry runs. [Idea :!]
You have to test on a live market; and it is like repairing an car engine while it is running or doing a heart surgery. At the risk of digressing, Omnesys does offer a staging server but I do not know details.
you should look at tradelink.org, it is a free opensource algotrading/simulation platform
 

mastermind007

Well-Known Member
#78
Re: 7. Interval

Before taking a long break from this, it needs to be outlined why GetPlusVersion will not work from an Ami afl, and what Omneysy can do about it. In a larger context, this affects the rest of the Plus auto trading API that has not been covered.

As a background, when I last talked to Omnesys during Plus version 1.3, one question that was asked of them was why the signature of GetOrderStatus looked like this:
GetOrderStatus(..., long* FillPrice)
How was the fill price a whole number? They replied that a) you need to divide fill price by 100, and b) that GetOrderStatus did not work. That is strange, and what happens in the case of currencies? They said that they would fix it in the next version, and they have; it is now a double data type.

It struck me that we would get into version dependency, and suggested that they have a trivial function like GetVersion() that would simply return the version number. User could use it to check that their setup was correct, and developers could use it for version variations that were bound to happen. Plus version 1.4 included a version fetch; for reasons explained earlier, you can only use it currently in NOW 1.8.

The expected way to use it in Ami would be: plusObject.GetPlusVersion(versionNo) where versionNo would be filled in by Nest Plus. But that would not work as the parameter is not passed by reference.
does it have HRESULT in front and is price prefixed with word "out"?

If yes, it is a return parameter with glorious microsoft HRESULT taking importance over the return value.

Call from clients will happen


returnedPrice = someValidComObject.GetOrderStatus(...);
 

yusi

Well-Known Member
#79
Re: 7. Interval

does it have HRESULT in front and is price prefixed with word "out"?

If yes, it is a return parameter with glorious microsoft HRESULT taking importance over the return value.

Call from clients will happen


returnedPrice = someValidComObject.GetOrderStatus(...);
Don't be daft.

- this is out of context.
- GetOrderStatus has other return values besides price, quantity for example.
- possible confusion between [retval] and [out].

If only Omnesys had followed glorious Microsoft here, as they did for the RTD interface...
 

yusi

Well-Known Member
#80
Re: 7. Interval

Yusi

i configured that with c#
GetOrderStatus(Refno, out tType, out tqty, out tPrice);

MessageBox.Show(tType);
MessageBox.Show(tqty);

i got message ("Order Not Found") and ("0")

Same Referance number i passed. and also i checked with Referance number in Order book but it has empty value.

May i miss something?

Can you figured out?

Thanks
suman
Suman, the call is good. And the reference number is not reflected in any column in the Orders Book -- so I do not know what you mean by "checked with Referance number in Order book but it has empty value".

Check in the log if the order that you placed was silently rejected. For example, see the note on case sensitivity of parameters.
 

Similar threads