Buy on certin dates, not on technical singal

Forums ProRealTime English forum ProOrder support Buy on certin dates, not on technical singal

Viewing 15 posts - 1 through 15 (of 22 total)
  • #228395

    Hi,
    I’m a cycle analyst and want to try my predicting of change in market trends by using PRTs backtest function and possibly try to automate trading of my models going forward as well.

    Is it possible to set certain dates when the LONG/SHORT order is opened? Instead of using a technical indicator as trigger (or several).

    Any my general strategy for the Open/close of position would be:
    Example have a scheduled trend change tomorrow (currently hold no positions). I want to LONG so I buy 1 lot at market close. In a few days time I have another trend change date and I want to sell my LONG at close. And open up a SHORT at the same time. and this goes on and on continuously. LONG positions turned into SHORT positions at the close of my selected pivot dates.

    SL would be set to 2-3%.

    Also, is the process of entering/selecting dates for the trades easy? I have maybe 50 dates on a year, sometimes less, can I upload or do I manually select them in the software?

    Any and all help is much appreciated. I’m new to this software of endless possibilities. 🙂

    Thanks so much.

    Regards

    #228414

    This is an example to open and close Long and Short trades according to set entry and exit dates:

    it can be adapted to your needs, but I need some examples to better understand what you want to achieve.

     

     

    #228421

    Thanks for your fantastic input Roberto, much appreciated.

    Let me give you a real example for the month of February of this year.

    For the purpose of this example I start with zero trades, no position.

    In my cycle work I continuously generate a date sequence which is basically a High-Low-High-Low-High pattern going forward.

    Now in Feb the dates are:
    20240201 High
    20240214 Low
    20240219 High
    20240223 Low
    20240228 High
    and so on…

    Now, coming 1 Feb I want to go short (-1 lot = -1 pos) at market close price since the shceduled pivot is a HIGH in market. SL 2%
    14 Feb: close my short (+1 lot = 0 pos) at market close and go long market, so buy 1 lot (+1 lot = +1 pos) at the same time as my previous short is closed, at market close. SL 2%.
    19 Feb: sell long (-1 lot = 0 pos) at market close and go short (-1 lot = -1 pos) at market close. SL 2%.
    23 Feb: close short (+1 lot = 0 pos) at market close and go long (+1 lot = +1 pos) at market close.
    28 Feb: close long (-1 lot = 0 pos) at market close and go short (-1 lot = -1 pos)

    And so it continues.

    Other extras I can think of:
    + Always close the previous position/direction before going into new position/direction (long/short)
    + Maybe build in possibility to have toggle option on trailing, lets say start with fixed Stop Loss at 2-3% (preferably adjustable manually) but when/if the market moves in right direction and positive trade, option to change it to a trailing Stop of xx-%.

    + Now to the final adjustment I need to figure out how to solve as the time goes by.
    At points in time there can all of a sudden appear an extra pivot in the sequence, one extra trading date, and as a result the polarity of the remaining pivots during the month/year/sequence all change their polarity. IE high becomes a LOW and I have to change polarity of all trades onward.

    Here is an example of extra pivot being introduced in February and the “new” sequence would look like this:

    20240201 High
    20240214 Low
    20240219 High
    20240221 NEW/EXTRA pivot which becomes LOW (from prior sequence)
    20240223 Originally Low but now changes into HIGH
    20240228 Originally High but now changes into LOW.

    The H-L-H-L-H-L needs to be intact all the time.

    So I’m thinking that instead of changing everything in the code would it be possible to assign a numerical value to each $myDateL, $myExitL, $myDateS and $myExitS.
    For example $myDateL = 1 and $myExitL = 2, $myDateS = 3 and $myExitS = 4.
    And if I see that this extra pivot have happened in the market I simply change the numbers above (in input fields) so the Long  becomes Short and vice versa.
    Or if you can think of other solution that is much more elegant. 🙂

    Again thanks Roberto.

    Regards
    Fredrik

    #228493

    Roberto,
    Forgot to add. If you need me to clarify any of the process/cycle just let me know. I’m so grateful for all your input and help here.

    Grazie mille! 🙂

    Regards
    Fredrik

    #228523

    Please post my original code with the updated dates you want.

    Dates already have a value, the one within brackets used to identify each elelement of the array.

    Then please rephrase the changes you want to make.

     

    #228531

    Roberto,

    Ok, I have changed to the correct dates based on the cycle logic I gave in the example.

    + Can you please add on all Open Long and Short trades, a fixed Stop Loss of 2% ?

    When are the trades executed, exactly at market close? And that is defined by my current selection of market, right?

    Also. this is just a big plus if it’s possible, you tell me:
    As I described earlier there can be an extra pivot coming into play without me knowing it in advance, called inversion, but I will notice quickly. This extra pivot changes the whole polarity going forward. The sequence must always be High-Low-High-Low and so on, and in code language BUY-SELL//SELLSHORT-EXITSHORT//BUY-SELL//SELLSHORT-EXITSHORT//BUY-SELL and so on.

    But if inversion happen the polarity of forward sequence change and I need to adjust all forward dates. IE instead of shorting next date in que I want to Long it and so on. Is there a simple way to change all entered dates so they become the opposite?

    I don’t know PRT code so please correct me here, but could this be done by altering:
    Line 29 from BUY to SELLSHORT
    Line 36 from SELLSHORT to BUT
    Line 47 from SELL AT MARKET to EXITSHORT AT MARKET
    Line 56 from EXITSHORT AT MARKET to SELL AT MARKET

    What do you think? Would this change the sequence without moving dates around?
    But this is only in case I need to change the whole sequence going forward.

    Thanks for you valuable input and help here Roberto.

    Regards
    Fredrik

    #228549

    Your questions:

    Can you please add on all Open Long and Short trades, a fixed Stop Loss of 2% ?
    done (see my code below)

    When are the trades executed, exactly at market close? And that is defined by my current selection of market, right?
    correct (there might be some slippage, though)

    Also. this is just a big plus if it’s possible, you tell me:
    As I described earlier there can be an extra pivot coming into play without me knowing it in advance, called inversion, but I will notice quickly. This extra pivot changes the whole polarity going forward. The sequence must always be High-Low-High-Low and so on, and in code language BUY-SELL//SELLSHORT-EXITSHORT//BUY-SELL//SELLSHORT-EXITSHORT//BUY-SELL and so on.

    But if inversion happen the polarity of forward sequence change and I need to adjust all forward dates. IE instead of shorting next date in que I want to Long it and so on. Is there a simple way to change all entered dates so they become the opposite?

    I don’t know PRT code so please correct me here, but could this be done by altering:
    Line 29 from BUY to SELLSHORT
    Line 36 from SELLSHORT to BUT
    Line 47 from SELL AT MARKET to EXITSHORT AT MARKET
    Line 56 from EXITSHORT AT MARKET to SELL AT MARKET

    What do you think? Would this change the sequence without moving dates around?
    Perfect, thats exacly what you need to do
    .

    Updated code with a 2% SL (you can change that percentage whenever you need to).

     

    #228551

    Thanks for your reply!!!!
    Will enter dates from a period last year and modify so I can backtest it and see performance.
    Again thank you!!

    I need to show DAILY chart in selected market in PRT to get the backtest to work right or can I look at 15min chart and this will still run on Daily time frame?

    Regards
    Fredrik

    #228553

    You can use it also on a 15-minute TF, but you need to add this line at the very beginning:

    and append this line at the end:

    #228557

    Trying to follow this in itself nice topic …

    From of sentence 1 I have been confident that what Fredrik wants, can’t work. But please correct me where I am wrong :

    Fredrik wants to inject newly emerged “pivots”. That is fine in itself. But he won’t be able to do that without stopping the system and change the code (change the arrays).
    Fredrik, if that is fine with you, then all OK and Roberto’s code will (or may) work.

    N.b.: My idea of an initial response would have been : Yes, possible, if you first make an Indicator for it after all. Thus, if your code would be able to determine those “dates”, then all would work fine. But this is not really the gist of your topic plus it would be the same everybody else is trying to get right. 🙂

    Regards,
    Peter

    #228559

    Is this correct understood?

    REST of CODE here…

    #228568

    Roberto,
    I threw in a few dates from last year to run a backtest and test code. For some reason it looks like the system only open the LONG trades and not the short ones.
    I’ve been over the code my self a few times to try to spot the error but I cannot see it. So I kindly ask for your help or if anyone else can spot it?

    No modification of your original code except the dates.

    #228570

    Was just thinking about one possibility.

    Could it be that the code see that I already have a position open (Long +1) and avoid to open a second one (short -1)?
    Or that my myDateL gets canceled by $myDateS and the $myExitL/$myExitS never gets run?
    Can I space out the Long and Short opening by 1 min to avoid this is this is the case? Any quick fix in the code?

    I’m not familiar with the logic so cannot tell the order of things.

    #228572

    Hi,
    I’ve read some more on the topic and I think I understand the solution now with MTF breakdown of the time of execution. I don’t need to complicate things As I LONG/SHORT on fixed dates so I can keep them running on two separate algos. One with LONG and one with SHORT.

    Was trying to create a separate code for LONG and a separate version for short but get error.

    Here is my LONG code version and get error on line 15:

    Can you spot the error?

    #228575

    The Max function requires two parameters – not one.
    Probably you don’t want to use Max at all there ? just LastElementL.

    1 user thanked author for this post.
Viewing 15 posts - 1 through 15 (of 22 total)

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