Help to program an idea that worked
Forums › ProRealTime English forum › ProOrder support › Help to program an idea that worked
- This topic has 42 replies, 4 voices, and was last updated 8 years ago by quo.
-
-
10/28/2016 at 9:17 PM #15688
All right, at long last I think I got it. You can have a “relaxing cup of café con leche” on me, you well deserve it. Why all this blunder of us but mainly mine? Well, as Her Gracious Majesty would put it: Shit happens!, but She’d really be thinking: Diana happens!
After the joke of the day, let’s talk business:
First, could you, when you have the time to spare, take a good look at picture Example-1 and confirm to me that’s how the strategy works? (Always with exit filter being equal to 0%).
Then, in picture Example-2, what value shoud have stop2? 148,6, the low of bar 1, or 144,16, the low of bar 2? That is, are the stops the lowest low between maximums (these excluded) or the lowest low with the more recent maximum (bar 2 too in this case) included?
If picture Example-1 is OK, that would be my only doubt right now. Others could appear in coding time, but I don’t think so. As a penance, I intend to try and code most or all of the strategy during this weekend.
Thanks. More soon.
10/29/2016 at 12:02 PM #15697Hi again, i think we are almost there.
You got it, but let me be fussy:
-.The day when we change the stops is the day marked with vertical blue dot line (i think we agree on that)
-.I see in jun 1993 that market crosses over the maximum (just by milimiters) before fall down, so to be strick you would have to rise the stop to the minimum of april (0,41 aprox). Therefore a stop number 4 is missing in that place and the exit should be there.
Lets go with picture number 2. Here is when you get to the point.
The answer to this question is: it depends
Talking about candle march 2014: If market opens and prices goes up to the maximum the stop will be number 1 because we dont have yet the minimum of march, but if prices goes down after the opening and after touch its minimum goes up and crosses the máximum, the stop will be number two. It is always the lowest point the day of the break out.
I normally check this manually going to weekly charts but i know this is not possible to code, so we have to establish by default something. PRT doesn´t know what happends first, the minimum or the maximum.
If i had to choose, in order to set the rules… i would say… that the system has to take stop number 2.I think is easier to code find the lowest between two day including first and last bar. Don´t you think?
The results won´t be the same than doing manually but i promise that if this is the only difference will be a great work and really helpful.
cheers
10/29/2016 at 3:57 PM #15699Hi,
Quote: “I see in jun 1993 that market crosses over the maximum (just by milimiters) before fall down, so to be strick you would have to rise the stop to the minimum of april (0,41 aprox). Therefore a stop number 4 is missing in that place and the exit should be there.”
??? If so, we are back to square one, man.
I didn’t want to, but I’m going to open a new thread in the Spanish forum. After all, it’s free, isn’t it?. See you there shortly.
10/29/2016 at 8:33 PM #1570310/29/2016 at 9:58 PM #15708The problem is we sell at 0.3 and not at 0.41.
The high of jun 1993 brokes the high of jan 1993 as you say and THEN I move the stop to 0.3 from 0.23. The stop will not be moved to 0.41 until the high of jun 1993 is broken which has not happened. That is my understanding but that’s not what you are saying, is it?
10/30/2016 at 3:06 AM #15710Ok, lets go:
- Dec 1990, new maximum, then stop in 0,11
- January 1992 new maximum , then stop up to 0,23
- Dec 1992, new maximum, then stop up to 0,3
- Jun 1993, new maximum, then stop to 0,41
Every new maximum (vertical blue dot line) you look backwards to find the lowest value between the day of the break (vertical blue dot line) and the previous maximum (where the horizontal blue dot line begins).
10/30/2016 at 9:54 AM #15712Morning man, late night I see.
Ok, that’s what has to be done. Understood. In fact, it’s the logic and natural thing to do.
But you wrote: “You did it with 3 previous stops…”. No, I didn’t. Look again CAREFULLY to my picture.
Never mind, as I say: NOW I got it. So, good news and hallelujah!
No need then to answer to my post in the Spanish forum. Let’s keep it in standby though. We might need it in future.
Bye
10/30/2016 at 11:19 PM #15732“Oh Lord, please don’t let me be misunderstood” sang The Animals and Nina Simone before them. Oh Lord, how well we understand you, guys!
The version v.03.1 of the strategy code goes like this:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263// TS name: Historical Maximum Breakout// Description: Buy at pivot highs breakouts.// Sell at relative minimums (or lows) between the// breakout of a pivot high and that pivot high// A pivot high is confirmed by a correction in the low// of the bar(s) after a new historical maximum// Instruments: Stocks/ETFs// Time frame: Daily / preferibly weekly or monthly// Features: Long only system. No money management// Version: 03.1// ****************************************************************************// customizable and optional parametersonce positionSize = 2000 // Fixed capitalonce exitFilter = 3 // % below relative minimum to exit position// variables declarationonce historicMax = 0 // pivot highonce currentMax = 0 // current maximum candidate to pivot highonce barHistoricMax = 0 // pivot high barIndexonce barCurrentMax = 0 // current maximum barIndexonce exitPrice = 0 // exit priceonce buyPrice = 0 // buy priceonce lowBar0 = 0 // stores low of 'tricky' first loaded bar//if barIndex = 0 thenlowBar0 = lowendifif high >= currentMax then//keep track of candidates to new pivot highcurrentMax = highbarCurrentMax = barIndexelsif high < currentMax and currentMax > historicMax thenif low < low[1] then// correction so update pivot high and buy pricehistoricMax = currentMaxbarHistoricMax = barCurrentMaxbuyPrice = historicMaxendifendifif high > historicMax then// update exit priceif barhistoricMax = 0 thenexitprice=min(lowbar0,lowest[barIndex - barHistoricMax](low) * (1 - exitFilter/100))elseexitPrice = lowest[barIndex - barHistoricMax](low) * (1 - exitFilter/100)endifendif// open position at new pivot highif not onmarket and buyPrice > 0 thenbuy positionSize cash at buyPrice stop // set buy stop orderendif// close position at exitPriceif onmarket and exitPrice > 0 thensell at exitPrice stop // set sell stop orderendif//graph exitPrice11/01/2016 at 12:56 AM #15797Thanks,
Checking it. I will be back soon. It looks good. I have seen a mistake but nothing important. What you did already is enough and i am grateful but i wonder if we can go one step beyond. Maybe privately if possible.
thanks again.
Nacho.
11/01/2016 at 1:52 PM #15818Hi Tikitaka, great job, thank you very much. I got already more than i thought. However have seen things to tweak if you feel like:
a) Sometimes there is a low<low[1] but the stop is not risen. It is because in the same candle we got a high>high[1]. Examples Citigroup (feb1993), Sabadell (may2016), ENGI(jan2008), ESRX (may2015).
b) Sometimes systems stops, i don´t know why, maybe is database, my computer, tell me if happens to you. Examples: British American Tobacco (from 2010 doesn´t give signals and we have new maximums), Next (NTX)(from 2011), Royal Dutch Shell(from 2012), Sabmiller (SAB from 2012).
c) System buys when prices is >= historical maximun and it should be >. In fact i normally put a filter of some cents. Example: Standard Chartered(STAN) (nov 2010).
I don´t know if i am going too far but taking advantage of your kindness i would ask you if you can:
1.-Code it for short positions. Same logic but for going short.
2.-What do i have to add and where, if i want to raise the stop to the entryprice+1% when prices reach 10% of profit. Something like:
123if longonmarket and high>=tradeprice*1,1 thensell at tradeprice*1.01else sell at exitprice stop3.-Change 2000 cash into shares following this formula: Number of shares will be (Equity line*0,6%)/(Entryprice-Stopprice) and if the result multipied by the price of the stock is less than 1000 don´t buy. Equityline is 50.000 when we start and later what i have in the equity line or equity curve (the result of add to 50.000 previous trades).
I imagine you running away after this post and i understand. The thing is that i don´t know if what i am asking you is difficult or not. If it is going to take you long forget it please, you have already did enough.
In fact you can forget a), b) and c) if it takes you time and pay attention to what is more important to me: 1) then 2) and finally 3). (I believe point 3 is the most difficult one and is the less important to me).
already gratefull, cheers
11/01/2016 at 1:54 PM #1581911/05/2016 at 9:22 PM #16019Hello, hello, hello. Many things.
Some anwers (the easiest ones):
b) That’s because its prices are > 2000, our capital in the code. No worries.
c) Yes, I was aware of the fact. We could use, if you agree:
1234// open position at new pivot highif not onmarket and buyPrice > 0 thenbuy positionSize cash at buyPrice+0.001 stop // set buy stop orderendifIn ProBacktest seems to work OK. I’m not utterly sure with real brokers, though.
.1) That will have to wait until the code for the long positions is good and clean.
2) A possible code (instead of lines 58 to 61):
123456789101112// close position at exitPriceonce newStop = 0 // better in the variables declarationif not onmarket thennewStop = 0 // reset newStopendifif onmarket and exitPrice > 0 thenif high >= tradeprice * 1.1 thennewStop = tradeprice * 1.01endifexitPrice = max(newStop, exitPrice)sell at exitPrice stop // set sell stop orderendifWaiting for your comments. For the rest, I’ll have to think about and possibly discuss int the Spanish forum.
Ciao
11/06/2016 at 7:19 PM #16042 -
AuthorPosts
Find exclusive trading pro-tools on