Jump to content
Medved Trader Forums

API access to chart period displayed?


Jason

Recommended Posts

In developing a C# version of the software I use for trading I'm not able to duplicate one of it's abilities. In the software I'm able to use a hotkey that launches a script that monitors price action and pulls candle data but to do this it needs to retrieve the period of the main chart I use. This is necessary as sometimes I will want to place a trade on a setup on the 5m chart or maybe the 2m chart, etc.

Is there any way through the API that the code I write can retrieve the period of a specific chart at the time I use the hotkey to begin monitoring for certain conditions? This chart is always the same window even though I have many different charts open while trading..5m charts, 2m, 15m, 30m charts etc.. I suppose it would be possible to report the period of a chart through the APIKeyPressUpdate but the challenge there is that it's difficult for me to ensure that I've always got the one window in focus when I use the hotkey to send the window data. I considered that it might be possible to use a hotkey that would both send the window data AND run my software but I'm not sure how that would work as I'm registering global hotkeys to run the software which I believe would take control of them away from MT.

In the original version of my software I would use a script to identify the window handle of the window in question and then through text manipulation of its title pull the chart period.

Link to comment
Share on other sites

I mean frequency. In my workflow I would use a hotkey which would then launch a script. The job of the script is to look at the candles that form as they are created and place trades if the price action does one thing or another. My decision to use the hotkey is dependent upon a setup or the trading environment I see on the chart (maybe with 2m candles or maybe I'm looking at a 5m candle chart). The script cannot do its job as intended if it doesn't know the frequency of the candles displayed on that main chart at the time I use the hotkey. A setup for a trade that I can see on the 2m chart would not be apparent, or valid, on the 5m chart, for example.

As I understand its functioning, the problem with using APIKeyPressUpdate is that I would need to use a hotkey specified in the MT settings for sending the window data and THEN follow that using a separate hotkey to initiate the process described above in my software. The problems are 1) I would then have to use two separate hotkeys to achieve the same outcome, 2) I would have to be very careful to make sure that the main chart window in question has focus at the moment I need to get everything started or bad things could happen (NOT easy to guarantee that the proper window has focus), 3) as far as I could see when I checked it out the candle frequency is not returned by APIKeyPressUpdate. Although I may be wrong about 3.. One complication is that, as far as I can tell, if in my software I set up and register a global hotkey that hotkey cannot be the same one I set up in MT to trigger the APIKeyPressUpdate.

One interesting thing I noticed is that in MT Dashboard I can see a complete list of ALL MT windows currently open along with their corresponding window titles. If I could retrieve that list in the API that would almost be enough of what I need. The missing piece is the ability to identify the correct window throughout the trading session. The main chart window I use is always the same window for each trade I place throughout the day. In original incarnation of my software I would use a function in my script to locate the correct window (by searching for a window with the same height and width of the main one) and extract the internal window handle used by Windows. Each script managing a trade would then be able to operate with impunity knowing the correct candle frequency would be used. I'm just not sure of a way to produce the same outcome with the API.

Link to comment
Share on other sites

  • 2 weeks later...

I've been thinking about this and believe there are a number of possible solutions. If I could pass a command through to the API that would retrieve a list of open windows or the window information for the window(s) which all share a particular linked symbol color that could allow me access to the necessary information. That may also open up opportunities in the future if there were ever any plans to expand the API to provide higher resolution control over MT.

I am not at the point where it's necessary for me to resolve this as I have a lot of other work that needs to be done but I also believe that I could work up my own solution to pull the window handle if necessary.

Link to comment
Share on other sites

Jason, I don't know if I fully I understand your use case but here's something you can try to read a chart's frequency from WS API.

Calculate CandleSizeInSec function's value in a Painbar to assign frequency to chartvar() or Intervar(). Set this paintbar on the chart then value read from your app from getintervar()

Link to comment
Share on other sites

  • 3 months later...

Wanted to update here to say that this indeed has solved the problem for me. It's a roundabout way of obtaining the candle frequency but does the job.

Now, if there were just a way to SET the frequency for a specific chart through the API. It's not critical for me but would be very nice. My use case would be that when my software sends an order to enter a position it could then set the symbol for the main chart AND change the frequency to the one in use when the setup was defined and the hotkey used.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...