How to input DateTime variable  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

How to input DateTime variable

Postby mirek » 08 Feb 2013

Hi all,

I would like to use time variable for start and end of calculation (STime, ETime). Can someone point me to the example in MC.NET?

I want to compare variable later with Bar.Time.

Thank you
mirek
EL format of variable was STime=0930.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: How to input DateTime variable

Postby Henry MultiСharts » 08 Feb 2013

Hello mirek,

You need to set the time through input and then use DateTime.Parse Method

mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

Re: How to input DateTime variable  [SOLVED]

Postby mirek » 08 Feb 2013

Hi Henry,

thank you for the quick response and pointing me to the right direction. I am just posting code to help someone else if he needs it.

If you have any comments just let me know.

mirek

Code: Select all

public _myInd(object _ctx):base(_ctx)
{
STime = "09:30";
}

[Input]
public string STime { get; set; }

private IPlotObject plot1;

protected override void Create() {
// create variable objects, function objects, plot objects etc.
plot1 = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Cyan));
}
protected override void StartCalc() {
// assign inputs
}
protected override void CalcBar(){
// indicator logic
DateTime mySTime;

mySTime = DateTime.Parse(STime);

if (Bars.Time[0] == mySTime)
....

SSS
Posts: 14
Joined: 01 Apr 2013
Has thanked: 10 times
Been thanked: 2 times

Plotting/Drawing "forward in time" or extending ETextStyleH

Postby SSS » 22 Apr 2013

Hello.

My indicator uses an ITextObject which has a border (myTextObject.Border = true), and it is anchored to the right of the current bar (myTextObject.HStyle = ETextStyleH.Right); but the border always seems to obscure the current bar, especially if I'm using OHLC bars.

Is there a way I can make the ITextObject draw at a time coordinate which is in the future? At present, I'm making it appear next to the current bar using something like:

Code: Select all

myTextObject.Location = new ChartPoint(Bars.Time[0], Bars.High[0])
However, I want it to appear further away to the right, as if locating it two or three bars into the future.

In PowerLanguage, I believe this is not possible; but a workaround was created by TS users which used the following functions:

AddTime:

Code: Select all

[LegacyColorValue = true];

{ User Function: AddTime
Inputs : xTime - time in 24 hour format.
Minutes - amount to add/subtract to xTime.
Sample Usage :
if (Time[0] > AddTime (Sess1StartTime, +30))
then ...
Returns: Adjusted time in 24 hour format.
}
Inputs : xTime (NumericSimple),
Minutes (NumericSimple) ;

AddTime = MinutesToTime (TimeToMinutes (xTime) + Minutes) ;
MinutesToTime:

Code: Select all

inputs: Minutes( numericsimple ) ;
variables: var0( 0 ), var1( 1 / 60 ), var2( 0 ) ;
var0 = IntPortion( Minutes * var1 ) ;
var2 = Minutes - 60 * var0 ;
MinutesToTime = 100 * Mod( var0, 24 ) + var2 ;
TimeToMinutes:

Code: Select all

inputs: XTime( numericsimple ) ;
Value1 = XTime * .01 ;
TimeToMinutes = 60 * IntPortion( Value1 ) + 100 * FracPortion( Value1 ) ;
Can something similar be created in MC .NET? If so, please point me in the right direction (for example DateTime?).

Alternatively, is it easy to extend ETextStyleH so that, instead of taking .Left, .Right, and .Centre as properties, it accepts other arguments like ".Right + myOffset"? or ".Left + myOffset"?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Plotting/Drawing "forward in time" or extending ETextSty

Postby Henry MultiСharts » 22 Apr 2013

Hello.

My indicator uses an ITextObject which has a border (myTextObject.Border = true), and it is anchored to the right of the current bar (myTextObject.HStyle = ETextStyleH.Right); but the border always seems to obscure the current bar, especially if I'm using OHLC bars.

Is there a way I can make the ITextObject draw at a time coordinate which is in the future? At present, I'm making it appear next to the current bar using something like:

Code: Select all

myTextObject.Location = new ChartPoint(Bars.Time[0], Bars.High[0])
Hello SSS,

You can offset the bars to the right by assigning the time value from the future with the help of AddMinutes or AddSeconds (depending on your chart resolution) methods of DateTime structure:

Code: Select all

Bars.Time[0].AddMinutes(5);

SSS
Posts: 14
Joined: 01 Apr 2013
Has thanked: 10 times
Been thanked: 2 times

Re: Plotting/Drawing "forward in time" or extending ETextSty

Postby SSS » 22 Apr 2013

Hello SSS,

You can offset the bars to the right by assigning the time value from the future with the help of AddMinutes or AddSeconds (depending on your chart resolution) methods of DateTime structure:

Code: Select all

Bars.Time[0].AddMinutes(5);
Thanks. You guys are great!

Dru
Posts: 107
Joined: 28 Aug 2007
Has thanked: 4 times
Been thanked: 171 times

Re: How to input DateTime variable

Postby Dru » 23 Apr 2013

I would like to use time variable for start and end of calculation (STime, ETime). Can someone point me to the example in MC.NET?
I want to compare variable later with Bar.Time.

Code: Select all

[Input]
public DateTime StartTime{get;set;}


Return to “MultiCharts .NET”