NexusFi: Find Your Edge


Home Menu

 





need help with trend lines indicator.


Discussion in TradeStation

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




 
Search this Thread

need help with trend lines indicator.

  #1 (permalink)
maggtrading
quintana roo, méxico
 
Posts: 84 since Mar 2013
Thanks Given: 222
Thanks Received: 40

folks, i'm having trouble with trend lines in easy language and i decided to post in this new thread.


i'm trying to create an indicator that would draw something like a gann fan on the high of the first bar after a % increase ( length 60, pctup .5% ) was observed. i would use the same logic the ts % increase paint bar uses, all the rays in the gann fan should continue extending to the right, and in the first bar that this % increase condition stops being true the gann fan should be stop extending right or be deleted.

 
Code
if RateOfChange( Price, Length ) >= PctUp then
	begin
	PlotPaintBar( High, Low, Open, Close, !( "%Incr" ) ) ;
	Alert ;
	end

i have taken a look at all the sample code for trend lines i have been able to find and the closest thing i could find has been this indicator below. however, i haven't been able to make any progress at all in putting this indicator together, i'm not a programmer and this has been really frustrating. i haven't been able to modify the code below so that it would identify the first bar when a % increase of .5 was observed (and also stored its date, time and price coordinates) and then it drew trend lines (a gann fan of 8x1,4x1,...,1x8 lines) that fanned out from the high of that particular bar.


i understand that creating trend lines from easylanguage requires a start and end point for each, but if i have just the start point and want to extend several lines from that point at different gann angles (¿or angles, or slopes?) i haven't been able to think of any possible methods so that i could get ts to do this. ¿does anyone know how does the code for gann fans drawing objects work or where could i find it?


 
Code
 
using elsystem ; 
using elsystem.drawingobjects ; 
using elsystem.drawing ; 
 
variables: 
	TrendLine MyTL( NULL ), 
	DTPoint StartDT( NULL ), 
	DTPoint EndDT( NULL ), 
	DateTime LastPivotLowBar( NULL ), 
	DateTime LastPivotHighBar( NULL ), 
	double LastPivotHigh( 0 ), 
	double LastPivotLow( 0 ) ; 
	 
method void CreateTL() 
	begin 
	{ create the start and end points for the trendline by bar number using the 
	  DTPoint class } 
	StartDT = DTPoint.Create( LastPivotLowBar, LastPivotLow ) ; 
	EndDT = DTPoint.Create( LastPivotHighBar, LastPivotHigh ) ; 
	 
	{ create the trendline } 
	MyTL = TrendLine.Create( StartDT, EndDT ) ; 
	MyTL.Tag = "Entry" astype string ; { this "Tag" property can be used to identify 
	 the trendline; an example can be found in the "MyTL_Click" event handler  
	 below } 
	MyTL.Click += MyTL_Click ; { event handler triggered when the trendline is  
	 clicked } 
	 
	{ set the trendline to NOT be extended left or right } 
	MyTL.ExtLeft = false ; 
	MyTL.ExtRight = false ; 
	 
	MyTL.Color = Color.Cyan ; { set the color of the trendline } 
	MyTL.Style = StyleType.solid ; { set the style of the trendline } 
	MyTL.Weight = 3 ; 
	 
	{ 
	set the trendline to persist once drawn; if set to false, the behavior is  
	similar to the legacy behavior where the TL is deleted unless created on  
	an bar closing tick 
	} 
	MyTL.Persist = true ; 
	end ;	 
 
method void ShowTL() 
	begin 
	{  
	this is how the trendline is "shown" - the trendline is added to the  
	DrawingObjects collection; if you want to remove the trendline, 
	you can use the Delete method of the DrawingObjects class 
	} 
	DrawingObjects.Add( MyTL ) ; 
	end ; 
 
method void MyTL_Click( Object sender, DrawingObjectEventArgs args ) 
variables: TrendLine TL ; 
	begin 
	{ the sender object identifies which trendline was clicked; to use the 
	  trendline object, the sender object needs to be cast as a trendline } 
	TL = sender astype TrendLine ; 
 
	print( "You clicked on the ", DoubleQuote, TL.Tag.ToString(), DoubleQuote, 
	 " trendline." ) ; 
	end ; 
 
once 
	begin 
	{ these DateTime objects will be used to hold the DateTime of the last Pivot 
	  High and last Pivot Low } 
	LastPivotHighBar = new DateTime ; 
	LastPivotLowBar = new DateTime ; 
	end ; 
					 
