San Jose
Posts: 1 since Dec 2020
Thanks Given: 1
Thanks Received: 0
|
{ Search Tag: WA-New High LE }
{
This strategy buys on a new high for the chart or for the specified calendar
period - day, week, month or year.
The IntrabarOrderGeneration attribute is set to false in this strategy because
strategy calculations depend on end-of-bar prices. Specifically, in this strategy
the end-of-bar high is used.
}
[IntrabarOrderGeneration = false]
inputs:
int PeriodType( 1 ) [DisplayName = "PeriodType", ToolTip =
"Enter the time period for which the code is looking for a new High. Enter 1 for chart, 2 for day, 3 for week, 4 for month, 5 for year."];
variables:
int BT( BarType ),
bool LastBarOfPeriod( false ),
{
HighestHi is initialized to a large positive value to ensure that if a
calendar period is specified, the first such period on the chart is ignored
because it may be incomplete
}
double HighestHi( 1000000 ),
bool IsDailyBarOrShorter( false ),
bool IsWeeklyBarOrShorter( false ),
bool IsMonthBarOrShorter( false ),
bool NextBarIsNewDay( false ),
bool NextBarIsNewWeek( false ),
bool NextBarIsNewMonth( false ),
bool NextBarIsNewYear( false );
if CurrentBar = 1 then
begin
IsDailyBarOrShorter = BT <= 2 or BT = 14;
IsWeeklyBarOrShorter = BT <= 3 or BT = 14;
IsMonthBarOrShorter = BT <= 4 or BT = 14;
end;
NextBarIsNewDay = Date <> Date next bar;
NextBarIsNewWeek = DayOfWeek( Date) > DayOfWeek( Date next bar );
NextBarIsNewMonth = Month( Date ) <> Month( Date next bar );
NextBarIsNewYear = Year( Date ) <> Year( Date next bar );
if ( PeriodType = 2 and IsDailyBarOrShorter and NextBarIsNewDay )
or ( PeriodType = 3 and IsWeeklyBarOrShorter and NextBarIsNewWeek )
or ( PeriodType = 4 and IsMonthBarOrShorter and NextBarIsNewMonth )
or ( PeriodType = 5 and IsMonthBarOrShorter and NextBarIsNewYear )
then
LastBarOfPeriod = true
else
LastBarOfPeriod = false;
if ( CurrentBar = 1 and ( PeriodType <= 1 or PeriodType > 5 ) )
or LastBarOfPeriod[1]
or High > HighestHi
then
HighestHi = High;
if LastBarOfPeriod = false then
Buy( !( "NewHi" ) ) next at bar at HighestHi + 1 point stop;
|