NexusFi: Find Your Edge


Home Menu

 





Zig Zag Strategy (like Joe Ross 1 2 3) is working but it is missing some entries


Discussion in MultiCharts

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




 
Search this Thread

Zig Zag Strategy (like Joe Ross 1 2 3) is working but it is missing some entries

  #1 (permalink)
Dvdkite
Trieste Italy
 
Posts: 162 since Feb 2018
Thanks Given: 131
Thanks Received: 25

Hello everyone,

I'm trying (using the a mix of the zig zag code posted here at FIO and the one provided from multicharts) to code a strategy that uses the zig zag values to perform trades based on the Joe Ross 123 concept.

Example: If you have 3 points p1(first, swing low), p2(second, swing high) and p3(third, swing low then if p3 > p1 and p2 is bigger of both then I want to go long when the price break the p2 value so long at p2 +1 with fixed TP and SL

So I coded the strategy and it often works but it is missing some entries and I cannot understand WHY. Do you have any idea?
The following strategy is coded for the DAX future but it should work on eerything (just check the TP and SL).

 
Code

[IntrabarOrderGeneration = True];

inputs:
 // TS inputs
	
	TargetPoints(10),
	stopPoints(20),
	RR(0),

	// end TS input

	Price( Close ), 
	RetraceType( 1 ), // 1 points , 2 percent
	RetracePct( 0 ),
	RetracePnts( 12 ), 
	LineColor( Yellow ), 
	LineWidth( 1 ),
	ZigZagLineColorDN( yellow ),
	ZigZagLineColorUP( cyan ),
	
	Time_MorningStart_at ( 0800 ),
	Time_MorningStop_at ( 1930 ), // set this higher if you do not need 2 window of the session but just once
	Time_AfternoonStart_at ( 1530 ),
	Time_AfternoonStop_at ( 1730),
	Time_CLOSE_SESSION (2120), // close every open contract at this time
	
	VertOffset1 ( 8 ); // offset for display zigzag swings

variables: 
	NewSwingPrice( 0 ), // SwingHigh/Low zig
	SwingPrice( Price ),
	ZigZagCount(0),                                         
	SwingDate( Date ),                                         
	SwingTime( Time ), 
	PeakTextRef(0), // testo per plottare valore swing
       PeakStr(""),
       ShowEnterAt(0),
  
       isTheRightTime (false),
       canEntry(false), 
       printDebug (true), 
                               
	TLDir( 0 ),                                                         
	var5( 1 + RetracePct * .01 ), // percent retrace up
	var6( 1 - RetracePct * .01 ), // percent retrace down
       RetracePriceLevel(0), // retracement value for ptns and %
	SaveSwing( false ), 
	AddTL( false ), 
	UpdateTL( false ), 
	var10( 0 ),
	
	//----------------
	
	intrabarpersist zigEnabled (false),
	intrabarpersist canPrint (false),
	//---------------
	
	z1(0),
	z2(0),
	z3(0),
	
	X(0),
	Y(0),
	Z(0);

arrays:
	ZigZagArray[10,4](0); // Save here the latest swings
                                                                               

//Time frame of the day where entries are allowed
isTheRightTime = ( time >= Time_MorningStart_at and time <= Time_MorningStop_at) or ( time >= Time_AfternoonStart_at and time <= Time_AfternoonStop_at);

//Selezione caso rintracciamento percentuale o a punti
Switch(TLDir)
	Begin
		Case <= 0:
			Switch(RetraceType)
				Begin
					Case 1: RetracePriceLevel=SwingPrice+RetracePnts;
					Case 2: RetracePriceLevel=SwingPrice*var5;
				End;					
		Case >= 0:
			Switch(RetraceType)
				Begin
					Case 1: RetracePriceLevel=SwingPrice-RetracePnts;
					Case 2: RetracePriceLevel=SwingPrice*var6;				
	                     End;

      End;
 
NewSwingPrice = SwingHigh( 1, Close, 1, 2 ) ; // Picco UP, se al posto di Price metto H usa i massimi altrimenti i close per i vertici
if NewSwingPrice <> -1 then 
	begin
		condition1 = TLDir <= 0 and NewSwingPrice>= RetracePriceLevel ; // var1 * var5 rappresenta RetracePriceLevel
		if condition1 then	// mi preparo ad aggiungere una trend line UP		                            
		begin
			SaveSwing= true ;
			AddTL= true ;
			TLDir= 1 ;
			//Alert("Swing Up");

			end 
		else 
		begin  // preparo un upgrade alla trend line UP precedente	                  
			condition1 = TLDir= 1 and NewSwingPrice>= SwingPrice;
			if condition1 then 
				                                
			begin
				SaveSwing= true ;
				UpdateTL = true ;
				//Alert("Swing Up");

			end ;
		end;
	end 
else 
	begin
	NewSwingPrice= SwingLow( 1, Price, 1, 2 ) ;  // Picco DOWN
	if NewSwingPrice<> -1 then 
		begin
			condition1 = TLDir>= 0 and NewSwingPrice<= RetracePriceLevel ;
			if condition1 then 
				                            
				begin
				SaveSwing= true ;
				AddTL= true ;
				TLDir= -1 ;
				//Alert("Swing Down"); 

				end 
			else 
			begin // preparo un upgrade alla trend line DOWN precedente
				condition1 = TLDir= -1 and NewSwingPrice<= SwingPrice;
				if condition1 then 				                                
				begin
				SaveSwing= true;
				UpdateTL= true ;
				//Alert("Swing Down");

				end ;
			end;
		end ;
	end ;

if SaveSwing then 
	                                      
	begin
	SwingPrice= NewSwingPrice;
	SwingDate= Date[1] ;
	SwingTime= Time[1] ;
	SaveSwing= false ;
	canEntry= true; // variabile per evitare entrate multiple, cos in teoria puo' farlo solo una volta dopo ogni swing confermato
	end ;

if AddTL then 
	                              
	begin
	var10 = TL_New( SwingDate, SwingTime, SwingPrice, SwingDate[1], SwingTime[1], 
	 SwingPrice[1] ) ;
	TL_SetExtLeft( var10, false ) ;
	TL_SetExtRight( var10, false ) ;
	TL_SetSize( var10, LineWidth ) ;
	PeakTextRef=Text_New(Date,Time,Close," "); //  Inizializzo

	
	If(TLDir=-1)Then TL_SetColor(var10,ZigZagLineColorDN)
	Else TL_SetColor(var10,ZigZagLineColorUp);
	
	ZigZagCount=ZigZagCount+1;
	
	//Scalo di un posto indietro i valori degli swing prima di inserire il nuovo al posto 0
	For Y=9 DownTo 0
		Begin 
		For Z=1 to 4
			Begin
			ZigZagArray[Y+1,Z]=ZigZagArray[Y,Z];
			End;
		End;
	//Inserisco i nuovi dati dello swing nella prima riga ovvero la zero
	ZigZagArray[0,1]=SwingPrice; {Current Swing Price}
	ZigZagArray[0,2]=BarNumber; {BarNumber}
	ZigZagArray[0,3]=TimetoMinutes(SwingTime); {SwingTime Variable}
	ZigZagArray[0,4]=ZigZagCount; {Current ZZ Count}
	
	//print(" zigzag " , NumToStr(ZigZagArray[1,1],2), "  ZZ number: " , NumToStr(ZigZagCount,0));
	//Plot valore swing
	PeakStr=NumToStr(SwingPrice,2);
	Text_SetString(PeakTextRef,PeakStr);
	Text_SetStyle(PeakTextRef,2,2);
	If(TLDir=-1)Then Text_SetColor(PeakTextRef,ZigZagLineColorDN)
	Else Text_SetColor(PeakTextRef,ZigZagLineColorUp);
	If(TLDir=-1)Then Text_SetLocation(PeakTextRef,SwingDate,SwingTime,SwingPrice - VertOffset1)
	else Text_SetLocation(PeakTextRef,SwingDate,SwingTime,SwingPrice + VertOffset1);
		
	AddTL = false ;
	canEntry = false;
	end 
else if UpdateTL then 
	                                     
	begin
	TL_SetEnd( var10, SwingDate, SwingTime, SwingPrice) ;
	
	ZigZagArray[0,1]=SwingPrice; {Current Swing Price}
	ZigZagArray[0,2]=BarNumber; {BarNumber}
	ZigZagArray[0,3]=TimetoMinutes(SwingTime); {SwingTime Variable}

	//Plot valore swing
	PeakStr=NumToStr(SwingPrice,2);
	Text_SetString(PeakTextRef,PeakStr);
	Text_SetStyle(PeakTextRef,2,2);
	If(TLDir=-1)Then Text_SetColor(PeakTextRef,ZigZagLineColorDN)
	Else Text_SetColor(PeakTextRef,ZigZagLineColorUp);
	If(TLDir=-1)Then Text_SetLocation(PeakTextRef,SwingDate,SwingTime,SwingPrice - VertOffset1)
	else Text_SetLocation(PeakTextRef,SwingDate,SwingTime,SwingPrice + VertOffset1);
	
	UpdateTL= false ;
	end ;


CommentaryCL ("PeakStr: ",PeakStr,NewLine);

//--------------------------------- STRATEGY START HERE --------------------------------------- 

// lo swing attuale (quello che sarebbe z0) e' la variabile SwingPrice
z1 = ZigZagArray[1,1];
z2 = ZigZagArray[2,1];
z3 = ZigZagArray[3,1];
	

//print("il valore delllo zig 1,1 alle ore ", time," e' ", NumToStr(z1,2), NewLine, NewLine, "mentre lo zig 2,1 e' ", NumToStr(z2,0), NewLine, NewLine,"mentre lo zig 3,1 e' ", NumToStr(z3,0));

if marketposition = 0 then // and isTheRightTime then
	begin
		//if z2 < z3 and z2 < z1 and z1 < z3 and // condizione massimi decrescenti
		if z1 < z2 and z1 < SwingPrice and SwingPrice < z2 and // condizione massimi decrescenti
		   L < z1 // mi assicuro che una volta passato z1 ovvero il punto 2 l'ordine rimanga a mercato
	              then begin
	                      //if printDebug and barstatus = 2 then print(NewLine," Punto 3 = SwingPrice alle ore ", time," e' ", NumToStr(swingPrice,2), NewLine, NewLine, " punto 2 = z[1,1] e' ",
				 //NumToStr(z1,2), NewLine, NewLine,"punto 1 = z[2,1] e' ", NumToStr(z2,2));
				
			       //if printDebug then print(NewLine," --Data ",FormatDate("dd-MM-yyyy", ELDateToDateTime(Date))," --Time ",NumToStr(time,0),"-------> SHORT at ", NumToStr(entryprice,2),NewLine);
				  //ShowEnterAt = Text_New(Date,Time,Close," Zig Short "); 
				  //Text_SetLocation(ShowEnterAt ,barnumber,time,H + VertOffset1);
				
			       sellshort ("Short Entry") 1 contract next bar at z1 - 1 * ticksize + RR * ticksize limit;
				//canEntry = false;
			end; 
			
		//if z2 > z3 and z2 > z1 and z1 > z3 and // condizione minimi crescenti
		if z1 > z2 and z1 > SwingPrice and SwingPrice > z2 and // condizione minimi crescenti
			H > z1 // mi assicuro che una volta passato z1 ovvero il punto 2 l'ordine rimanga a mercato
			
		       then begin
		       		
		             //if printDebug and barstatus = 2 then print(NewLine," Punto 3 = SwingPrice alle ore ", time," e' ", NumToStr(swingPrice,2), NewLine, NewLine, " punto 2 = z[1,1] e' ",
				// NumToStr(z1,2), NewLine, NewLine,"punto 1 = z[2,1] e' ", NumToStr(z2,2));
				//if printDebug then print(NewLine," --Data ",FormatDate("dd-MM-yyyy", ELDateToDateTime(Date))," --Time ",NumToStr(time,0),"-------> LONG at ", NumToStr(entryprice,2),NewLine);
				ShowEnterAt = Text_New(Date,Time,Close," Zig Long "); 
				  Text_SetLocation(ShowEnterAt ,date,time,L - VertOffset1);
				
				 

				buy ("Long Entry") 1 contract next bar at z1 + 1 * ticksize - RR  * ticksize limit;// 
				canPrint = true;


			end; 

	end;

setstoploss( stopPoints * bigpointvalue);
setprofittarget( targetPoints * bigpointvalue );
 	
	
if marketposition = 1 then begin

	//Sell("TargetLong") 1 contract Next Bar at (entryprice + TargetPoints) limit;
	//Sell("StopLong") 1 contract Next Bar at (entryprice - stopPoints) stop;
	if printDebug and canPrint and barstatus = 2 then print(NewLine," Punto 3 = SwingPrice alle ore ", time," e' ", NumToStr(swingPrice,2), NewLine, NewLine, " punto 2 = z[1,1] e' ",
				 NumToStr(z1,2), NewLine, NewLine,"punto 1 = z[2,1] e' ", NumToStr(z2,2));
				
	if time = Time_CLOSE_SESSION then sell("LE CLOSE SESSION") 1 contract next bar at market;
	canprint = false;

end;
	
if marketposition = -1 then begin

	//buytocover("TargetShort") 1 contract Next  Bar at (entryprice - TargetPoints) limit;
	//buytocover("StopShort") 1 contract Next Bar at (entryprice + stopPoints) stop;
	
	if time = Time_CLOSE_SESSION then buytocover("SE CLOSE SESSION") 1 contract next bar at market;

end;

Now just to give you an idea of MISSED ENTRY this is an example: (it should have gone long at 11940 but it didn't):



Any idea is appreciated

Thanks

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
45 thanks
Just another trading journal: PA, Wyckoff & Trends
31 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
  #2 (permalink)
Dvdkite
Trieste Italy
 
Posts: 162 since Feb 2018
Thanks Given: 131
Thanks Received: 25

Anyone had a chance to try the code?

I'm still working on it and I'm also facing problems in order to avoid 2 consecutive entries based on the same conditions....
I'm struggling to find a way to allow only ONE order when conditions are met...

Reply With Quote




Last Updated on May 20, 2019


© 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