premarket open price breakout strategy idea

Forums ProRealTime English forum ProOrder support premarket open price breakout strategy idea

Viewing 15 posts - 1 through 15 (of 38 total)
  • #66884

    hi there

    I am a total newbie here (but an expert programmer)

    I would like to test a simple program before i go deeper into the code

    the program would:

    1. take a bar 2 hour prior to the US market open (for example for IBM share)
    2. get the high of that bar at 7:30 US time
    3. buy once the US market opens at 9:30 if the price is equal or higher then that high bar price
    4. stop after the initial buy

    any suggestions would be greatly appreciated

    Here is my code:

     

    Moderator’s edit: code above reformated on your behalf, when adding code to a message please use the “insert PRT code” button located in the message editor at the end of the first line of tools icons, thanks

    #66982
    • For a new topic, your title should be explicit enough to prompt the community to read your discussion.

    “simple code” means nothing to me … I changed it.

    1 user thanked author for this post.
    #66990
    Hello and welcome

    not sure how to get the current price right now – as i don’t want the high,low,close,open but the current price

    Close, same as Close[0]  is the price at any instant, i.e. the current price.

    When a new candle opens then the Close of the previous candle becomes Close[1]

    Hope that makes sense, if not just say

    Cheers
    GraHal

     

    1 user thanked author for this post.
    #67020

    Great Thanks GraHal,

    I have a few more questions and would very much appreciate your help:

    1. I understand there is no option to “debug” or trace a program while it is running, is there any “printout” option to make sure the code is doing what I want it to do?
    2. It seems the code I wrote above continues working endlessly (keeps on buying shares starting at 9:30). how do I stop it after a single buy or single sell (or maybe after 1 buy and 1 sell)
    3. How can I know if I have a profit at run time (for example I would like to write: BUY 1 CONTRACTS AT MARKET and if you made a profit then stop else buy another contract when the condition is met again)

    Thanks again for all your help guys

    Cheers,

    Alan

     

    #67026

    BTW for itme #2 above I used

    to get it to try again after 9:30 but I do want to limit the amount of time it sells/buys

    to be more exact, how do I get MyBuyPrice in the example below

    to occur only once a day at the open of the market and then be triggered only a set X amount of times during that day

    #67035

    you dont need to reinvent the wheel

    https://www.prorealcode.com/topic/ts-break-prima-ora/#post-56666

     

    1 user thanked author for this post.
    #67069

    Thanks, that was very informative

    I always prefer not to invent the wheel if possible

    based on the code you sent me I run a quick test and it seems it still doesn’t fully do what I expect it to do.

    I wrote the simplest possible program to just get the last high from the bar before now and buy when the market is above that highest buy.

    I run it for IBM 15 min bars on March 28 at 14:30

    the highest of that 14:15 bar was 15274.5

    but the buy order was triggered at 14:30 at 15265.5

    it seems like it is ignoring the high[1] and just buying the open of the current bar

    what am i missing here?

     

    #67071

    You place a market order when your condition comes true. This order is executed at the open of the next bar. Try replacing your market order with a limit order.

    1 user thanked author for this post.
    #67077

    Thanks, Can you elaborate?

    I can’t see how my condition could have been met if close>MyBuyprice was not reached yet at market open.

    I reread the documentation about limit and tried changing the code to “BUY 1 CONTRACTS AT MyBuyprice  limit” but that didn’t work  (tried “close-10 limit” and other options too)

    So I guess I don”t know how to use limit in this sense here.

    my understanding of limit is the amount or points I want to profit where as stoploss are the amount/points I am willing to lose

    also, from reading the docs I see that the LIMIT order should be below the close price which is not what I need

     

    It seems no matter what I do the MyBuyprice  is set to a number that is different then the high[1]

    #67083

    Line 9 sets MyBuyPrice equal to the high price of the 141500 bar, so that price will be your trigger, no matter if it is higher or lower than the one of the previous or following bar!

    To place a pending order you can replace lines 11-14 with

    but pending oders only last one bar, so I suggest to remove line 13 to prevent it from being placed again correctly next bar. You should set it when the strategy IS ON MARKET to prevent further trading, at the same price, once the trade is closed.

    Effectively line 13 is of not much use since there is never a test against it, nor it has ever been initialized!

    1 user thanked author for this post.
    #67163

    First off I’d like to thank all of you for taking the time to reply to my questions. I really appreciate it!

    Thanks roberto, I tried the code you suggested as follows

    but it just gets into the market at 14:30 with the open of that bar (not the amount in MyBuyPrice/high[1]) no matter what I do

    here is what I need for this simple example to work:

    1. get the high of the previous bar when the market opens
    2. get into the market with a buy order if the market reached that high

    Thanks again

    Alan

    #67187

    STOP pending orders are used to BUY at a less convevient price than the current one (you want to BUY at a higher price), while LIMIT pending orders are used to BUY at a more convenient price (you want to BUY at a lower price). So you’ll have to use STOP or LIMIT according to such cases.

    Using

    embedded in your code, you can debug your strategy and might be able to spot any bug/issue you may have encountered.

    Anyway, you know that the very first bar of each day is when INTRADAYBARINDEX = 0, so you just need to chek the previous HIGH to know it’s the one before trading started

    I hope this helps further.

     

    1 user thanked author for this post.
    #67342

    Yes “GRAPH” is exactly the debugging tool I was looking for. Thanks!

    Now I see the problem (at 14:30 high[1] is actually giving me the value from 14:00 not 14:15 – not sure why…)

    So now to finish my example I have another question:

    How can I tell if a position made profit or loss. I want the code to do the following:

    WHEN out of the market/position

    IF CONDITION <“made profit today”> THEN quit for the day

    ELSE attempt another trade

     

    any thoughts?

    Thanks

    Alan

    #67346

    POSITIONPERF (https://www.prorealcode.com/documentation/positionperf/) will do the trick together with a variable to Enable/Disable trading

    This should do, but it will stop trading as soon as the previous trade of the day was profitable, despite there may have been losing trades before so that your STRATEGYPROFIT (https://www.prorealcode.com/documentation/strategyprofit/) may still be negative for the day.

    You’ll have to improve the code with the use of STRATEGYPROFIT to make your strategy more afficient and tailored to your needs.

    If you save the current STRATEGYPROFIT at the very beginning of each day, later that day you may tell (by comparing the current and old values) if, despite the POSITIONPERF of any trade, you are still in gain or not.

    1 user thanked author for this post.
    #67781

    Thanks again Roberto and all

    For the last few days I wrote the basic test code but it is still not finished.

    1. I am still not sure how to cancel all positions and orders – is there a command (like QUIT but only for a single day) or do I need to manually SELL AT MARKET even when I didn’t buy yet
    2. I am also not sure if all the code is run for each bar again and again (I am guessing the answer is yes)
    3. if the bar is a 3 minute bar does it wait till close to run the code is it not in “real time” tick for tick
    4. if I want to look back and backtest the data from the last 12 month can I do it on a 3 min bar? it seems I have very limited access to the data on a 3 min bar

    Any help would be greatly appreciated

    Thanks

    Alan

Viewing 15 posts - 1 through 15 (of 38 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login