Start "painting" indicator from specific date

Is there a way to tell an indicator to start "painting" from a specific date?

I'm calculating the Drawdown as an indicator, and I would like to be able to indicate the date from which to start counting and start "painting" the line. But from this date should be start at 0 the MaxDD, but I don't get that behavior

WhatsApp Image 2021-08-18 at 13.38.15

_SECTION_BEGIN("Drawdown From Date");

System_MaxEQ = Highest( C ); 
Sys_DD = 100 * ( C - System_MaxEQ ) / System_MaxEQ; 

startDate = ParamDate( "Start Date", "2019-01-01" );
dt = DateTime();
barsince = BarsSince(dt <= startDate);
barsToCount = IIf(IsNull(barsince), Cum(1), barsince);
Sys_DATEMaxDD = LLV(Sys_DD,barsToCount);

dn = DateNum();
SysDD_perDate = IIf(dn>=startDate, Sys_DATEMaxDD, Null);
 
Plot(SysDD_perDate,"Sys_DATEMaxDD",colorOrange,styleLine + styleThick);


_SECTION_END();

Is it possible?

Thank you very

ParamDate function has 3rd argument where you can choose the output option.
If you insert value 2 then it returns type datetime.

_SECTION_BEGIN("Drawdown From Date");
dt = DateTime();
startDate = ParamDate( "Start Date", "2019-01-01", 2 );

System_MaxEQ = Highest( C ); 
DD = 100 * ( C - System_MaxEQ ) / System_MaxEQ;
Sys_DD = IIf(dt>=startDate, DD, 100); 
Sys_DATEMaxDD = Lowest(Sys_DD);
SysDD_perDate = IIf(dt>=startDate, Sys_DATEMaxDD, Null);
 
Plot(SysDD_perDate,"Sys_DATEMaxDD",colorOrange,styleLine + styleThick);
_SECTION_END();
1 Like

WhatsApp Image 2021-08-19 at 08.11146.37

Thanks, the code looks cleaner, but it still shows the same behavior, when I draw the drawndown from a date I would like to force the 0 from that start forward.

Is this possible?

Yes, of course it is.

_SECTION_BEGIN("Drawdown From Date");
dt = DateTime();

startDate = ParamDate( "Start Date", "2019-01-01", 2 );

dt_cond = dt>=startDate;
spc = SparseCompress(dt_cond, C);
System_MaxEQ = Highest( spc ); 
DD = 100 * ( spc - System_MaxEQ ) / System_MaxEQ;
Sys_DATEMaxDD = Lowest(DD);
SysDD_perDate = SparseExpand(dt_cond, Sys_DATEMaxDD);

Plot(SysDD_perDate,"Sys_DATEMaxDD",colorOrange,styleLine + styleThick);

_SECTION_END();

26

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.