Hi All,
I am trying code an idea to show me if current symbol has 3 years of data but I am on struggle street.
Would someone be able to have a quick look and point me in the right direction please?
Thanks
Paul
+++++++++++++++++++++
{ // Indicator Name "Demo-Date" }
Inputs:
Lookback(3), { // Type = Integer }
Periodicity(0); { // Type = Integer }
Variables:
SFD(0), { // Type = Date }
MyDate(0), { // Type = Date }
OK2Trade(0); { // Type = Integer }
If Periodicity = 0 then DateType = Years
If Periodicity <> 0 then DateType = Months
{ // Symbol First Date is the first date record of the symbol}
{ // Chart Start Date = start date on the chart}
{ // Chart End Date = end date on the chart }
SFD = Symbol FirstDate;
MyDate = Date - Lookback (DateType);
{ //eg: Lookback = 3 }
{ //eg: Periodicity = years }
{ //eg: MyDate = Date - (3 years) }
Ok2Trade = 0;
If SymbolFirstDate <= MyDate then OK2Trade = 1;
If OK2Trade = 1 then Plot1(1,"Date OK");
If OK2Trade = 0 then begin
Plot2(0.333,"Date No1");
Plot3(-0.333,"Date No2");
End;
Help with date code [SOLVED]
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Help with date code
No problem, here's an example:I am trying code an idea to show me if current symbol has 3 years of data but I am on struggle street.
Would someone be able to have a quick look and point me in the right direction please?
Code: Select all
Variables:
firstDate(0), lastDate(0), numYears(0);
if (LastBarOnChart_s) then begin
firstDate = Symbol_DateTime[Symbol_CurrentBar - 1];
lastDate = Symbol_DateTime[0];
// Output for verification
Print("first date: ", FormatDate("d-M-yyyy", firstDate),
", last date: ", FormatDate("d-M-yyyy", lastDate));
// Calculate number of years
numYears = (lastDate - firstDate) / 365;
Print("Number of years: ", NumToStr(numYears, 5), NewLine, NewLine);
end;
The code generates the following output:
Code: Select all
first date: 19-11-2009, last date: 27-10-2015
Number of years: 5.93961
Re: Help with date code
Just wanted to say thank you for the heads up. I was going about it completely backwards
I have shared to code below in case anyone stumbles upon this in future
Thanks again.
Cheers
Paul
I have shared to code below in case anyone stumbles upon this in future
Thanks again.
Cheers
Paul
Code: Select all
{ // Indicator Name "Demo Date" }
Inputs:
Lookback(3); { // Type = Integer }
Variables:
SFD(0), { // Type = Date }
StartYear(0), { // Type = Integer }
BarsYear(0), { // Type = Integer }
YearRange(0); { // Type = Integer }
SFD = Symbol_DateTime[Symbol_CurrentBar - 1];
BarsYear = Year(Date);
StartYear = Year(SFD);
YearRange = BarsYear - StartYear;
If YearRange >= Lookback then Plot1(1,"Date OK");
If YearRange < Lookback then begin
Plot2(0.333,"Date No1");
Plot3(-0.333,"Date No2");
End;