NexusFi: Find Your Edge


Home Menu

 





High/Low in Easy Language for Specific Time Frame


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one cnbcsucks with 7 posts (4 thanks)
    2. looks_two ABCTG with 3 posts (6 thanks)
    3. looks_3 MsTs with 1 posts (0 thanks)
    4. looks_4 Big Mike with 1 posts (0 thanks)
    1. trending_up 7,512 views
    2. thumb_up 12 thanks given
    3. group 4 followers
    1. forum 11 posts
    2. attach_file 4 attachments




 
Search this Thread

High/Low in Easy Language for Specific Time Frame

  #1 (permalink)
 cnbcsucks 
PDX, Oregon
 
Experience: Intermediate
Platform: NinjaTrader, Tradestation
Broker: Tradestation
Posts: 13 since Jan 2010
Thanks Given: 3
Thanks Received: 4

Hello Everyone,

Total EL newbie here and I'm trying to plot the high and low for a specific timeframe 8am - 9:30 for current day. This is what I have so far, but unable to get the EL code to plot for current day. This is what I have so far - compiles ok, but not getting it:

Variables:
PreMarketHigh (High),
PreMarketLow (Low);


If time > 0830 and time < 0930 then
begin

Plot1 ( Premarkethigh , "Premarkethigh" ) ;
Plot2 ( PreMarketLow, "PreMarketLow" ) ;
end;

Can someone correct me please? Many Thanks in advance!!

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Deepmoney LLM
Elite Quantitative GenAI/LLM
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
Battlestations: Show us your trading desks!
26 thanks
The Program
18 thanks
  #2 (permalink)
greggotanafro
Dallas + Texas
 
Posts: 4 since Apr 2020
Thanks Given: 2
Thanks Received: 1

I did this:

 
Code
inputs:
PreMarketHigh (High of data1),
PreMarketLow (Low of data1);


If time > 0830 and time < 0930 then
begin

Plot1 ( Premarkethigh , "Premarkethigh" ) ;
Plot2 ( PreMarketLow, "PreMarketLow" ) ;
end;
Essentially changing VARIABLES to INPUTS, hard coding the Data stream, changing my chart window to 15 mins, and changing the style of the plot from line to dot plotted it correctly

Still a little confused about the time function and how it iterates by default within ES so I'll be following this thread for that. (ex. if you add PRINT(TIME) within that IF statement, what tf is it actually doing?)

Reply With Quote
Thanked by:
  #3 (permalink)
 cnbcsucks 
PDX, Oregon
 
Experience: Intermediate
Platform: NinjaTrader, Tradestation
Broker: Tradestation
Posts: 13 since Jan 2010
Thanks Given: 3
Thanks Received: 4


Thanks for the quick reply. This is what I"m trying to get - the high and low for premarket open for SPY (0500 - 0630) local time here (pacific) - for Current day.
spy

Started this thread Reply With Quote
Thanked by:
  #4 (permalink)
MsTs
Tunisia Tunis
 
Posts: 5 since Mar 2020
Thanks Given: 0
Thanks Received: 2

