Hi,
I want to analyse some stock prices. I want to know the highest high and lowest low from each date in the past for the upcoming 100 days. I also want to know when there is a drop of 10% in price since start date. I was able to code this.
But now I want to know also the date when the drop in price occured and the number of days since start date.
This is the code I have:
lookback = 100;
ddThreshold = 10;
startClose = Close;
startDate = DateTime();
endDate = Ref(DateTime(), lookback);
endClose = Ref(Close, lookback);
highestPrice = HHV(High, lookback);
lowestPrice = LLV(Low, lookback);
highestPriceDate = ValueWhen(High == highestPrice, DateTime(), lookback);
lowestPriceDate = ValueWhen(Low == lowestPrice, DateTime(), lookback);
highestClose = HHV(Close, lookback);
lowestClose = LLV(Close, lookback);
highestCloseDate = ValueWhen(Close == highestClose, DateTime(), lookback);
lowestCloseDate = ValueWhen(Close == lowestClose, DateTime(), lookback);
maxDrawdownLowest = 100 * (highestPrice - lowestPrice) / highestPrice;
maxDrawdownClose = 100 * (highestClose - lowestClose) / highestClose;
drawdownAlert = IIf(maxDrawdownClose > ddThreshold, 1, 0);
Filter = 1;
AddColumn(startDate, "Start Date", formatDateTime);
AddColumn(startClose, "Start Close", 1.2);
AddColumn(endDate, "End Date", formatDateTime);
AddColumn(endClose, "End Close", 1.2);
AddColumn(highestPrice, "Highest Price (High)", 1.2);
AddColumn(highestPriceDate, "Highest Price Date", formatDateTime);
AddColumn(highestClose, "Highest Close", 1.2);
AddColumn(highestCloseDate, "Highest Close Date", formatDateTime);
AddColumn(lowestPrice, "Lowest Price (Low)", 1.2);
AddColumn(lowestPriceDate, "Lowest Price Date", formatDateTime);
AddColumn(lowestClose, "Lowest Close", 1.2);
AddColumn(lowestCloseDate, "Lowest Close Date", formatDateTime);
AddColumn(maxDrawdownLowest, "Max Drawdown (Lowest)", 1.2);
AddColumn(maxDrawdownClose, "Max Drawdown (Close)", 1.2);
AddColumn(drawdownAlert, "DD Close > Threshold", 1.0);
Can someone help me?