Hi Everyone!
How do I create a code that will calculate a ROI% in the following scenario:
I have a criterion on the end of day close on the daily chart 956 days ago that is triggered. I want to calculate a ROI% that is based on an order for tomorrow (955 days ago) which is equal to one cent above the close today (956), but I want to exit the trade 150 minutes after the market opens. Also, if the trade is not filled within the first 30 minutes of the day, I want to cancel the order.
Example:
Trade criteria on the close of today (956 days ago) is met.
XYZ stock closes 956 days ago at 59.06.
Order for 955 days ago (which is the next day) is a limit order at 59.07.
If the order would be filled in the first 30 minutes of the day, I want to exit the trade at 150 minutes from the open time of the day (955) and have the screener calculate a column that shows what the ROI% would be at the 150 minutes mark.
If the order would not be filled during the first 30 minutes of the day, I want the screener to return 0.
I have figured out how to get this ROI% with only end of day data, but I can’t figure out how to get it to do what I describe above for the intraday time frames indicated. (If there is no way to calculate it for the 150 minutes timeframe, I will use the 2 hour timeframe instead.)
Here is the code I currently am using to calculate for end of day data:
N = 956
Combo = Close[N] > 5 and Volume[N] > 500000
OpenBelow99 = (Open / (Close[1]+.01)) < 1
LowVsYstCLBelow99AndOpenAbove99 = (Low / (Close[1]+.01)) <= 1
LowVsYstCLAbove99 = (Low / (Close[1]+.01)) > 1
IF LowVsYstCLBelow99AndOpenAbove99 THEN
LowVsYstCL = ((Close / (Close[1]+.01))-1)*100
ENDIF
IF OpenBelow99 THEN
LowVsYstCL = ((Close – Open) / Open)*100
ENDIF
IF LowVsYstCLAbove99 THEN
LowVsYstCL = 0
ENDIF
criteria11 = LowVsYstCL[N-1]
SCREENER [combo] (criteria11 AS “ROI %”)
What is the code to accomplish what I am looking for?
Thank you!