NexusFi: Find Your Edge


Home Menu

 





Problem with Zigzag that prints highs/lows and swing distance


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one treydog999 with 6 posts (0 thanks)
    2. looks_two courier12 with 2 posts (0 thanks)
    3. looks_3 kronie with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 6,758 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 10 posts
    2. attach_file 1 attachments




 
Search this Thread

Problem with Zigzag that prints highs/lows and swing distance

  #1 (permalink)
 
treydog999's Avatar
 treydog999 
seoul, Korea
 
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039

90% of the time this thing plots the highs and lows and swing distance correctly but sometimes it doesn't I have played with all the variables but cant figure out what's up. Anyone more experienced can help?

 
Code
// ZigZag Pnts - Text Plots
//Treydog999

inputs: 
	HighLow( True ), 
	RetracePnts( .0005 ), 
	LineColor( Yellow ), 
	LineWidth( 1 ),
	LineStyle ( 1 ) ,
	PlotLines(false),
	PriceOrSwing("Swing"),
	DecimalPlaces(4),
	Color(yellow),
	TextSize(8);
	
variables: 
	SwingMult(0),
	Price(close),
	Price1(close),
	Price2(close),
	var0( 0 ), 
	var1( Price ),                                         
	var2( Date ),                                         
	var3( Time ),                                         
	var4( 0 ),                                                         
	var5( false ), 
	var6( false ), 
	var7( false ), 
	var8( 0 ),
	SwingDistance( 0 ) ;
//Set Swing Mult
SwingMult = MinMove*PriceScale;
//High Low switch
if HighLow = true then begin
	price1 = high;
	price2 = low;
	end;

if highlow = false then begin
	price1 = close;
	price2 = close;
	end;
	                                                          
// Zigzag calcs
var0 = SwingHigh( 1, Price1, 1, 2 ) ;
if var0  <> -1 then 
	begin
		condition1 = var4 <= 0 and var0 >= var1 + RetracePnts ;
		if condition1 then 			                            
			begin
				var5 = true ;
				var6 = true ;
				var4 = 1 ;
			end 
		else 
		begin 
			condition1 = var4 = 1 and var0 >= var1 ;
			if condition1 then 			                                
			begin
				var5 = true ;
				var7 = true ;
			end;
		end ;
	end 
else 
	begin
	var0 = SwingLow( 1, price2, 1, 2 ) ;
	if var0 <> -1 then 
		begin
			condition1 = var4 >= 0 and var0 <= var1 - RetracePnts ;
			if condition1 then 				                            
			begin
				var5 = true ;
				var6 = true ;
				var4 = -1 ;
			end 
			else 
			begin 
				condition1 = var4 = -1 and var0 <= var1 ;
				if condition1 then 					                                
				begin
					var5 = true;
					var7 = true ;
				end ;
			end;
		end ;
	end ;

if var5 then 
	                                      
	begin
	var1 = var0 ;
	var2 = Date[1] ;
	var3 = Time[1] ;
	var5 = false ;
	end ;

if var6 and PlotLines = True then 
	                              
	begin
	var8 = TL_New( var2, var3, var1, var2[1], var3[1], 
	 var1[1] ) ;
	TL_SetExtLeft( var8, false ) ;
	TL_SetExtRight( var8, false ) ;
	TL_SetSize( var8, LineWidth ) ;
	TL_SetColor( var8, LineColor ) ;
	tl_setstyle(var8,LineStyle);
	var6 = false ;
	end 
else if var7 and PlotLines = True then 
	                                     
	begin
	TL_SetEnd( var8, var2, var3, var1 ) ;
	var7 = false ;
	end ;

//Text Prints
SwingDistance = absvalue(var1 - var1[1])*SwingMult;

if var4 <> var4[1] and PriceOrSwing = "Price" then
value1 = text_new(var2, var3, var1, numtostr(var1,DecimalPlaces));

if var4 <> var4[1] and PriceOrSwing = "Swing" then
value1 = text_new(var2, var3, var1, numtostr(swingdistance,0));

if var4 <> var4[1] and PriceOrSwing = "Both" then begin
if DecimalPlaces = 4 then
value1 = text_new(var2, var3, var1, numtostr(var1,DecimalPlaces)+ NewLine + "    " + numtostr(swingdistance,0) );
if DecimalPlaces = 2 then
value1 = text_new(var2, var3, var1, numtostr(var1,DecimalPlaces)+ NewLine + "  " + numtostr(swingdistance,0) );
end;

if var4 = -1 then 
	text_setlocation(value1,var2,var3,var1 - truerange*.25);

if var4 = 1 then
	text_setlocation(value1,var2,var3,var1 + truerange*.25);
	
if value1 > 0 then begin
	text_setcolor(value1,color);
	text_setstyle(value1,2,2);
	text_setsize(value1,textsize);

end;	


