Stock Portfolio Organizer
The ultimate porfolio management solution.
Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
TWS Trade Plotter for Amibroker (AFL)
Rating:
5 / 5 (Votes 1)
Tags:
Plots auto-exported tws trades
By Yofa
Indicator / Formula
Copy & Paste Friendly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | _SECTION_BEGIN ( "IB Trades" ); //******************************************************************************************** // // Plotting TWS trade excutions // Coded by Yofa // Original experimental code from Herman // //******************************************************************************************** // // Goals: to present TWS real time trade execution data on any price pane. // // This code reads the auto exported TWS trade executions file and plots BOT AND SLD transactions on a price pane. // It is intended for Real-Time intraday trading. // Tws auto exports only the current trading day's data! // // To use this, you need to configure your TWS to auto export the trade executions list (TWSTrades.csv) each Minute: // Select Configure-Misc-Auto Export menu in TWS. // In Auto Export settings window: // Check "Activate auto export" // Set "Start time", "Stop Time", "Interval" according to your intraday trading // Set "Export directory" to "C:\JTS" // Set "Export file" to "TWSTrades.csv" // Select "Default columns" // Check "Write trade times using local time zone" // Select "Local sysbol" for "Symbol" // Select "," for "Field Delimeter" // // You can manually create export files and concatanate them for the last few days (TWSTradesHistory.csv). // //******************************************************************************************** // // Dependencies // // TWS (892.7) auto export settings (see above) // //******************************************************************************************** IBTradesTradeExists = False ; IBTradesPrice = Null ; IBTradesTradeColor = Null ; procedure IBTradesProcessFile(InputFileName) { IBTradesTradeExists = False ; InputFHandle = fopen (InputFileName, "r" ); if (InputFHandle) { FirstVisible = Status ( "firstvisiblebar" ); LastVisible = Min ( Status ( "lastvisiblebar" ), BarCount -1); BarDT = DateTime (); Index = FirstVisible; //skip header line fgets (InputFHandle); //outer loop to go down the file until the EOF or until the last visible bar while (! feof (InputFHandle) AND Index <= LastVisible) { InputLine = fgets (InputFHandle); if (InputLine != "" ) { Ticker = StrExtract (InputLine,0); if ( StrLeft ( Name (), 3) == StrLeft (Ticker, 3)) //may need to customize this (3 is needed for forex) { TradeDate = StrExtract (InputLine,5); TradeDate = StrMid (TradeDate, 4,2) + "/" + StrRight (TradeDate, 2) + "/" + StrLeft (TradeDate, 4); TradeTime = StrExtract (InputLine,4); TradeDT = StrToDateTime (TradeDate + " " + TradeTime); //Date AND time of the trade (DateTime() precision!) //inner loop to find the bar for the trade while (Index <= LastVisible AND TradeDT >= BarDT[Index]) { //check if next bar's datetime is later than the trade's DateTime if (Index == BarCount -1) NextIsLater = 1; else NextIsLater = TradeDT < BarDT[Index+1]; if (TradeDT >= BarDT[Index] AND NextIsLater) { IBTradesPrice[Index] = StrToNum ( StrExtract (InputLine,3)); Action = StrExtract (InputLine,1); if (Action == "SLD" ) IBTradesTradeColor[Index] = colorRose ; else if (Action == "BOT" ) IBTradesTradeColor[Index] = colorLime ; IBTradesTradeExists = True ; } Index++; } } } } fclose (InputFHandle); } } IBTradesProcessFile( "C:\\Jts\\TWSTrades.csv" ); if (IBTradesTradeExists) PlotShapes ( IIf ( NOT IsNull (IBTradesPrice), shapeSmallCircle , shapeNone ),IBTradesTradeColor, 0, IBTradesPrice, 0); IBTradesProcessFile( "C:\\Jts\\TWSTradesHistory.csv" ); if (IBTradesTradeExists) PlotShapes ( IIf ( NOT IsNull (IBTradesPrice), shapeSmallCircle , shapeNone ),IBTradesTradeColor, 0, IBTradesPrice, 0); _SECTION_END (); //"IB Trades" |
0 comments
Leave Comment
Please login here to leave a comment.
Back