Profit/stoploss lines based on date

#1
Hi folks,
Im looking for some help!
Here is a afl code, which plots nicely stop and profit levels based on the day you clicked.
This makes it easy to study trades visually.

_SECTION_BEGIN("__pricechart with automatic lines");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
PlotOHLC( O, H, L, C, "" , colorWhite, styleCandle);

// ******** CHARTING
STOPLOSS = 2.0;
PROFIT = 3.5;
EPT1= 1.5;
EPT2= 2.0;
EPT3= 2.5;
EPT4= 3.0;

mystartbar = SelectedValue(BarIndex()); // FOR GRAPHING
mystartbardate = LastValue(ValueWhen(mystartbar == BarIndex(),DateNum(),1));

InitialValue = LastValue(ValueWhen(mystartbardate == DateNum(), O , 1 ) ) ;

Temp1 = IIf(BarIndex() >= mystartbar, InitialValue, Null) ;

Verline = DateNum() == ParamDate("Date", "01/11/2011", 0);
LinesLONG = ParamToggle("Show lines LONG ","No|Yes",0);
LinesSHORT = ParamToggle("Show lines SHORT ","No|Yes",0);

if (LinesLONG ) Plot(Temp1, "OPEN ", colorYellow,styleLine) AND
Plot((1-(LastValue(STOPLOSS)/100))*(Temp1), "STOPLOSS ", colorRed, styleLine) AND
Plot((1+(LastValue(PROFIT)/100))*(Temp1), "PROFIT ", colorGreen, styleLine) AND
Plot((1+(LastValue(EPT1)/100))*(Temp1), "EPT1 ", colorWhite, styleLine|styleDashed) AND
Plot((1+(LastValue(EPT2)/100))*(Temp1), "EPT2 ", colorWhite, styleLine|styleDashed) AND
Plot((1+(LastValue(EPT3)/100))*(Temp1), "EPT3 ", colorWhite, styleLine|styleDashed) AND
Plot((1+(LastValue(EPT4)/100))*(Temp1), "EPT4 ", colorWhite, styleLine|styleDashed) AND
Plot(Verline , "", colorRed, styleHistogram | styleOwnScale | styleThick | styleNoLabel); //vertical line on entered day

if (LinesSHORT ) Plot(Temp1, "OPEN ", colorYellow,styleLine) AND
Plot((1+(LastValue(STOPLOSS)/100))*(Temp1), "STOPLOSS ", colorRed, styleLine) AND
Plot((1-(LastValue(PROFIT)/100))*(Temp1), "PROFIT ", colorGreen, styleLine) AND
Plot((1-(LastValue(EPT1)/100))*(Temp1), "EPT1 ", colorWhite, styleLine|styleDashed) AND
Plot((1-(LastValue(EPT2)/100))*(Temp1), "EPT2 ", colorWhite, styleLine|styleDashed) AND
Plot((1-(LastValue(EPT3)/100))*(Temp1), "EPT3 ", colorWhite, styleLine|styleDashed) AND
Plot((1-(LastValue(EPT4)/100))*(Temp1), "EPT4 ", colorWhite, styleLine|styleDashed) AND
Plot(Verline , "", colorRed, styleHistogram | styleOwnScale | styleThick | styleNoLabel); //vertical line on entered day
_SECTION_END();

However, I would prefer a more static way. Enter a date in the parameters, and select Show lines LONG or Show lines SHORT, and it should plot the lines from the entered day
to the right.

I tried different ways, but don't get the results I want. Does anyone see a solution?
 
#2
I made some progress on this, but still don't have what I want.
Maybe somebody knows,

How do you get the barnumber of the date you enter in the parameters?

It all works with linearrays, and the problem will probably x0
That the place where I want the horizonal line to be draw from?

Any advise on this?

Here's the updated code

_SECTION_BEGIN("__add custom lines to pricechart_test");

STOPLOSS = 2.5;
PROFIT = 2.5;
EPT1= 1.0;
EPT1a= 1.5;
EPT2= 2.0;
EPT3= 3.0;
EPT4= 4.0;

EPT5= 5.0;
EPT6= 7.5;
EPT7= 10.0;

line = DateNum() == ParamDate("VUL IN V/D DAG NA SIGNAAL: DATUM", "24/02/2012", 0); //plot vertical line

Value = Param( "VUL IN V/D DAG NA SIGNAAL: OPEN", 327.52,200,600,0.01 );

LinesLONG = ParamToggle("Toon lijnen positie LONG ","No|Yes",0);
LinesSHORT = ParamToggle("Toon lijnen positie SHORT ","No|Yes",0);


mystartbar = SelectedValue(BarIndex()); // FOR GRAPHING
mystartbardate = LastValue(ValueWhen(mystartbar == BarIndex(),DateNum(),1));

InitialValue = LastValue(ValueWhen(mystartbardate == DateNum(), O , 1 ) ) ;
Temp1 = IIf(BarIndex() >= mystartbar, InitialValue, Null) ;
bi = BarIndex();
dn = DateNum();


y0=Value;
y1=Value;
x0=mystartbar ;
x1=LastValue( BarIndex() );
//Plot( xLine, "Trend line", colorBlue );