//debug
//value2 = text_new(var2, var3, var1 + .25*averagetruerange(10) , numtostr(var1,4));
//print(var0:0:4," ", var1:0:4, " ", var2, " ", var3, " ", var4, " ", var5, " ", var6, " ", var7, " ", var8);

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
NexusFi Journal Challenge - May 2024
Feedback and Announcements
How to apply profiles
Traders Hideout
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
35 thanks
Bigger Wins or Fewer Losses?
24 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #3 (permalink)
 
kronie's Avatar
 kronie 
NYC + NY / USA
 
Experience: Advanced
Platform: "I trade, therefore, I AM!"; Theme Song: "Atomic Dog!"
Trading: EMD, 6J, ZB
Posts: 796 since Oct 2009


I also noticed the inability to push the fibs over, say, using the displacement or +- offset, in this manner the lines and percentages can be located in the clear margin, especially if you set a high number for the margin property

is there anyway to displace right these fibs?

Reply With Quote
  #4 (permalink)
 
treydog999's Avatar
 treydog999 
seoul, Korea
 
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039


kronie View Post
I also noticed the inability to push the fibs over, say, using the displacement or +- offset, in this manner the lines and percentages can be located in the clear margin, especially if you set a high number for the margin property

is there anyway to displace right these fibs?

No you can not displace right or left.

Started this thread Reply With Quote
  #5 (permalink)
 
treydog999's Avatar
 treydog999 
seoul, Korea
 
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039

Here is an example. all of the plots on this chart except this one is correct. no idea how it does it. the zigzag plot is correct but the exit value which uses the same variable var1 is now the wrong when its set to string. If its not clear i am refering to the 1.3265 13 plot the 2nd 1.3265 is in fact correct.


Started this thread Reply With Quote
  #6 (permalink)
 
treydog999's Avatar
 treydog999 
seoul, Korea
 
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039

any easy language guru's out there lend a helping hand?

Started this thread Reply With Quote
  #7 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

When a current swing high updates by making a higher high (vice versa for the low) you correctly update the trendline end point and text location, but the code is missing the update for the text string. Add this and it should work fine.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
  #8 (permalink)
 
treydog999's Avatar
 treydog999 
seoul, Korea
 
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039


ABCTG View Post
When a current swing high updates by making a higher high (vice versa for the low) you correctly update the trendline end point and text location, but the code is missing the update for the text string. Add this and it should work fine.

Regards,
ABCTG

Yes, I have tried that and also cleaned up the variables. multicharts is stupid as they dont name anything. anyway what happens now is the swing distance when updated does not calculate correctly if there is an update. I have tried several iterations, using TL_GetBeginVal works great but if I choose the option not to plot the lines then i cant grab the value. so i added swingstart variable to extract that but now i on updates i get the distance between the update and the previous end swing so the value can be like 1 tick or something instead of from the start of the move.

 
Code
// ZigZag Pnts - Text Plots
//Treydog999

inputs: 
	HighLow( True ), 
	RetracePnts( .0005 ), 
	LineColor( Yellow ), 
	LineWidth( 1 ),
	LineStyle ( 1 ) ,
	PlotLines(false),
	PriceOrSwing("Both"),
	DecimalPlaces(4),
	Color(yellow),
	TextSize(8);
	
variables: 
	SwingMult(0),
	Price(close),
	Price1(close),
	Price2(close),
	SwingPrice( 0 ), 
	SwingPrice1( Price ),                                         
	SwingDate( Date ),                                         
	SwingTime( Time ),                                         
	TLDir( 0 ),                                                         
	SaveSwing( false ), 
	AddTL( false ), 
	UpdateTL( false ), 
	var8( 0 ),
	SwingDistance( 0 ),
	SwingStart(0) ;
//Set Swing Mult
SwingMult = MinMove*PriceScale;
//High Low switch
if HighLow = true then begin
	price1 = high;
	price2 = low;
	end;

if highlow = false then begin
	price1 = close;
	price2 = close;
	end;
	                                                          
// Zigzag calcs
SwingPrice = SwingHigh( 1, Price1, 1, 2 ) ;
if SwingPrice  <> -1 then 
	begin
		condition1 = TLDir <= 0 and SwingPrice >= SwingPrice1 + RetracePnts ;
		if condition1 then 			                            
			begin
				SaveSwing = true ;
				AddTL = true ;
				TLDir = 1 ;
			end 
		else 
		begin 
			condition1 = TLDir = 1 and SwingPrice >= SwingPrice1 ;
			if condition1 then 			                                
			begin
				SaveSwing = true ;
				UpdateTL = true ;
			end;
		end ;
	end 
else 
	begin
	SwingPrice = SwingLow( 1, price2, 1, 2 ) ;
	if SwingPrice <> -1 then 
		begin
			condition1 = TLDir >= 0 and SwingPrice <= SwingPrice1 - RetracePnts ;
			if condition1 then 				                            
			begin
				SaveSwing = true ;
				AddTL = true ;
				TLDir = -1 ;
			end 
			else 
			begin 
				condition1 = TLDir = -1 and SwingPrice <= SwingPrice1 ;
				if condition1 then 					                                
				begin
					SaveSwing = true;
					UpdateTL = true ;
				end ;
			end;
		end ;
	end ;