[

Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

cnbcsucks,

you need to keep track of the high and low within your code. Just initializing a variable with a value once on declaration will not update it further.
Something along the lines of the below should get you going:

 
Code
Variables:
bool doReset		( false ),
double preMarketHigh 	( -999999 ),
double preMarketLow 	( +999999 );

if Date <> Date[1] then //set flag on date change
   doReset = true ;

If time > 0830 and time < 0930 then
begin
	//reset the tracking values at the beginning of bracket
	if doReset then
	begin 
                doReset = false ;
  		preMarketHigh = High ;
  		preMarketLow = Low ;
        End ; 
	
	//keep track of higher highs and lower lows
	If High > preMarketHigh then
		preMarketHigh = High ;
		
	If Low < preMarketLow then
		preMarketLow = Low ;
End ;

If preMarketHigh <> -999999 then  
	Plot1( preMarketHigh , "Premarkethigh" ) ;
If preMarketLow <> +999999 then	
	Plot2( preMarketLow, "PreMarketLow" ) ;
Regards,

ABCTG



cnbcsucks View Post
Hello Everyone,

Total EL newbie here and I'm trying to plot the high and low for a specific timeframe 8am - 9:30 for current day. This is what I have so far, but unable to get the EL code to plot for current day. This is what I have so far - compiles ok, but not getting it:

Variables:
PreMarketHigh (High),
PreMarketLow (Low);


If time > 0830 and time < 0930 then
begin

Plot1 ( Premarkethigh , "Premarkethigh" ) ;
Plot2 ( PreMarketLow, "PreMarketLow" ) ;
end;

Can someone correct me please? Many Thanks in advance!!


Follow me on Twitter Reply With Quote
  #6 (permalink)
 cnbcsucks 
PDX, Oregon
 
Experience: Intermediate
Platform: NinjaTrader, Tradestation
Broker: Tradestation
Posts: 13 since Jan 2010
Thanks Given: 3
Thanks Received: 4

ABCTG, Thank you for replying. I tried the EL code on a 5 minute chart for SPY. Is it a formatting issue or is the code plotting highs/lows on each 5 minute bar from 5 - 6:30am? Please see posted chart. Possible to plot the low and high across the entire 5 - 6:30am pre-market window as drawn manually on chart with white line?
spy

Started this thread Reply With Quote
  #7 (permalink)
 cnbcsucks 
PDX, Oregon
 
Experience: Intermediate
Platform: NinjaTrader, Tradestation
Broker: Tradestation
Posts: 13 since Jan 2010
Thanks Given: 3
Thanks Received: 4

Thanks Greggotanafro. This plots each 5 minute or 15 minute bar high and lo. I'm looking the for the high and low for 5 - 6:30 premarket pacific time. Please see attached chart with the EL code applied. I manually drew the white line to illustrate what I'm trying to get.

Big thanks for supplying the EL code. :-)



greggotanafro View Post
I did this:

 
Code
inputs:
PreMarketHigh (High of data1),
PreMarketLow (Low of data1);


If time > 0830 and time < 0930 then
begin

Plot1 ( Premarkethigh , "Premarkethigh" ) ;
Plot2 ( PreMarketLow, "PreMarketLow" ) ;
end;
Essentially changing VARIABLES to INPUTS, hard coding the Data stream, changing my chart window to 15 mins, and changing the style of the plot from line to dot plotted it correctly

Still a little confused about the time function and how it iterates by default within ES so I'll be following this thread for that. (ex. if you add PRINT(TIME) within that IF statement, what tf is it actually doing?)


spy

Started this thread Reply With Quote
  #8 (permalink)
 cnbcsucks 
PDX, Oregon
 
Experience: Intermediate
Platform: NinjaTrader, Tradestation
Broker: Tradestation
Posts: 13 since Jan 2010
Thanks Given: 3
Thanks Received: 4

Browsing through the builtin indicators, I think I found what works. Indicator 'Subsession OHLC' does the trick. You can set timeframes and select what you want to see OHL or Close for any time frame. Very helpful for first hour trading SPY and other Equities.

Please see chart. A big thanks to everyone for helping out.


spy


EL Code:

{ Search Tag: WA-Subsession OHLC }

