I have the following issue. The attached strategy identifies the High/Low for a specific time period. Once the High is exceeded within the Session Close time, the signal is generated. Now this strategy only takes the current session into consideration. I also want to use the High/Low from yesterdays session. So the signal is only generated when the current and yesterday sessions high is exceeded by factor X. How can I add yesterdays Session High/Low? Can somebody help out?
Code: Select all
//Time HLRange Define
input:
Multiplier(1),Ratio(3),
StartTime( 900), // Time of start of channel
EndTime( 1000),
SessionCloseTime (1200),
EntrySizes (10000),
int NATR(9), // 5-60 STEP 5
double Fract(1.3); // 0.6 - 3.5 STEP 0.1 or 0.15
Vars:
PeriodHigh( 0 ), // Updated with period high during formation of channel
LastPeriodHigh( 0 ), // After channel completes stores PeriodHigh value before it is reset
PeriodLow( 999999 ), // Updated with period low during formation of channel
LastPeriodLow( 0 );
If T>= StartTime and T<=Endtime then
Begin
If H > PeriodHigh then PeriodHigh = H;
If L < PeriodLow then PeriodLow = L;
// Code below added for TL Example
if Time[1] < StartTime and Time >= StartTime then
Value1 = TL_New( Date, StartTime, PeriodHigh, Date, SessionCloseTime, PeriodHigh )
else if Value1 > 0 then
begin
TL_SetEnd( Value1, Date, SessionCloseTime, PeriodHigh ) ;
TL_SetBegin( Value1, Date, StartTime, PeriodHigh ) ;
end;
if Time[1] < StartTime and Time >= StartTime then
Value2 = TL_New( Date, StartTime, PeriodLow, Date, SessionCloseTime, PeriodLow )
else if Value2 > 0 then
begin
TL_SetEnd( Value2, Date, SessionCloseTime, PeriodLow ) ;
TL_SetBegin( Value2, Date, StartTime, PeriodLow ) ;
end ;
end ;
// Print(D,T," PeriodHigh ",PeriodHigh," PeriodLow ",PeriodLow );
If T > EndTime and T[1] <= EndTime then
Begin
Print( D, T, " PeriodHigh ", PeriodHigh," PeriodLow ", PeriodLow );
LastPeriodHigh = PeriodHigh;
LastPeriodLow = PeriodLow;
PeriodHigh = 0; // Reset PeriodHigh
PeriodLow =9999999; // Reset PeriodLow
End;
If time>Endtime and time< SessionCloseTime
and
marketposition=0 and EntriesToday(Date)<1
Then
begin
If Close >LastperiodHigh+(Fract * AvgTrueRange(NATR)) then
Buy EntrySizes/close contracts next bar at Market ;
end;
If marketposition=1 then begin
sell next bar at (entryprice-(Ratio*Multiplier*(LastPeriodHigh-LastPeriodLow) * BigPointValue)) stop; // StopLoss
sell next bar at (entryprice+(Multiplier*(LastPeriodHigh-LastPeriodLow) * BigPointValue)) limit; // take profit
end;
setexitonclose;