if SaveSwing then 
	                               
	begin
	SwingPrice1 = SwingPrice ;
	SwingDate = Date[1] ;
	SwingTime = Time[1] ;
	SaveSwing = false ;
	end ;
//added Updates text when you need to update the trend line. - Me

If UpdateTL = True then begin
SwingDistance = //absvalue(SwingPrice1 - SwingPrice1[1])*SwingMult;
		//absvalue(TL_GetBeginVal(var8)-swingprice1)*swingmult;
		absvalue(SwingStart - SwingPrice1)*SwingMult;
	If  PriceOrSwing = "Both" then begin
	if DecimalPlaces = 4 then
		Text_Setstring(value1,  numtostr(SwingPrice1,DecimalPlaces)+ NewLine + "    " + numtostr(swingdistance,0) );
	if DecimalPlaces = 2 then
		Text_Setstring(value1, numtostr(SwingPrice1,DecimalPlaces)+ NewLine + "  " + numtostr(swingdistance,0)) ;
	end;
	
	IF PriceOrSwing = "Price" then
		Text_SetString(value1, numtostr(SwingPrice1,DecimalPlaces));
	If PriceOrSwing = "Swing" then
		Text_SetString(value1, numtostr(swingdistance,0));
end;
	
//end 
If AddTL and Plotlines = false then
		SwingStart = SwingPrice1;
if AddTL and PlotLines = True then 
	                              
	begin
	SwingStart = SwingPrice1;
	var8 = TL_New( SwingDate, SwingTime, SwingPrice1, SwingDate[1], SwingTime[1], SwingPrice1[1] ) ;
	TL_SetExtLeft( var8, false ) ;
	TL_SetExtRight( var8, false ) ;
	TL_SetSize( var8, LineWidth ) ;
	TL_SetColor( var8, LineColor ) ;
	tl_setstyle(var8,LineStyle);
	AddTL = false ;
	end 
else if UpdateTL and PlotLines = True then 
	                                     
	begin
	TL_SetEnd( var8, SwingDate, SwingTime, SwingPrice1 ) ;
	UpdateTL = false ;
	end ;

//Text Prints
SwingDistance = absvalue(SwingPrice1 - SwingPrice1[1])*SwingMult;

if TLDir <> TLDir[1] and PriceOrSwing = "Price" then
value1 = text_new(SwingDate, SwingTime, SwingPrice1, numtostr(SwingPrice1,DecimalPlaces));

if TLDir <> TLDir[1] and PriceOrSwing = "Swing" then
value1 = text_new(SwingDate, SwingTime, SwingPrice1, numtostr(swingdistance,0));

if TLDir <> TLDir[1] and PriceOrSwing = "Both" then begin
if DecimalPlaces = 4 then
value1 = text_new(SwingDate, SwingTime, SwingPrice1, numtostr(SwingPrice1,DecimalPlaces)+ NewLine + "    " + numtostr(swingdistance,0) );
if DecimalPlaces = 2 then
value1 = text_new(SwingDate, SwingTime, SwingPrice1, numtostr(SwingPrice1,DecimalPlaces)+ NewLine + "  " + numtostr(swingdistance,0) );
end;

if TLDir = -1 then 
	text_setlocation(value1,SwingDate,SwingTime,SwingPrice1 - truerange*.25);

if TLDir = 1 then
	text_setlocation(value1,SwingDate,SwingTime,SwingPrice1 + truerange*.25);

//Text styling	
if value1 > 0 then begin
	text_setcolor(value1,color);
	text_setstyle(value1,2,2);
	text_setsize(value1,textsize);

end;	
		

//value2 = text_new(SwingDate, SwingTime, SwingPrice1 + .25*averagetruerange(10) , numtostr(SwingPrice1,4));
//print(SwingPrice:0:4," ", SwingPrice1:0:4, " ", SwingDate, " ", SwingTime, " ", TLDir, " ", SaveSwing, " ", AddTL, " ", UpdateTL, " ", var8);

Started this thread Reply With Quote
  #9 (permalink)
 courier12 
Mumbai India
 
Experience: None
Platform: TradeStation
Trading: Forex
Posts: 39 since Nov 2014
Thanks Given: 58
Thanks Received: 10

Hi @treydog999 :

Were you finally able to get this to work? Will be extremely useful to have.

Thank you

Reply With Quote
  #10 (permalink)
 
treydog999's Avatar
 treydog999 
seoul, Korea
 
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039



courier12 View Post
Hi @treydog999 :

Were you finally able to get this to work? Will be extremely useful to have.

Thank you

Sorry I never did figure it out. The plot and data seemed to be linked.

Started this thread Reply With Quote




Last Updated on August 7, 2015


© 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