{
This indicator is designed to plot the period open, high, low and close for a time
period set by the "StartTime_HHMMSS" and "EndTime_HHMMSS" inputs. As noted below
in the input tooltips, the format for entering time is HH:MM:SS, in 24-hour
military format. For example, to enter 10:21:02 PM in one of the time inputs,
enter 22:21:02.

This indicator can be used to plot an opening range by setting the times to the
desired opening range. For the current day opening range, set "NumSubSessionsAgo"
input to 0, which is the "current" OHLC values.

The OHLCV calculations are reset when the new time period starts as evaluated
by the "ResetCalcs" calculations in the code. When "ResetCalcs" evaluates to true,
the calculations are reset to start tracking new Open, High, Low, and Close values.

This indicator is intended for application only to intraday bars (tick or time-
based) and works in Charting and RadarScreen.

Inputs allow control of:
1) Colors for the plots and associated text labels. Colors are controlled
by inputs to ensure the plot colors and text labels use the same colors.
2) The font size of the text labels using the "TextLabelFontSize" input.
3) Showing or not showing of plots.
4) Showing or not showing of text labels.

Commentary on the use of vectors for OHLCV, along with calculation explanations,
can be found in the "OHLCVCollection" function.
}

using elsystem;
using elsystem.collections;
using elsystem.drawingobjects;
using elsystem.drawing;

inputs:
int NumSubSessionsAgo( 1 ) [
DisplayName = "NumSubSessionsAgo",
ToolTip = "Number of Subsessions Ago. Enter the number of sub-sessions ago to plot the Open, High, Low and Close."],

string StartTime_HHMMSS( "09:30:00" ) [
DisplayName = "StartTime_HHMMSS",
ToolTip = "Enter subsession starting 24-hr time as a string of HH:MM:SS"],

string EndTime_HHMMSS( "16:00:00" ) [
DisplayName = "EndTime_HHMMSS",
ToolTip = "Enter subsession ending 24-hr time as a string of HH:MM:SS"],

int ShowOpen( 1 ) [
DisplayName = "ShowOpen",
ToolTip = "Enter 1 to show Open line"],

int ShowHigh( 1 ) [
DisplayName = "ShowHigh",
ToolTip = "Enter 1 to show High line"],

int ShowLow( 1 ) [
DisplayName = "ShowLow",
ToolTip = "Enter 1 to show Low line"],

int ShowClose( 1 ) [
DisplayName = "ShowClose",
ToolTip = "Enter 1 to show Close line"],

int OpenColor( Red ) [
DisplayName = "OpenColor",
ToolTip = "Enter color for the Open line and its associated text label"],

int HighColor( Magenta )[
DisplayName = "HighColor",
ToolTip = "Enter color for the High line and its associated text label"],

int LowColor( Yellow ) [
DisplayName = "LowColor",
ToolTip = "Enter color for the Low line and its associated text label"],

int CloseColor( Cyan ) [
DisplayName = "CloseColor",
ToolTip = "Enter color for the Close line and its associated text label"],

int ShowTextLabels( 1 ) [
DisplayName = "ShowTextLabels",
ToolTip = "Enter 1 to show text labels on the lines"],

double TextLabelFontSize( 8.0 ) [
DisplayName = "TextLabelFontSize",
ToolTip = "Enter the font size for the text labels on the lines"];

variables:
intrabarpersist bool InAChart( false ),
intrabarpersist bool FontSizeOkay( false ),
{ OHLCV_Vector will be passed by reference to the function OHLCVCollection;
it will hold all the OHLCV values }
Vector OHLCV_Vector( NULL ),
Vector HighVector( NULL ),
Vector LowVector( NULL ),
Vector OpenVector( NULL ),
Vector CloseVector( NULL ),
bool ResetCalcs( false ),
bool IncludeThisBar( false ),
intrabarpersist int NumberOfDecimals( 0 ),
{ variable to hold the value returned by call to OHLCVCollection function }
int ReturnValueOrErrorCode( 0 ),
{ used to ensure that there is enough data in the vector before requesting a
value }
intrabarpersist bool ValuesAvailable( false ),
double SubSessionOpen( -1 ), { holds Open of NumSubSessionsAgo }
double SubSessionHigh( -1 ), { holds High of NumSubSessionsAgo }
double SubSessionLow( -1 ), { holds Low of NumSubSessionsAgo }
double SubSessionClose( -1 ), { holds Close of NumSubSessionsAgo }
TimeSpan StartTimeTS( NULL ), { TimeSpan for start time }
TimeSpan EndTimeTS( NULL ), { TimeSpan for end time }
string ErrorMessage( "" ),
TextLabel OpenTextLabel( NULL ),
TextLabel HighTextLabel( NULL ),
TextLabel LowTextLabel( NULL ),
TextLabel CloseTextLabel( NULL );

