How do I calculate ROI% based on a combination of EOD and intraday time frames?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #218696 quote
    ijackdoe85
    Participant
    New

    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!

    #218705 quote
    ijackdoe85
    Participant
    New

    I figured out the following code, and it works perfectly… but only going back until you have a holiday that only trades til noon, then the calculations become inaccurate. Is there anyway to fix this?

     

    N = 23
    
    Combo = Close[N] > 5 and Volume[N] > 500000
    
     
    Timeframe(2 hours)
    OP2hr = Open
    Low2hr = Low
    CL2hr = Close
    Timeframe(default)
    
    OpenBelow99 = (OP2hr[1] / (CL2hr[2]+.01)) < 1
    LowVsYstCLBelow99AndOpenAbove99 = (Low2hr[1] / (CL2hr[2]+.01)) <= 1
    LowVsYstCLAbove99 = (Low2hr[1] / (CL2hr[2]+.01)) > 1
    
    IF LowVsYstCLBelow99AndOpenAbove99 THEN
    LowVsYstCL = ((CL2hr / (CL2hr[2]+.01))-1)*100
    ENDIF
    IF OpenBelow99 THEN
    LowVsYstCL = ((CL2hr - OP2hr[1]) / OP2hr[1])*100
    ENDIF
    IF LowVsYstCLAbove99 THEN
    LowVsYstCL = 0
    ENDIF
    
    
    criteria11 = LowVsYstCL[(N*4)-2]
    
    SCREENER [combo] (criteria11 AS “ROI %”)
    #218717 quote
    robertogozzi
    Moderator
    Master

    With IG there’s a 256-bar limit, you cannot exceed that lookback period.

    With PRT Premium that limit is 1024 bars.

    This could be the source of the reported inaccuracy.

    ijackdoe85 thanked this post
    #218755 quote
    ijackdoe85
    Participant
    New

    Thank you, Roberto!

    I have PRT Premium.

    The problem currently is occurring only 24 daily bars looking back (which is 96 2-hours bars looking back.) The problem is due to the early close for July 4th. I figured out the work around:

    criteria11 = LowVsYstCL[(N*4)-2]
    
    has to be changed to:
    criteria11 = LowVsYstCL[(N*4)-3]
    
    The last integer has to be increased by one each time the market closes early to get the correct calculation for the 2 hours bars.
    Thank you.
    robertogozzi thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

How do I calculate ROI% based on a combination of EOD and intraday time frames?


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
ijackdoe85 @ijackdoe85 Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by ijackdoe85
2 years, 7 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 08/07/2023
Status: Active
Attachments: No files
Logo Logo
Loading...