How to draw a few buttons on charts?
Author: Clearpicks
Creation Date: 7/19/2010 8:52 PM
profile picture

Clearpicks

#1
Hi,

Can someon show me some code snippet to draw a button on a chart so that whenever that button is clicked the close price of the last bar on chart is printed out in a log file or on the chart? Your help is greatly appreciated.

- Clearpicks
profile picture

Cone

#2
Nothing really occurs to me, although my feeling is that you'd have to experiment attempting to do this kind of interaction within a custom Chart Style.

What's the motivation for the need to use a button for this purpose? Can the logic for when you "press" the button be coded in a script?
profile picture

Eugene

#3
Although I too feel that clicking the "Go" button might be enough to output anything to a log file, creating a button should be easily possible if you program it as a Chart Drawing Object (CDO). Unfortunately, last time Fidelity disclosed the API documentation, this innocuous piece of it was omitted.
profile picture

Cone

#4
Hey, nice idea! "Draw yourself a button" :)
profile picture

Clearpicks

#5
Hi Eugene,

Could you post the Chart Drawing Object API or code snippet here? I contacted Fidelity support, but they said they didn't have that API document and because you are the WL developer it would be better to ask you directly. The purpose of drawing a button on chart is not to write something on screen or in log file. If it is possible to draw some user clickable buttons on charts, it would open a door for users to interact with the scripts in realtime. I don't use wealth-lab for backtesting or screening, I use it for realtime market monitoring and trade signal generation. I need to interact with the running scripts to adjust some parameters, turn on/off certain logic in the script, etc. Moreover, once I meet the 500 trades/yr requirement, I am able to do some on-chart trading via the buttons drawn and the Auto-Trading APIs.


- Clearpicks
profile picture

Eugene

#6
QUOTE:
it would open a door for users to interact with the scripts in realtime.

No it wouldn't. Just forget about the idea, interacting with the running scripts is not going to work.
profile picture

Eugene

#7
P.S. If I had more time, I could try building a code example with buttons. Not only would it be a waste of time, it would also be useless to you. Hence, it makes sense starting with what you're after (e.g. "interacting with scripts"), not with the vision of it (i.e. "buttons on chart"). It's much like saying "build me a car" and later adding, "oh, I want it to fly".
profile picture

Clearpicks

#8
Engene,


Thank you for your response. Could you explain why it would not work? If I define a few member variables in a strategy class, and when the user clicks those buttons to set those member variables to certain values, and the strategy just checks those variables at the end of current bar in realtime. For example, the user may define four different trading setups (trend following buy, trend following sell, trend fadng buy, trend fading sell) in one strategy script, and the user may tell the script which kind of signals among these four kinds of signals to generate in realtime according to his own interpretation of the market status. Also it is possible to draw a buy or sell button on the chart, whenever the user clicks the "buy" button, a buy market order is sent to fidelity. Why do you say such kind of interaction via button would not work? On Ninjatrader forum, those guys are able to place buttons on chart or even in the toolstrip of a chart window. Since both wealth-lab and Ninjatrader are C# .net based, what can be done in NT can also be done in WL5, am I correct?

- Clearpicks
profile picture

Eugene

#9
Because the strategy executes each time it receives a "new bar in, previous bar closed" event, and then finishes - i.e. it doesn't react to intra-bar events.

Not intend to sound harsh at all, but just because two applications provide the user with a similar programming language, it doesn't make them cousins in a conceptual way. From the architectural standpoint, intra-bar operation and script interaction takes something else (not available).

profile picture

Cone

#10
QUOTE:
strategy just checks those variables
Well, this is already there too. They're call Strategy Parameters and you can adjust them using the sliders at the bottom of the Data Tree.

QUOTE:
it is possible to draw a buy or sell button on the chart, whenever the user clicks the "buy" button, a buy market order is sent to fidelity
Already answered in another post - you don't have to draw it, it's already there.

Re: Ninjatrader
Sure, anything is possible if you spend the money to add it. I think you need to still discover what is already available and how you can use it.
profile picture

Eugene

#11
QUOTE:
They're call Strategy Parameters and you can adjust them using the sliders at the bottom of the Data Tree.

Right, but not while a Strategy is streaming.
profile picture

Cone

#12
Good point.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).