{ create TimeSpan objects for start and end times }
method string CreateStartandEndTimeSpan()
variables: datetime tempDateTime, string ErrorString;
begin
ErrorString = "";

if DateTime.TryParse( StartTime_HHMMSS, tempDateTime ) then
StartTimeTS = TimeSpan.Create( tempDateTime.Hour,
tempDateTime.Minute, tempDateTime.Second )
else
{ the start time could not be parsed; set error message }
ErrorString = !( "StartTime_HHMMSS invalid value or format. Enter subsession starting 24-hr time as a string of HH:MM:SS." );

if DateTime.TryParse( EndTime_HHMMSS, tempDateTime ) then
EndTimeTS = TimeSpan.Create( tempDateTime.Hour,
tempDateTime.Minute, tempDateTime.Second )
else
{ the end time could not be parsed; set error message }
ErrorString = !( "EndTime_HHMMSS invalid value or format. Enter subsession ending 24-hr time as a string of HH:MM:SS." );

return ErrorString;
end;

method void CreateVectors()
begin
OHLCV_Vector = new Vector;
HighVector = new Vector;
LowVector = new Vector;
OpenVector = new Vector;
CloseVector = new Vector;
end;

method TextLabel CreateTextLabel( string PriceField, double pPrice )
variables: TextLabel varTextLabel;
begin
{ create a text label positioned on the current bar }
varTextLabel = TextLabel.Create( DTPoint.Create( BarDateTime, pPrice ), "" );
{
setting 'Persist' to false causes the text label to be deleted on an
intrabar tick. This method is called on every tick when the calculations
are reset, so Persist is set to false to prevent creating and retaining in
the drawingobjects collection a new text label on every tick. When set
to false, a text label that is created on the closing tick of the bar
is saved/retained.
}
varTextLabel.Persist = false;
varTextLabel.Lock = true; { prevent inadvertent movement with the mouse }
varTextLabel.TextString = !( PriceField.ToUpper() ) + ": " +
NumToStr( pPrice, NumberOfDecimals );
varTextLabel.HStyle = HorizontalStyle.Left;
varTextLabel.Font = Font.Create( varTextLabel.Font.Name, TextLabelFontSize );
{
set the vertical style of the text label; some overlapping of text labels
may occur depending on the price levels; code logic can be added to prevent
overlapping, if desired, but can get fairly complex
}
varTextLabel.VStyle = VerticalStyle.Bottom;

{ set the TextLabel color to match the plot color }
switch ( PriceField.ToUpper() )
begin
case "O": { Open }
varTextLabel.Color = GetColorFromInteger( 255, OpenColor );
case "H": { High }
varTextLabel.Color = GetColorFromInteger( 255, HighColor );
{ set vertical style to 'Top' so that it is visible when near
the top of the screen when the plot is visible }
varTextLabel.VStyle = VerticalStyle.Top;
case "L": { Low }
varTextLabel.Color = GetColorFromInteger( 255, LowColor );
case "C": { Close }
varTextLabel.Color = GetColorFromInteger( 255, CloseColor );
end;

{
this is how the text label is "shown"; the text label is added to the
DrawingObjects collection; if you want to remove the text label, you can
use the Delete method of the DrawingObjects class; DrawingObjects collection
is not available in RadarScreen (it is NULL), so we only add the TextLabel
to the collection if in a chart
}
if InAChart then
DrawingObjects.Add( varTextLabel );

return varTextLabel;
end;

{ convert integer color to color object and return the color object }
method Color GetColorFromInteger( int Alpha, int ColorInteger )
begin
return Color.FromARGB( Alpha, GetRValue( ColorInteger ),
GetGValue( ColorInteger ), GetBValue( ColorInteger ) );
end;

once
begin
if BarType >= 2 and BarType <> 14 then
throw Exception.Create( !( "Subsession OHLC can be applied to intraday bars only." ) );

{ if all of the inputs that control plotting are set to 0, display a message
to that effect }
if ShowOpen <> 1 and ShowHigh <> 1 and ShowLow <> 1 and ShowClose <>1 then
begin
Value1 = InfoBox( !( "No plot lines were drawn. All of the inputs that control plots are set to 0." ),
!( "Message" ), 50, 50 );
end;

{ it is assumed that if the TextLabelFontSize is set to a value <= 0, the user
does not want text labels displayed }
FontSizeOkay = TextLabelFontSize > 0;
InAChart = GetAppInfo( aiApplicationType ) = cChart;
NumberOfDecimals = NumDecimals( PriceScale );
CreateVectors();

{ calculate TimeSpans for start and end times }
ErrorMessage = CreateStartandEndTimeSpan();

{ throw runtime error if start time and/or end time are not entered correctly }
if ErrorMessage <> "" then
throw Exception.Create( ErrorMessage );
end;

{ condition upon which OHLC values will be reset for next period }
ResetCalcs =
( BarDateTime.TimeOfDay > StartTimeTS and BarDateTime[1].TimeOfDay <= StartTimeTS )
or
( BarDateTime.TimeOfDay > StartTimeTS and BarDateTime[1].TimeOfDay > BarDateTime.TimeOfDay )
or
( BarDateTime[1].TimeOfDay > BarDateTime.TimeOfDay and StartTimeTS > BarDateTime[1].TimeOfDay );

{
IncludeThisBar is passed in to OHLCVCollection to designate whether this bar is to
be used in the OHLCV calcultions. This variable is true if the bar falls within the
time frame established by the StartTime and EndTime inputs and false if the bar is
outside the time frame.
}
if StartTimeTS > EndTimeTS then
IncludeThisBar = BarDateTime.TimeOfDay > StartTimeTS or
BarDateTime.TimeOfDay <= EndTimeTS
else
IncludeThisBar = BarDateTime.TimeOfDay > StartTimeTS and
BarDateTime.TimeOfDay <= EndTimeTS;


ReturnValueOrErrorCode = OHLCVCollection( ResetCalcs, IncludeThisBar,
OHLCV_Vector );

{ set up OpenVector, HighVector, LowVector and CloseVector }
once
begin
OpenVector = OHLCV_Vector[0] astype Vector; { [0] = Open Price }
HighVector = OHLCV_Vector[1] astype Vector; { [1] = High Price }
LowVector = OHLCV_Vector[2] astype Vector; { [2] = Low Price }
CloseVector = OHLCV_Vector[3] astype Vector; { [3] = Close Price }
end;

{ only allow retrieval of data once there is enough data loaded into the vector }
once ( ReturnValueOrErrorCode > NumSubSessionsAgo )
begin
ValuesAvailable = true;
end;

if ValuesAvailable then { valid values are availabe; okay to plot }
begin
SubSessionOpen = OpenVector.At( NumSubSessionsAgo ) astype double;
SubSessionHigh = HighVector.At( NumSubSessionsAgo ) astype double;
SubSessionLow = LowVector.At( NumSubSessionsAgo ) astype double;
SubSessionClose = CloseVector.At( NumSubSessionsAgo ) astype double;

