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,387 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Converting y to price with TS

  #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?
About a successful futures trader who didnt know anythin …
Psychology and Money Management
Cheap historycal L1 data for stocks
Stocks and ETFs
Trade idea based off three indicators.
Traders Hideout
What broker to use for trading palladium futures
Commodities
Better Renko Gaps
The Elite Circle
 
  #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,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

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 Twitter 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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts