[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: NinjaTrader automation AFL code



PureBytes Links

Trading Reference Links

Some additional info that might be useful:

This code is obviously only for generating buy orders with associated 
OCA stop loss and target profit orders.  It is currently set up only 
for stocks (STK) and only for limit buy orders (LMT) and only for 
stop limit orders (STP LMT) and with a time in force of a day (DAY).

If any changes to the above parameters are required , the user would 
have to modify "mystring" in the AFL code.  

Also, if a user is pasting this code into the AFL editor, there is a 
chance that the editor might change the case of some of the words 
in "mystring".  This is because these words (e.g. Buy, Day) are 
reserved words in the AFL language. To make sure that the AFL editor 
does not change the case, the user must uncheck the following 
setting: Tools > Preferences > Editor tab > Auto change case.

Also, there is a line in the VBscript which says "MsgBox "Copying to 
NT directory."".  This line should not be removed since it gives NT a 
chance to process the previous passentry.txt file, if it exists.  A 
better solution would be to first check if the passentry.txt file 
exists in the NT directory.  Maybe I'll add that later and upload a 
newer version of the code.

Finally, the user would obviously have to define filepath, numshares, 
stopprice, stopoffset [which is just LastValue(BuyPrice)-stopprice], 
and targetoffset.

HB


--- In amibroker@xxxxxxxxxxxxxxx, "hmab1" <hossamb@xxxx> wrote:
> Hello all,
> 
> NinjaTrader (www.ninjatrader.com) is a rapid order entry system 
that 
> can control Interactive Broker's TWS.  It is similar to 
BracketTrader 
> or any other app you might now.  It has a mode called PassThrough 
> automation (http://www.ninjatrader.com/automatedtrading.htm) where, 
> given signals from a tech analysis application like Amibroker, it 
can 
> generate the order for you in TWS.
> 
> Here's some AFL code that will generate the necessary passentry.txt 
> file and copies it to the ninjatrader directory.  This code 
requires 
> the ABtool plugin found in the files section (thanks Uenal for a 
> great plugin !).
> 
> ///////////// NinjaTrader integration code - start //////////
> 
> fileischanged = 0;
> 
> if (LastValue(Buy) == 1) {
>   mystring = "\"BUY\"" + "," + "\"" + WriteVal(numshares, 1.2) 
+ "\"" 
> + "," + "" + "\"" + Name() + "\""  + "," + "\"STK\"" + "," + "\"\"" 
> + "," + "\"SMART\"" + ","  + "\"LMT\"" + "," + "\"" + WriteVal
> (LastValue(BuyPrice),1.2) + "\"" + "," + "\"" + WriteVal
> (stopprice,1.2) + "\"" + "," + "\"" + WriteVal(targetoffset,1.2) 
> + "\"" + "," + "\"" + WriteVal(stopoffset,1.2) + "\"" + "," 
+ "\"0.01
> \"" + ","  + "\"STP LMT\"" + "," +  "\"0\"" + ","  + "\"DAY\"" 
> + ",\n";
> 
>   filepath="C:\\whateverpathyouwant\\passentry.txt";
>   filehandle=xxFileOpen(filepath, "w");
>   temp=xxFileWriteStr(mystring, filehandle);
>   temp=xxFileClose(filehandle);
>   temp=xxMsgBox(mystring, "Message", 0);
>   fileischanged=1;
> };
> 
> EnableScript("vbscript");
> 
> <%
> filechanged=AFL("fileischanged")
> 
> if filechanged then
>   Set ofs = CreateObject("scripting.filesystemobject")
>   MsgBox "Copying to NT directory."
>   
> 
ofs.CopyFile "C:\whateverpathyouwant\passentry.txt", "C:\ninjatrader\"
>   set ofs = nothing
> End if
> %>
> 
> ///////////// NinjaTrader integration code - end //////////
> 
> 
> Enjoy,
> HB


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get A Free Psychic Reading! Your Online Answer To Life's Important Questions.
http://us.click.yahoo.com/Lj3uPC/Me7FAA/ySSFAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/