if ShowOpen = 1 then
Plot1( SubSessionOpen, !( "SubSessOpen" ), OpenColor );
if ShowHigh = 1 then
Plot2( SubSessionHigh, !( "SubSessHigh" ), HighColor );
if ShowLow = 1 then
Plot3( SubSessionLow, !( "SubSessLow" ), LowColor );
if ShowClose = 1 then
Plot4( SubSessionClose, !( "SubSessClose" ), CloseColor );
end
else if LastBarOnChartEx then
begin
throw Exception.Create( !( "OHLC not available for requested session. Try loading more historical data or increasing 'load additional bars' setting." ) );
end;

if ValuesAvailable and ResetCalcs then
begin
{ set plot colors to transparent for the prior bar to eliminate connectors from
prior sub-session }
SetPlotColor[1]( 1, Transparent );
SetPlotColor[1]( 2, Transparent );
SetPlotColor[1]( 3, Transparent );
SetPlotColor[1]( 4, Transparent );

{
create text labels for the plots if in Charting; it is assumed that if the
TextLabelFontSize is set to a value <= 0 (in which case, FontSizeOkay is set
to false), the user does not want text labels displayed
}
if InAChart and FontSizeOkay and ShowTextLabels = 1 then
begin
if ShowOpen = 1 then
OpenTextLabel = CreateTextLabel( "O", SubSessionOpen );
if ShowHigh = 1 then
HighTextLabel = CreateTextLabel( "H", SubSessionHigh );
if ShowLow = 1 then
LowTextLabel = CreateTextLabel( "L", SubSessionLow );
if ShowClose = 1 then
CloseTextLabel = CreateTextLabel( "C", SubSessionClose );
end;
end;

{
if plotting the current period OHLC (NumSubSessionsAgo = 0) values, the text
labels need to be moved as the values are updated on each bar that is used to
determine the OHLC values and the text labels need to be updated with the
current price values
}
if InAChart { only show text objects in a chart }
and FontSizeOkay
and ShowTextLabels = 1
and NumSubSessionsAgo = 0
and ValuesAvailable
and IncludeThisBar then
begin
if ShowOpen = 1 and OpenTextLabel <> NULL then
begin
OpenTextLabel.SetPointValue( DTPoint.Create( BarDateTime,
SubSessionOpen ) );
OpenTextLabel.TextString = !( "O" ) + ": " + NumToStr( SubSessionOpen,
NumberOfDecimals );
end;

if ShowHigh = 1 and HighTextLabel <> NULL then
begin
HighTextLabel.SetPointValue( DTPoint.Create( BarDateTime,
SubSessionHigh ) );
HighTextLabel.TextString = !( "H" ) + ": " + NumToStr( SubSessionHigh,
NumberOfDecimals );
end;

if ShowLow = 1 and LowTextLabel <> NULL then
begin
LowTextLabel.SetPointValue( DTPoint.Create( BarDateTime, SubSessionLow ) );
LowTextLabel.TextString = !( "L" ) + ": " + NumToStr( SubSessionLow,
NumberOfDecimals );
end;

if ShowClose = 1 and CloseTextLabel <> NULL then
begin
CloseTextLabel.SetPointValue( DTPoint.Create( BarDateTime,
SubSessionClose ) );
CloseTextLabel.TextString = !( "C" ) + ": " + NumToStr( SubSessionClose,
NumberOfDecimals );
end;
end;


{ ** Copyright © TradeStation Technologies, Inc. All Rights Reserved **
** TradeStation reserves the right to modify or overwrite this analysis technique
with each release. ** }
spy


spy

Started this thread Reply With Quote
Thanked by:
  #9 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,396 since Jun 2009
Thanks Given: 33,172
Thanks Received: 101,534

Just a note, please wrap code in the [code] bbcode so it's displayed better.

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #10 (permalink)
 cnbcsucks 
PDX, Oregon
 
Experience: Intermediate
Platform: NinjaTrader, Tradestation
Broker: Tradestation
Posts: 13 since Jan 2010
Thanks Given: 3
Thanks Received: 4


Will do BigMike :-)

Started this thread Reply With Quote
Thanked by:




Last Updated on April 24, 2020


© 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