Buy on certin dates, not on technical singal
Forums › ProRealTime English forum › ProOrder support › Buy on certin dates, not on technical singal
- This topic has 21 replies, 4 voices, and was last updated 7 months ago by Laliberte.
-
-
02/19/2024 at 12:58 PM #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
02/19/2024 at 5:14 PM #228414This is an example to open and close Long and Short trades according to set entry and exit dates:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960// LONG open dates$myDateL[1] = 20220401$myDateL[2] = 20220715$myDateL[3] = 20221122$myDateL[4] = 20230202// LONG exit dates$myExitL[1] = 20220420$myExitL[2] = 20220730$myExitL[3] = 20221202$myExitL[4] = 20230209LastElementL = 4// SHORT open dates$myDateS[1] = 20220507$myDateS[2] = 20221115$myDateS[3] = 20221219$myDateS[4] = 20230629// SHORT exit dates$myExitS[1] = 20220524$myExitS[2] = 20221123$myExitS[3] = 20221229$myExitS[4] = 20230713LastElementS = 4//IF Not OnMarket THENFOR i = 1 TO max(LastElementL,LastElementS)//LONG tradesIF i <= LastElementL THENIF Date = $myDateL[i] THENBUY 1 CONTRACT AT MARKETbreakENDIFENDIF// SHORT tradesIF i <= LastElementS THENIF Date = $myDateS[i] THENSELLSHORT 1 CONTRACT AT MARKETbreakENDIFENDIFNEXTENDIF//// exit LONG tradesIF LongOnMarket THENFOR i = 1 TO LastElementLIF Date = $myExitL[i] THENSELL AT MARKETbreakENDIFNEXTENDIF// exit SHORT tradesIF ShortOnMarket THENFOR i = 1 TO LastElementSIF Date = $myExitS[i] THENEXITSHORT AT MARKETbreakENDIFNEXTENDIFit can be adapted to your needs, but I need some examples to better understand what you want to achieve.
02/19/2024 at 9:36 PM #228421Thanks 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
Fredrik02/21/2024 at 10:57 AM #22849302/21/2024 at 6:33 PM #228523Please 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.
02/21/2024 at 10:15 PM #228531123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960// LONG open dates$myDateL[1] = 20240214$myDateL[2] = 20240223$myDateL[3] = 20240306$myDateL[4] = 20240315// LONG exit dates$myExitL[1] = 20240219$myExitL[2] = 20240228$myExitL[3] = 20240313$myExitL[4] = 20240321LastElementL = 4// SHORT open dates$myDateS[1] = 20240201$myDateS[2] = 20240219$myDateS[3] = 20240228$myDateS[4] = 20240313// SHORT exit dates$myExitS[1] = 20240214$myExitS[2] = 20240223$myExitS[3] = 20240306$myExitS[4] = 20240315LastElementS = 4//IF Not OnMarket THENFOR i = 1 TO max(LastElementL,LastElementS)//LONG tradesIF i <= LastElementL THENIF Date = $myDateL[i] THENBUY 1 CONTRACT AT MARKETbreakENDIFENDIF// SHORT tradesIF i <= LastElementS THENIF Date = $myDateS[i] THENSELLSHORT 1 CONTRACT AT MARKETbreakENDIFENDIFNEXTENDIF//// exit LONG tradesIF LongOnMarket THENFOR i = 1 TO LastElementLIF Date = $myExitL[i] THENSELL AT MARKETbreakENDIFNEXTENDIF// exit SHORT tradesIF ShortOnMarket THENFOR i = 1 TO LastElementSIF Date = $myExitS[i] THENEXITSHORT AT MARKETbreakENDIFNEXTENDIFRoberto,
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 MARKETWhat 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
Fredrik02/22/2024 at 10:27 AM #228549Your 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 MARKETWhat 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).
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364// LONG open dates$myDateL[1] = 20240214$myDateL[2] = 20240223$myDateL[3] = 20240306$myDateL[4] = 20240315// LONG exit dates$myExitL[1] = 20240219$myExitL[2] = 20240228$myExitL[3] = 20240313$myExitL[4] = 20240321LastElementL = 4// SHORT open dates$myDateS[1] = 20240201$myDateS[2] = 20240219$myDateS[3] = 20240228$myDateS[4] = 20240313// SHORT exit dates$myExitS[1] = 20240214$myExitS[2] = 20240223$myExitS[3] = 20240306$myExitS[4] = 20240315LastElementS = 4//SLpercent = 2 //2% stop loss//IF Not OnMarket THENFOR i = 1 TO max(LastElementL,LastElementS)//LONG tradesIF i <= LastElementL THENIF Date = $myDateL[i] THENBUY 1 CONTRACT AT MARKETSET STOP %LOSS SLpercentbreakENDIFENDIF// SHORT tradesIF i <= LastElementS THENIF Date = $myDateS[i] THENSELLSHORT 1 CONTRACT AT MARKETSET STOP %LOSS SLpercentbreakENDIFENDIFNEXTENDIF//// exit LONG tradesIF LongOnMarket THENFOR i = 1 TO LastElementLIF Date = $myExitL[i] THENSELL AT MARKETbreakENDIFNEXTENDIF// exit SHORT tradesIF ShortOnMarket THENFOR i = 1 TO LastElementSIF Date = $myExitS[i] THENEXITSHORT AT MARKETbreakENDIFNEXTENDIF02/22/2024 at 11:01 AM #228551Thanks 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
Fredrik02/22/2024 at 11:16 AM #228553You can use it also on a 15-minute TF, but you need to add this line at the very beginning:
1Timeframe(Daily)and append this line at the end:
1Timeframe(default)02/22/2024 at 11:40 AM #228557Trying 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,
Peter02/22/2024 at 11:44 AM #22855902/22/2024 at 1:38 PM #228568Roberto,
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.
This is the code I have used:12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364// LONG open dates$myDateL[1] = 20230316$myDateL[2] = 20230328$myDateL[3] = 20230411$myDateL[4] = 20230424// LONG exit dates$myExitL[1] = 20230321$myExitL[2] = 20230403$myExitL[3] = 20230417$myExitL[4] = 20230428LastElementL = 4// SHORT open dates$myDateS[1] = 20230321$myDateS[2] = 20230403$myDateS[3] = 20230417$myDateS[4] = 20230428// SHORT exit dates$myExitS[1] = 20230328$myExitS[2] = 20230411$myExitS[3] = 20230424$myExitS[4] = 20230508LastElementS = 4//SLpercent = 2 //2% stop loss//IF Not OnMarket THENFOR i = 1 TO max(LastElementL,LastElementS)//LONG tradesIF i <= LastElementL THENIF Date = $myDateL[i] THENBUY 1 CONTRACT AT MARKETSET STOP %LOSS SLpercentbreakENDIFENDIF// SHORT tradesIF i <= LastElementS THENIF Date = $myDateS[i] THENSELLSHORT 1 CONTRACT AT MARKETSET STOP %LOSS SLpercentbreakENDIFENDIFNEXTENDIF//// exit LONG tradesIF LongOnMarket THENFOR i = 1 TO LastElementLIF Date = $myExitL[i] THENSELL AT MARKETbreakENDIFNEXTENDIF// exit SHORT tradesIF ShortOnMarket THENFOR i = 1 TO LastElementSIF Date = $myExitS[i] THENEXITSHORT AT MARKETbreakENDIFNEXTENDIF02/22/2024 at 1:50 PM #228570Was 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.
02/22/2024 at 2:50 PM #228572Hi,
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:
1234567891011121314151617181920212223242526272829303132// LONG open dates$myDateL[1] = 20230316$myDateL[2] = 20230328$myDateL[3] = 20230411$myDateL[4] = 20230424// LONG exit dates$myExitL[1] = 20230321$myExitL[2] = 20230403$myExitL[3] = 20230417$myExitL[4] = 20230428LastElementL = 4SLpercent = 2 //2% stop loss//IF Not OnMarket THENFOR i = 1 TO max(LastElementL)//LONG tradesIF i <= LastElementL THENIF Date = $myDateL[i] THENBUY 1 CONTRACT AT MARKETSET STOP %LOSS SLpercentbreakENDIFENDIF// exit LONG tradesIF LongOnMarket THENFOR i = 1 TO LastElementLIF Date = $myExitL[i] THENSELL AT MARKETbreakENDIFNEXTENDIFCan you spot the error?
02/22/2024 at 3:06 PM #228575The 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.
-
AuthorPosts
Find exclusive trading pro-tools on