once ( LastBarOnChartEx  ) { use LastBarOnChartEx for accuracy to the second } 
	begin 
	CreateTL() ; 
	ShowTL() ; 
	end ; 
 
{ look for pivot high and pivot low; store the DateTime of the most recent pivots } 
if PivotHighVSBar( 1, High, 5, 5, 5 + 1 ) <> -1 then { Pivot High found } 
	begin 
	LastPivotHighBar = BarDateTime[5] ; { store the bar DateTime stamp } 
	LastPivotHigh = High[5] ; { store pivot High price } 
	end ; 
 
if PivotLowVSBar( 1, Low, 5, 5, 5 + 1 ) <> -1 then { Pivot Low found } 
	begin 
	LastPivotLowBar = BarDateTime[5] ; { store the bar DateTime stamp } 
	LastPivotLow = Low[5] ; { store pivot Low price } 
	end ; 
	 
Plot1( Close ) ; { dummy plot to let you know the indicator is applied }

what i have in mind would look like this:

this is the paint bar by itself showing that the % increase is being observed.



and as soon as the condition starts being true, i would want the 9 trend lines to be drawn from the high of that bar and to extend right until the % increase condition stopped being true.




if anyone can help me put this indicator together or has any suggestions i would greatly appreciate it. thanks.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
19 thanks
GFIs1 1 DAX trade per day journal
16 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

maggtrading,

take a look in the Tradestation forum, there are threads with indicators drawing Gann Fans (use the Advanced Search option as it allows you to search for exact phrases like Gann Fan). This might give you some ideas.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #3 (permalink)
maggtrading
quintana roo, méxico
 
Posts: 84 since Mar 2013
Thanks Given: 222
Thanks Received: 40


good day again to everyone,



i have been putting in more time trying to get easylanguage trend lines to work but i have made practically no progress so far. i have some very concrete questions and if anyone with easylanguage knowledge could chip in with the answers that would be great.



first of all, ¿is there any way to get the ts development environment to comment on any errors that are keeping a particular instrument from verifying? every other coding interface i have come across earlier does give a brief description of what went wrong, where and why but with ts there are no explanations as to why any piece of code won't verify.




now, back to the subject of trend lines, as far as i understand, every trend line needs 4 coordinates: starting date and time, starting price level, ending date and time, and ending price level.


i want my trend line to be drawn at the high of the first bar for which a % increase ( length 60, pctup .2% ) is true. i think something similar to this fragment of code below could identify when this condition ( startingpointfan ) becomes true:

 
Code
 
 
  
if RateOfChange( Price, Length ) >= PctUp then percchange = true; 
 
 
if percchange[0] = true and percchange[1] = false then startingpointfan = true; 
 
else startingpointfan = false;
now the question would be, ¿how could i get easylanguage to obtain and store the date, time and price values for the bar where this event last took place? ¿what if i wanted the ts engine to obtain these same values for the bar when price last crossed over an sma or other similar conditions?


the sample code that ts linked to (i included it in my second post) uses a specialized function PivotHighVSBar that returns the location for an event. i also discovered that a similar function exists for the bars where the highest or lowest values were observed, but if i want to obtain and store the data for other kind of events i have no idea whether ts can accomplish this kind of tasks.



the second question would be, once i have managed to get the set of coordinates for the starting point, ¿how could i extend a trend line from that particular point?


from what i have researched, the ending price level could be determined with the following equation, where y2 is the ending price level, y1 is the starting price level, L could be standardized to 1 and a would be the angle we wanted.

y2 = y1 + (L * sin(a))


it is the ending date and time coordinate i'm having the most trouble with. ¿how could i add get the ts engine to go to the next bar on the chart? keep in mind that this code would require tweaks - adjustments for different kinds of bars (daily, weekly, monthly, versus minute - range - momentum - etc). i'm thinking that x2 could be determined very simply by adding 1 to x1.

x2 = x1 + 1


i have tried this very formulation on my indicator but it won't verify:


 
Code
 
 
	LastPivotHighBar = BarDateTime[5] ; 
 
LastPivotHighBarse = LastPivotHighBar + 1;


very well, if anyone has any suggestions or code samples they will be greatly appreciated. thanks, regards.

Reply With Quote




Last Updated on October 16, 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