alv123 Posted November 24, 2021 Report Share Posted November 24, 2021 Hi guys, I can no longer cope with the lack of good risk management tools on TWS and i'm hoping Medved trader will save the day! This is how I trade: 1) Decide what % of my account i'm willing to risk on the trade 2) Decide price of 1st scale in 3) Decide price of 2nd scale in 4) Decide price of my Stop 5) Calculate the correct position size for the trade and place it 6) Scale out half of my total position 7) Update my stop to reflect the new total position size On TWS this is painfully slow / manual / and takes a lot of concentration. All I really need is a slightly more sophisticated version of the long position tool on tradingview. If that tool could accommodate scaling in, and if you could change % account risk without having to open up the menu, it would be perfect. It even auto populates the order form for you. Do you think it would be possible for me to automate these steps using your chart trader, or perhaps with the new hot keys you are working on? I believe you do have a position size tool on the chart, but it does not accommodate scaling in. Thank you for all of your efforts to make interactive brokers actually usable! Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted November 25, 2021 Report Share Posted November 25, 2021 If you can program a bit, using MT's API would allow you to do all this stuff in your own program that communicates with MT. You may also look at MT's hotkeys system (probably also using the "global variables" in the hotkeys for customized parameters). Quote Link to comment Share on other sites More sharing options...
alv123 Posted November 25, 2021 Author Report Share Posted November 25, 2021 Thanks for you reply! My programming experience goes as far as making a simple indicator using pine script. This is the only API documentation I could find:https://www.medvedtrader.com/www/frontend/blog/HTTP-API Is there any other documentation I can read? Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted November 25, 2021 Report Share Posted November 25, 2021 Go to the Settings / Application / API - and click on the Documentation link there next to WS API. Or just go here: https://docs.google.com/document/d/15IvYQEYzSeftTSEdVhsptAguM0fGm9mTJFSDDAK7zWE/edit#heading=h.vjt2wnr366ew It is a simple Websocket/JSON API and we can provide enough C# code in the API Tester to get you started. Using this API you can fully automate anything at all since it allows you to subscribe to/get market data, log into your trading account, get all the info from your trading account, place/monitor trades etc. All streaming. Quote Link to comment Share on other sites More sharing options...
Donald Q. Posted November 25, 2021 Report Share Posted November 25, 2021 1 hour ago, Mike Medved said: API Tester What and where is this? 😃 Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted November 25, 2021 Report Share Posted November 25, 2021 I will add this to the documentation. https://medvedtrader.com/gf?File=APITester.zip Quote Link to comment Share on other sites More sharing options...
alv123 Posted November 25, 2021 Author Report Share Posted November 25, 2021 Brilliant! Thanks Mike. Reading through it now. Quote Link to comment Share on other sites More sharing options...
alv123 Posted November 26, 2021 Author Report Share Posted November 26, 2021 (edited) Sorry to be a pain. I've read through the API documentation and I feel like I would be able to make something useful by combining some of the code examples together. However, despite lots of googling I am not sure what I am supposed to do with the Test api files you sent above. I believe i am on the right track by downloading 'visual studio community'. I then opened up the API tester.snl file, which I believe is the project file. But from that point I am lost on the next steps. I assume you have lots of better things to do than walking me through this. If you think i am way out of my depth then please say so lol. I think if I can just get to the stage where I can type out commands and see the responses, I will be able to get the hang of it, but this initial setup part is tripping me up. Edited November 26, 2021 by alv123 "visual basic" changed to "visual studio" Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted November 26, 2021 Report Share Posted November 26, 2021 Hmm. Well I would not recommend jumping straight into API Tester from no knowledge of C# at all. C# is not that hard, but it is a fairly advanced programming language. What do you know how to program? All that API needs is access to Websockets and JSON parsing... Quote Link to comment Share on other sites More sharing options...
Donald Q. Posted November 27, 2021 Report Share Posted November 27, 2021 (edited) Hmm... Added using MT.Util; to ByteBufferQueue.cs and WSTester.cs and we are in business. Edited November 27, 2021 by Donald Q. Quote Link to comment Share on other sites More sharing options...
alv123 Posted November 27, 2021 Author Report Share Posted November 27, 2021 My programming experience is making simple indicators on tradingview and a few apple script programs for keyboard shortcuts. I think I have now successfully loaded the files into visual studio. I believe that my next step is editing some of the code to include the 127.0.0.1 websocket described in the API document. Where would I enter this 127.0.01 number? I think I also need to enter the websocket port number from the medved application into the code. Where would I enter that number? If anyone could point me in the right direction, I would greatly appreciate it. Quote Link to comment Share on other sites More sharing options...
Donald Q. Posted November 27, 2021 Report Share Posted November 27, 2021 Hey @alv123, The code provided by the MT Team is non-compiled C# which needs compiled into a Windows executable through an interpreter like Visual Studio (you have this already). Next step would be to add using MT.Util; at the top of ByteBufferQueue.cs and WSTester.cs (inadvertently missing as far as I can tell). Next, you press the "Play" button at the top which will compile and launch the WSTester application which can be used to send API commands to MT and observe the output. If you receive errors during compilation, we would need to look at those and would typically be a missing class that can be downloaded from NuGet (i.e., WebSocket4Net), but by default all required ones should be there. Beyond the above, you would then want to look at adding business logic to the WSTester for your needs or using it as a baseline and developing your own application. For example, I created a sample function that outputs a message based on the balanceUpdate and alertTriggerUpdate messages. private void BusinessLogic(String data) { var json = JsonConvert.DeserializeObject<dynamic>(data); if (json.cmd.ToString() == "balancesUpdate") { if (json.result["account_value/change"] <= 1000.00) { UpdateLog($"Oh no! Still poor, keep trading... {json.result["account_value/change"]}"); } else { UpdateLog($"Wowzers! Done for the day... {json.result["account_value/change"]}"); } } if (json.cmd.ToString() == "alertTriggerUpdate") { if (json.result["alertDesc"] == "Volume") { UpdateLog($"Wish me luck, getting long {json.result["sym"]}"); String order = OrderBuilder(json.result["sym"]) SendSocket(order); } else { UpdateLog($"Hmm, waiting for next alert to execute a trade."); } } } Quote Link to comment Share on other sites More sharing options...
Jerry Medved Posted November 27, 2021 Report Share Posted November 27, 2021 I updated the APITester.zip to fix the MT.Util reference. sorry about that. we really should do a proper sample app. Just have not had time. sorry 1 Quote Link to comment Share on other sites More sharing options...
alv123 Posted November 27, 2021 Author Report Share Posted November 27, 2021 SUCCESSFUL BUILD Thank you so much Donald! I would have been sat here for the next 6 months trying to figure that out. I ran into a couple of other errors a long the way, which I will document here for in-case other coding newbs need it in the future. After I made the MT.Util corrections, I still had a warning about 'WebSocket4net' could not be found, as you mentioned above Donald. So I went to trusty google and downloaded the package from: https://www.nuget.org/packages/Websocket.Client/ I then copy and pasted that package into my API test folder and that seemed to resolve it. Finally, I still had an error asking me to remove 'the mark of the web' from WS Tester.resx That was solved by finding the file in windows, clicking on properties, and clicking on 'unblock' at the bottom of the general section. Quote Link to comment Share on other sites More sharing options...
alv123 Posted November 27, 2021 Author Report Share Posted November 27, 2021 (edited) So now its a case of me playing around with the sample code in here I guess, to see if I can get something working: https://docs.google.com/document/d/15IvYQEYzSeftTSEdVhsptAguM0fGm9mTJFSDDAK7zWE/edit# Are there any risks I should be aware of before I start typing code in willy nilly? It is only connected to my IB paper trading account so I should be fine to do whatever, right? Edited November 27, 2021 by alv123 Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted November 28, 2021 Report Share Posted November 28, 2021 Just try things in the API Tester first. Send a command, see what comes back. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.