OK

Apologies for clumsy example script, I've tidied it up with printfs to try to explain the logic.

With new code there are still buy stops not being hit when they should.

Code:
function run()
{

	set (TICKS);						
	set (PLOTNOW);						
	set (LOGFILE);						
	set (TESTNOW);						
	
 
	BarPeriod		= 60;			 
	BarOffset 		= (ET+17)*60;
	
	LookBack			= 100; 
	
	StartDate		= 20110101;
	EndDate			= 20110120;
	
	Hedge				= 2; 

	vars op			= series(priceOpen());
	vars cl			= series(priceClose());
	vars hi			= series(priceHigh());
	vars lo			= series(priceLow());
	vars wt			= series((hi[0]+lo[0]+cl[0]+cl[0])/4);
	
	Stoch(14,3,MAType_EMA,3,MAType_EMA);
	vars sto5K		= series(rSlowK);	
	vars sto5D		= series(rSlowD);
	
	vars signal		= series(0);

	Stop				= 40*PIP;
	TakeProfit		= 20*PIP;
	
	EntryTime		= 10;


	if ((sto5K[0] < 30) and (sto5K[0] > sto5K[1]))
		{
			signal[0] = 1;
			printf("\nStoch Signal Fired");
		}


	if (NumOpenLong < 1) // if open trade do not set pending
		{
			printf("\nNo Trade Open");
			
			// Set new pending trade if signal fires
			
			if (NumPendingLong < 1)
			{
					printf("\nNo Pending Trade");
				
				if (signal[0] > 0)
				{
					enterLong(0,hi[0]);
					plotGraph("Entry",0,hi[0]+5*PIP,MAIN|TRIANGLE4,PURPLE);
					printf("\nNo Pending Trade, Signal = %1.1f, placing new pending at %1.4f",signal[0],hi[0]);
				}
			}
			
			// If pending not hit check if signal valid
			
			else
			{
				printf("\nPending Trade not Hit hi[1] = %1.4f; hi[0] = %1.4f",hi[1],hi[0]);
				
				if (signal[0] > 0)
				{
					exitLong();
					enterLong(0,hi[0]);
					plotGraph("Entry2",0,hi[0]+5*PIP,MAIN|TRIANGLE4,GREEN);
					printf("\nSignal = %1.1f, exiting old trade placing new pending at %1.4f",signal[0],hi[0]);
				}
				else
				{
					if  (hi[0] < hi[1])
					{
						exitLong();
						enterLong(0,hi[0]);
						plotGraph("Entry3",0,hi[0]+5*PIP,MAIN|TRIANGLE4,YELLOW);
						printf("\nSignal = %1.1f, exiting old trade placing new pending at %1.4f",signal[0],hi[0]);
					}
				}
				
			}
				
			

		}
		
	else printf("\nTrade Open");	
	
	
	if (is(EXITRUN))
	{
		exitLong();
		exitShort();
	}

	
	
	plot("Sto 5,2,2 K",sto5K[0],NEW,RED);
	plot("Sto 5,2,2 D",sto5D[0],0,BLUE);
	plot("30",30,0,GREY);
	plot("70",70,0,GREY);
	

	

	PlotWidth		= 2400;
	PlotHeight1		= 800;

}



Log file extract for region in attached pic:

Code:
[105: Mon 10.01.11 00:00]  1.28963
No Trade Open
No Pending Trade
[106: Mon 10.01.11 01:00]  1.28969
Stoch Signal Fired
No Trade Open
No Pending Trade
(EUR/USD::L) Long 1@1.2907 Entry stop
No Pending Trade, Signal = 1.0, placing new pending at 1.2907
(EUR/USD::L) Entry stop 1.2907 hit at 01:00
[EUR/USD::L0701] Long 1@1.2907 Risk 3$ p at 01:00

[107: Mon 10.01.11 02:00]  0p 1/0
Stoch Signal Fired
Trade Open
[EUR/USD::L0701] Target 1@1.2927: +1.35 at 02:18

[108: Mon 10.01.11 03:00]  17p 1/0
Stoch Signal Fired
No Trade Open
No Pending Trade
(EUR/USD::L) Long 1@1.2931 Entry stop
No Pending Trade, Signal = 1.0, placing new pending at 1.2931

[109: Mon 10.01.11 04:00]  17p 1/0
No Trade Open
Pending Trade not Hit hi[1] = 1.2931; hi[0] = 1.2925
(EUR/USD::L) Missed entry 1.2931 at exit command
(EUR/USD::L) Long 1@1.2925 Entry stop
Signal = 0.0, exiting old trade placing new pending at 1.2925

[110: Mon 10.01.11 05:00]  17p 1/0
No Trade Open
Pending Trade not Hit hi[1] = 1.2925; hi[0] = 1.2912
(EUR/USD::L) Missed entry 1.2925 at exit command
(EUR/USD::L) Long 1@1.2912 Entry stop
Signal = 0.0, exiting old trade placing new pending at 1.2912

[111: Mon 10.01.11 06:00]  17p 1/0
No Trade Open
Pending Trade not Hit hi[1] = 1.2912; hi[0] = 1.2911
(EUR/USD::L) Missed entry 1.2912 at exit command
(EUR/USD::L) Long 1@1.2911 Entry stop
Signal = 0.0, exiting old trade placing new pending at 1.2911

[112: Mon 10.01.11 07:00]  17p 1/0
Stoch Signal Fired
No Trade Open
Pending Trade not Hit hi[1] = 1.2911; hi[0] = 1.2912
(EUR/USD::L) Missed entry 1.2911 at exit command
(EUR/USD::L) Long 1@1.2912 Entry stop
Signal = 1.0, exiting old trade placing new pending at 1.2912

[113: Mon 10.01.11 08:00]  17p 1/0
No Trade Open
Pending Trade not Hit hi[1] = 1.2912; hi[0] = 1.2921
[114: Mon 10.01.11 09:00]  17p 1/0
Stoch Signal Fired
No Trade Open
Pending Trade not Hit hi[1] = 1.2921; hi[0] = 1.2926
(EUR/USD::L) Missed entry 1.2912 at exit command
(EUR/USD::L) Long 1@1.2926 Entry stop
Signal = 1.0, exiting old trade placing new pending at 1.2926

[115: Mon 10.01.11 10:00]  17p 1/0
No Trade Open
Pending Trade not Hit hi[1] = 1.2926; hi[0] = 1.2916
(EUR/USD::L) Missed entry 1.2926 at exit command
(EUR/USD::L) Long 1@1.2916 Entry stop
Signal = 0.0, exiting old trade placing new pending at 1.2916
(EUR/USD::L) Entry stop 1.2916 hit at 10:00
[EUR/USD::L1602] Long 1@1.2916 Risk 3$ p at 10:00

[116: Mon 10.01.11 11:00]  17p 1/7
Trade Open
[EUR/USD::L1602] Target 1@1.2936: +1.30 at 11:14

[117: Mon 10.01.11 12:00]  34p 2/0
No Trade Open
No Pending Trade


Attached Files
zorro problem4.png (51 downloads)