I wish to code a stop loss indicator commencing with a given date ( The date on which I purchased the stock)
Would someone be able to advise me how to code the start date into my indicator. I cannot find any reference
as to how to do this
Thanks
Michael Mulcahy
200 chosen for development only. Could be any number.
This function will plot for all the data on the screen but will not suite my aim as it refers to 200 days and may well give a HHV very different from my entry point.
My wish is to
Make the look back period a variable based on the number of trading days between the current date and the buy date.
Variable = No. of trading days between current date and buy date = A
So the plot would become
Plot ((HHV(h, A )-(HHV(h, A )*0.1)),"HHV ( A )",colorBrightGreen);
So I am really looking for a mechanism to enter the initial date and then have the system use the current date to calculate the value of “A” the look back period .
Hopefully the indicator will only be displayed commencing at the buy date.
// In a separate part of your code, store the buy Date
// Use some unique naming methodology for the variable name
setBuyDT = DateTime(); // or suitable code
StaticVarSetText( "Symb1Buy1", DateTimeToStr( setBuyDT ), True );
Do read about Persist=True in Static Variables.
Retrieving and using it.
// In another part of your code, where you want to retrieve the value
// I will skip NZ and other validation checks, bad get variable will be erroneous.
getBuyDt = StrToDateTime( StaticVarGetText( "Symb1Buy1" ) );
barsSinceBuy = DateTimeDiff( LastValue( DateTime() ), getBuyDt ) / Interval();
// Now you have the Bars since you bought
The above computes bars, if your chart is Daily, then you can infer it as Trading Days
Is this good enough a direction?
Edit: barsSinceBuy would be the value referring to A in your code.