NexusFi: Find Your Edge


Home Menu

 





Converting y to price with TS


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one forward2012 with 2 posts (0 thanks)
    2. looks_two onnb with 2 posts (1 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 ABCTG with 1 posts (0 thanks)
    1. trending_up 2,903 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 onnb 
Vancouver, Canada
Onn
 
Experience: Intermediate
Platform: NinjaTrader, SierraCharts, thinkorswim
Trading: Stocks
Posts: 10 since Sep 2011
Thanks Given: 0
Thanks Received: 3

Hi all, I am writing a TS program that responds to mouse clicks. I need to know the price at which the user clicked the price chart. I have the code that responds to mouse clicks. It generally receives the x/y coordinates and those need to be translated to price.

The code below almost works. The problem is that the clientWindow.Height includes the height of the main price sub graph as well as any other panels I have on (MACD or what not). I need to access the height of the main price panel or perhaps someone has anothe approach as to how to convert y coordinates to price?

 
Code
Using elsystem;
Using elsystem.collections;
Using elsystem.xml;
Using elsystem.io;
Using elsystem.windows.forms;
Using elsystem.drawing;
Using tsdata.common;
Using tsdata.trading;
Using platform;
Using charting;


Vars:
ChartingHost ch(NULL), price(0);

// Method called on AnalysisTechnique Initialized event.
// The sender parameter identifies the object that fires the event.
// The args parameter contains additional information about the event.
// NOTE:  Do not modify the method name, return type, or input parameters.

Method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args ) 
begin
	{ Insert your EasyLanguage statements below }
	Print("AnalysisTechnique_Initialized");
	ch = ChartingHost.Create();
	
	ch.ChartElementClick += ChartingHost1_ChartElementClick;
end;



Method double ConvertYToPrice(int y)
Var: double highDisplay, double lowDisplay, double chartscale, double percentage, double clickPrice;
Begin
	highDisplay = Getappinfo(Aihighestdispvalue);
	lowDisplay = Getappinfo(Ailowestdispvalue);
	
	percentage = y / ch.ClientWindow.Height;
	clickPrice = highDisplay - (highDisplay - lowDisplay) * percentage;
	
        // next, round to tick size	

	Return 0;

end;


Method void ChartingHost1_ChartElementClick( elsystem.Object sender, charting.ChartElementClickEventArgs args )
begin
	If (args.Button  = MouseButton.Right) then
		Return;
	
	price  = ConvertYToPrice(args.Y);
			
end;


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
ATFX Suspends Prop Trading Unit ATFunded -- Full Review …
Funded Trading Evaluation Firms
Election Sunday Resolves: Peru Heads to Runoff at 42pct, …
Prediction Markets & Event Contracts
Powell in 48 Hours: Word Markets Give 78% on Inflation, …
Prediction Markets & Event Contracts
UMA Votes Tonight: Polymarkets $80M Strategy Bitcoin Bat …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
196 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
BERN ALGOS algo trading journal
8 thanks
Volume Indicators
8 thanks
  #3 (permalink)
 onnb 
Vancouver, Canada
Onn
 
Experience: Intermediate
Platform: NinjaTrader, SierraCharts, thinkorswim
Trading: Stocks
Posts: 10 since Sep 2011
Thanks Given: 0
Thanks Received: 3


For anyone interested, I think I found the solution....

elsystem.InitializedEventArgs args has an attribute called DataStreamValue which returns the price on which the user clicked.

so it looks like: args.DataStreamValue

You can test that the price is between Getappinfo(Aihighestdispvalue); and Getappinfo(Ailowestdispvalue); and determine that the user clicked on the price chart and not on some other panel.

Onn


Started this thread Reply With Quote
Thanked by:
  #4 (permalink)
 forward2012 
AUSTIN, TX
 
Experience: Advanced
Platform: Thinkorswim
Trading: stocks
Posts: 4 since Nov 2012
Thanks Given: 0
Thanks Received: 0

Anybody knows how to make this code work?


Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

forward2012,

can you elaborate what exactly is not working for you? I suspect that you need to include the solution @onnb pointed out in his second post for the code to work.

Regards,
ABCTG


Follow me on X Reply With Quote
  #6 (permalink)
 forward2012 
AUSTIN, TX
 
Experience: Advanced
Platform: Thinkorswim
Trading: stocks
Posts: 4 since Nov 2012
Thanks Given: 0
Thanks Received: 0

I took the code and attempted to run it. Nothing is happening. I was hoping it will show me the price on the chart or log, nope. I want to to get the price after I click on the chart, with that price I wanted to buy or sell a security. That is what I am attempting to do. If you know, it will be great show me some example or sample code.


Reply With Quote




Last Updated on August 31, 2014


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts