NexusFi: Find Your Edge


Home Menu

 





Non scrolling trendlinies


Discussion in EasyLanguage Programming

Updated
    1. trending_up 1,907 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 1 posts
    2. attach_file 1 attachments




 
Search this Thread

Non scrolling trendlinies

  #1 (permalink)
 TwoHands 
Fort Lauderdale, Florida
 
Experience: Beginner
Platform: TradeStation
Trading: ES
Posts: 115 since Apr 2011
Thanks Given: 97
Thanks Received: 150

This is a repost from another thread because I forgot this thread existed. Duh.
___________________________


Got some code from one of the TradeStation coders on their forum but as a non-coder and failed tinkerer I don't know how to get this to where I want it. I added the inputs and variables to show the nine lines I want.

 
Code
#region - Documentation - 
{ 
--------------------------------------------------------------------------------------------------- 
IDENTIFICATION 
============== 
Name:			RightTLs 
Type:			Indicator 
TS Version:		9.5 Build 17 or later 
 
--------------------------------------------------------------------------------------------------- 
DOCUMENTATION 
============= 
This 9.5 sample indicator draws a trendline to the right of the current bar, extended to the right 
and shifts the starting point as new bars are added to the chart.  A label is also drawn abvoe the  
trendline. 
 
--------------------------------------------------------------------------------------------------- 
HISTORY 
======= 
Date		By		Version		Task 
---------	-------	--------	------------------------------------------------------------------- 
01/22/18	chrisd	01.00.00	* Created 
 								 
--------------------------------------------------------------------------------------------------- 
} 
#endregion 
 
using elsystem;   
using elsystem.collections;  
using elsystem.drawing;   
using elsystem.drawingobjects;  
using tsdata.common;  
 
inputs: 
	int iBarsToRight(2), 
	string iColorName("Green"), 
	double iLabelFontSize(9.5),
	Lab1("R2"),
	Lab2("R1"),
	Lab3("PP"),
	Lab4("S1"),
	Lab5("S2"),
	Lab6("Glo Hi"),
	Lab7("Glo Lo"),
	Lab8("Y Close"),
	Lab9("Today Open"),
	Val1 (0),
	Val2 (0),
	Val3 (0),
	Val4 (0),
	Val5 (0),
	Val6 (0),
	Val7 (0),
	Val8 (0),
	Val9 (0);
	 
	 
variables: 
	TrendLine TL(null), 
	TextLabel TX(null), 
	BNPoint BNP(null); 
 
  
method TrendLine CreateTL(int startBarNo,  
	double price,  
	string tlName, 
	Color MyColor )    
variables: TrendLine TL;   
begin   
	TL = TrendLine.Create( BNPoint.Create(startBarNo + MaxBarsBack - 1, price),   
						   BNPoint.Create(startBarNo + MaxBarsBack - 1 + 1, price));   
	TL.Lock = true;   
	TL.Color = MyColor;   
	TL.Weight = Weight.Weight1;  
	TL.Persist = true;   
	TL.ExtRight = true; 
	TL.Name = tlName; 
	return TL;   
end;  
 
method TextLabel CreateTextLabel(int startBarNo, 
	double price,  
	string txName, 
	string labelText,  
	Color MyColor)   
variables: TextLabel TxtLbl;   
begin   
	TxtLbl = TextLabel.Create(BNPoint.Create(startBarNo + MaxBarsBack - 1, Price), labelText);  
	TxtLbl.Lock = true;   
	TxtLbl.Color = MyColor;   
	TxtLbl.Persist = true;  
	TxtLbl.VStyle = VerticalStyle.Bottom;   
	TxtLbl.HStyle = HorizontalStyle.Left;   
	TxtLbl.Font = Font.Create( "Arial", iLabelFontSize );  
	TxtLbl.Name = txName;  
	return TxtLbl;   
end;  
 
if LastBarOnchartEx and TL = null then 
begin 
	TL = CreateTL(CurrentBar + iBarsToRight, Val1, Lab1, Color.FromName(iColorName)); 
	DrawingObjects.Add(TL); 
	TX = CreateTextLabel(CurrentBar + iBarsToRight, Val1, Lab1, string.Format("{0} {1}", Lab1, Val1), 
		Color.White); 
	DrawingObjects.Add(TX);	
	   
	TL = CreateTL(CurrentBar + iBarsToRight, Val2, Lab2, Color.FromName(iColorName)); 
	DrawingObjects.Add(TL); 
	TX = CreateTextLabel(CurrentBar + iBarsToRight, Val2, Lab2, string.Format("{0} {1}", Lab2, Val2), 
		Color.White); 
	DrawingObjects.Add(TX);	 
 
	TL = CreateTL(CurrentBar + iBarsToRight, Val3, Lab3, Color.FromName(iColorName)); 
	DrawingObjects.Add(TL); 
	TX = CreateTextLabel(CurrentBar + iBarsToRight, Val3, Lab3, string.Format("{0} {1}", Lab3, Val3), 
		Color.White); 
	DrawingObjects.Add(TX);	 
	 
	TL = CreateTL(CurrentBar + iBarsToRight, Val4, Lab4, Color.FromName(iColorName)); 
	DrawingObjects.Add(TL); 
	TX = CreateTextLabel(CurrentBar + iBarsToRight, Val4, Lab4, string.Format("{0} {1}", Lab4, Val4), 
		Color.White); 
	DrawingObjects.Add(TX);	 
	 
	TL = CreateTL(CurrentBar + iBarsToRight, Val5, Lab5, Color.FromName(iColorName)); 
	DrawingObjects.Add(TL); 
	TX = CreateTextLabel(CurrentBar + iBarsToRight, Val5, Lab5, string.Format("{0} {1}", Lab5, Val5), 
		Color.White); 
	DrawingObjects.Add(TX);	 
	 
	TL = CreateTL(CurrentBar + iBarsToRight, Val6, Lab6, Color.FromName(iColorName)); 
	DrawingObjects.Add(TL); 
	TX = CreateTextLabel(CurrentBar + iBarsToRight, Val6, Lab6, string.Format("{0} {1}", Lab6, Val6), 
		Color.White); 
	DrawingObjects.Add(TX);	 
	 
	TL = CreateTL(CurrentBar + iBarsToRight, Val7, Lab7, Color.FromName(iColorName)); 
	DrawingObjects.Add(TL); 
	TX = CreateTextLabel(CurrentBar + iBarsToRight, Val7, Lab7, string.Format("{0} {1}", Lab7, Val7), 
		Color.White); 
	DrawingObjects.Add(TX);	 
	 
	TL = CreateTL(CurrentBar + iBarsToRight, Val8, Lab8, Color.FromName(iColorName)); 
	DrawingObjects.Add(TL); 
	TX = CreateTextLabel(CurrentBar + iBarsToRight, Val8, Lab8, string.Format("{0} {1}", Lab8, Val8), 
		Color.White); 
	DrawingObjects.Add(TX);	 
	 
	 	TL = CreateTL(CurrentBar + iBarsToRight, Val9, Lab9, Color.FromName(iColorName)); 
	DrawingObjects.Add(TL); 
	TX = CreateTextLabel(CurrentBar + iBarsToRight, Val9, Lab9, string.Format("{0} {1}", Lab9, Val9), 
		Color.White); 
	DrawingObjects.Add(TX);	
	
//	Move right 
if BarStatus(datanum + 1) = 2 and TL <> null then 
begin 
	BNP = BNPoint.Create(CurrentBar + MaxBarsBack - 1 + iBarsToRight, (TL.StartPoint astype BNPoint).Price); 
	TL.SetStartPoint(BNP); 
	TX.SetPointValue(BNP); 
	BNP = BNPoint.Create(CurrentBar + MaxBarsBack - 1 + iBarsToRight + 1, (TL.StartPoint astype BNPoint).Price); 
	TL.SetEndPoint(BNP); 
end;
end;
The idea is to have levels show up on a chart with trendlines and labels that stay on the right side of the chart in the area defined by "space to the right" in the Format Window dialog box as in this pic…



Ideally this would be done with ADE but I'm not even in coding kindergarden so I'm not gonna try. I don't mind manually entering my levels in the morning but I've run into two problems. Both were addressed by the TS coder but I don't have the knowledge or skill to implement them.

1. The display cuts off the trailing zeros from the value on the text label so it won't alway show the two decimal places I want.

TS answer: Rather than having the numeric value as the value utilized by a string.Format pass in a numtostr(price, 2) to force the price to have two decimal places. If you want to make the code be able to handle different symbols with different numbers of decimal places, declare an intrabarpersist variable name DecimalPlaces and then populate it as follows:

DecimalPlaces = NumDecimals(PriceScale);


2. As candles are added to the chart the trendlines scroll left and will eventually overlap the candles. The coder has a subroutine to prevent this but I don't know how to call it from each trendline

TS answer:The code at the bottom below the // Move Right needs to be expanded to move every line and every text label you added.

I'd be grateful is someone could dig into this and apply the changes I want.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Quantum physics & Trading dynamics
The Elite Circle
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
What broker to use for trading palladium futures
Commodities
 




Last Updated on February 3, 2018


© 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