Breakout Session Strategy

Questions about MultiCharts and user contributed studies.
Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Breakout Session Strategy

Postby Jonny473 » 29 Dec 2022

Hi,

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;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Breakout Session Strategy

Postby TJ » 29 Dec 2022

you can use the HighD function.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Breakout Session Strategy

Postby TJ » 29 Dec 2022

HighD (Function)

The HighD series function allows you to reference the daily high of a previous day in an intraday chart (minute, second, or tick-based) or a daily chart. HighD is one of a family of functions that allows historical references across various data intervals.

Syntax
HighD(PeriodsAgo)

Returns (Double)
The daily high price from a specified number of days ago. If there is not enough data, the function will return –1.

Parameters
Sets the number of days/periods back to reference a previous day’s high price. (0 = Today’s current high)

Remarks
You must have enough intraday data in the chart in order to look back and reference any previous daily high. For example, if you want to look back at the high of 25 days ago on a 5-minute chart, you must have at least 26 full days of 5-minute bars in the chart.

The value for the PeriodsAgo input parameter should always be a whole number greater than or equal to 0. Setting PeriodsAgo to 0 returns today’s current high.

This function considers the transition between one day and the next to occur at midnight, when the date changes. If you're using a symbol that trades overnight and would prefer to use the end of a session to transition to a new "day," consider using the HighSession function.

If you're calling this function in a study that will be applied to RadarScreen, be sure to set the "Load additional bars" setting. This setting should be set so as to ensure that it exceeds the number of intra-day bars in the PeriodsAgo. For example, if your code looks back 5 days (that is, PeriodsAgo is set to 5), then at least 6 days of intra-day bars should be loaded using the "Load additional bars" setting. On hourly bars for a symbol that trades 24 hours a day, this would be approximately 144 bars (6 x 24). For more detail on the "Load additional bars" setting, see Customize Study Properties.

Example
In order to place a short limit order at the High of the previous day you would write:

SellShort Next Bar at HighD(1) Limit;



See Also
LowD, CloseD, OpenD, HighW, HighM, and HighY.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Breakout Session Strategy

Postby Jonny473 » 30 Dec 2022

Hi TJ thanks for the response. But doesnt the HighD function use the High of the whole day? In my case I want the High of a specified time intervall which was defined with StartTime( 900), // Time of start of channel, EndTime( 1000) and SessionCloseTime (1200).

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Breakout Session Strategy

Postby Jonny473 » 04 Jan 2023

Does my reply make sense? I still cant figure it out...

ScottishSpeculator
Posts: 47
Joined: 03 Jan 2023
Been thanked: 3 times

Re: Breakout Session Strategy

Postby ScottishSpeculator » 05 Jan 2023

Hello I am new to EL and multicharts but just purchased the lifetime pass to give my trading a go on algo. Was reading your post and thought perhaps you could create a indicator for the previous high within your time window . Probably the way I will try and create a breakout strategy. Then you could reference the indicator in a strategy .

Maybe the code below is nonsense I hope not

Inputs:
StartTime (8),
EndTime (10);

Variables:
High8to10 (0),
PreviousHigh8to10 (0);

PreviousHigh8to10 = Highest(High, (StartTime * 60) * 60, (EndTime * 60) * 60)[1];

If Time = StartTime * 60 Then
High8to10 = PreviousHigh8to10;

Plot1(High8to10);

ScottishSpeculator
Posts: 47
Joined: 03 Jan 2023
Been thanked: 3 times

Re: Breakout Session Strategy

Postby ScottishSpeculator » 05 Jan 2023

or maybe something like a count function. Not sure..

Inputs:
StartTime(0900),
EndTime(1600);

Variables:
HighDuringPeriod(0),
i(0);

for i = 0 to BarCount-1 do
begin
if Time >= StartTime and Time <= EndTime then
if High > HighDuringPeriod then
HighDuringPeriod = High;
end;

Plot1(HighDuringPeriod);


Return to “MultiCharts”