Do you need to insert a time slot for a Tradestation or MultiCharts indicator or trading system? With StartTime and EndTime in EasyLanguage, it will be straightforward.
We create a simple indicator that draws a histogram within a given time session.
The code is straightforward:
Inputs: StartTime(2300), EndTime(1200); If Time > StartTime and Time < EndTime then Plot1(1); End;
We have received many emails because many users do not know how to solve the problem of a StartTime < EndTime.
For example, suppose we want to start a session from 22:00 to 12:00 in the next day.
In this case, our code would not work because StartTime is bigger than EndTime.
There are various ways to solve this problem; we have created this simple code:
Input: MA_length(20); vars: MA(0), color(white); MA = average(Close, MA_length); If MA>MA and MA>MA then color = Green; If MA<MA and MA<MA then color = Red; Plot1( MA, “MA”,color,0,3 );
What if we wanted to use this code to open positions or for something else?
You will need to create a handy true false function.
// EasyLanguage StartTime EndTime inputs: StartTime(numericsimple), EndTime(numericsimple); If StartTime > EndTime then Begin If (Time > StartTime and Time < 2359) or (Time >= 000 and Time < EndTime) then BoxTime=true Else BoxTime=False; End; If StartTime < EndTime then Begin If Time > StartTime and Time < EndTime then BoxTime=true Else BoxTime=False; End;
This function can be used both for an indicator and for a strategy.
Here’s how the indicator becomes simple using the function:
// EasyLanguage StartTime EndTime Inputs: StartTime(2300), EndTime(1200); If BoxTime(StartTime,EndTime) Then Plot1(1);
With this function we can, for example, create a strategy that buys and sells at a certain time.
We can use the function both as a filter to allow us to open new positions only in a certain period.
For example, we will write:
If RSI> 90 and BoxTime = True then ……
This function allows for endless uses. Remember that creating a special function is always the optimal choice.
The code of your indicator or strategy will remain cleaner and more understandable.
EasyLanguage Bar DateTime
BarDateTime is an EasyLangauge Reserved Word that references the DateTime object properties for a specific bar.
You can use all this FieldName:
Print(BarDateTime.Hour:4:0, ” “,BarDateTime.Minute:4:0, ” ” ) ;
More from Finance Strategy System
More resources Click Here
Why should you use the Hull Moving Average? This article shows you the pros and cons of this fantastic indicator and how to use it with graphical examples. There are many...
Download for free the MTF MACD MT4 indicator and learn how to use it. This fantastic indicator will show the trend of 4 different time frames. The MACD is an excellent trend...