VLONG_INGEVULD=Value;
VLONG_TARGET=Value +((Value /100)*PROFIT);
VLONG_STOPLOSS=Value -((Value /100)*STOPLOSS);
VLONG_1=Value +((Value /100)*EPT1);
VLONG_15=Value +((Value /100)*EPT1a);
VLONG_2=Value +((Value /100)*EPT2);
VLONG_3=Value +((Value /100)*EPT3);
VLONG_4=Value +((Value /100)*EPT4);
VLONG_5=Value +((Value /100)*EPT5);
VLONG_75=Value +((Value /100)*EPT6);
VLONG_100=Value +((Value /100)*EPT7);

LINELONG_INGEVULD =LineArray( x0, y0, x1, y1, 0);
LINELONG_TARGET=LineArray( x0, VLONG_TARGET, x1, VLONG_TARGET, 0 );
LINELONG_STOPLOSS=LineArray( x0, VLONG_STOPLOSS, x1, VLONG_STOPLOSS, 0 );
LINELONG_1=LineArray( x0, VLONG_1, x1, VLONG_1, 0 );
LINELONG_15=LineArray( x0, VLONG_15, x1, VLONG_15, 0 );
LINELONG_2=LineArray( x0, VLONG_2, x1, VLONG_2, 0 );
LINELONG_3=LineArray( x0, VLONG_3, x1, VLONG_3, 0 );
LINELONG_4=LineArray( x0, VLONG_4, x1, VLONG_4, 0 );
LINELONG_5=LineArray( x0, VLONG_5, x1, VLONG_5, 0 );
LINELONG_75=LineArray( x0, VLONG_75, x1, VLONG_75, 0 );
LINELONG_100=LineArray( x0, VLONG_100, x1, VLONG_100, 0 );

if (LinesLONG )
Plot(LINELONG_INGEVULD,"LINELONG_INGEVULD", colorBlue ,styleLine | styleThick, Null, Null, 10) AND
Plot(LINELONG_TARGET, "LINELONG_TARGET" ,colorGreen,styleLine | styleThick, Null, Null, 10) AND
Plot(LINELONG_STOPLOSS,"LINELONG_STOPLOSS", colorRed,styleLine | styleThick, Null, Null, 10) AND
Plot(LINELONG_1," 1.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINELONG_15," 1.5% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINELONG_2," 2.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINELONG_3," 3.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINELONG_4," 4.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINELONG_5," 5.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINELONG_75," 7.5% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINELONG_100," 10.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(line, "", colorLightBlue, styleHistogram | styleOwnScale | styleNoLabel | styleThick);

VSHORT_INGEVULD=Value;
VSHORT_TARGET=Value -((Value /100)*PROFIT);
VSHORT_STOPLOSS=Value +((Value /100)*STOPLOSS);
VSHORT_1=Value -((Value /100)*EPT1);
VSHORT_15=Value -((Value /100)*EPT1a);
VSHORT_2=Value -((Value /100)*EPT2);
VSHORT_3=Value -((Value /100)*EPT3);
VSHORT_4=Value -((Value /100)*EPT4);
VSHORT_5=Value -((Value /100)*EPT5);
VSHORT_75=Value -((Value /100)*EPT6);
VSHORT_100=Value -((Value /100)*EPT7);

LINESHORT_INGEVULD =LineArray( x0, y0, x1, y1, 0);
LINESHORT_TARGET=LineArray( x0, VSHORT_TARGET, x1, VSHORT_TARGET, 0 );
LINESHORT_STOPLOSS=LineArray( x0, VSHORT_STOPLOSS, x1, VSHORT_STOPLOSS, 0 );
LINESHORT_1=LineArray( x0, VSHORT_1, x1, VSHORT_1, 0 );
LINESHORT_15=LineArray( x0, VSHORT_15, x1, VSHORT_15, 0 );
LINESHORT_2=LineArray( x0, VSHORT_2, x1, VSHORT_2, 0 );
LINESHORT_3=LineArray( x0, VSHORT_3, x1, VSHORT_3, 0 );
LINESHORT_4=LineArray( x0, VSHORT_4, x1, VSHORT_4, 0 );
LINESHORT_5=LineArray( x0, VSHORT_5, x1, VSHORT_5, 0 );
LINESHORT_75=LineArray( x0, VSHORT_75, x1, VSHORT_75, 0 );
LINESHORT_100=LineArray( x0, VSHORT_100, x1, VSHORT_100, 0 );

if (LinesSHORT )
Plot(VSHORT_INGEVULD,"INGEVULD:",colorBlue ,styleLine | styleThick, Null, Null, 10) AND
Plot(LINESHORT_TARGET," TARGET ",colorGreen,styleLine | styleThick, Null, Null, 10) AND
Plot(LINESHORT_STOPLOSS," STOP ",colorRed,styleLine | styleThick , Null, Null, 10) AND
Plot(LINESHORT_1," 1.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINESHORT_15," 1.5% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINESHORT_2," 2.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINESHORT_3," 3.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINESHORT_4," 4.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINESHORT_5," 5.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINESHORT_75," 7.5% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(LINESHORT_100," 10.0% ",colorBlack,styleLine|styleDashed, Null, Null, 10 ) AND
Plot(line, "", colorLightBlue, styleHistogram | styleOwnScale | styleNoLabel | styleThick);
_SECTION_END();