ProRealCode - Trading & Coding with ProRealTime™
Attached are results for Roberto version code
But Roberts code still has the conditions looking at the wrong candles.
It works good on high TF’s. On DAX Daily it yields good profits, but only 6 trades in 8 years!
I have something to point out:
I mean, maybe you should rethink it a bit… make some changes, or even drop it (I have about 30 running strategies on demo, but I have coded a few hundreds, my trash bin is FULL).
you never care about the current candle, but THAT is the entry price at which your trade will open.
I think we established earlier on that the OP misunderstood how the candle indexing system worked and did not realise that the most recently closed candle was candle zero. However I have modified his code to look at what I believe are the candles he wanted to look at and also changed the indexing in the SL and TP calculations and it still does not work very well. Losses on fast time frames and barely any trades on slower time frames.
Here’s the current code as I think that the System should work:
DEFPARAM CumulateOrders = false
//Buy-Condition l1: Kerze vor 3 Perioden muss bullish sein und es müssen 3 Kerzen mit tieferen Hochs und tieferen Tiefs folgen und der Schlusskurs der vorherigen Kerze muss größer sein als der Schlusskurs der ersten Kerze
l1 = OPEN[2] < CLOSE[2] AND High[2] > High [1] AND High[1] > High AND Low[2] > Low[1] AND Low[1] > Low AND Close >= Close[2]
//Buy-Condition l2: Kerze vor 3 Perioden muss bearish sein und es müssen 3 Kerzen mit tieferen Hochs und tieferen Tiefs folgen und der Schlusskurs der vorherigen Kerze ist größer als das Open der ersten Kerze
l2 = OPEN[2] > CLOSE[2] AND High[2] > High [1] AND High[1] > High AND Low[2] > Low[1] AND Low[1] > Low AND Close >= Open[2]
//Sell-Condition s1: Kerze vor 3 Perioden muss bullish sein und es müssen 3 Kerzen mit höheren Hochs und höheren Tiefs und der SK der vorherigen Kerze ist kleiner als der SK's der ersten Kerze, wenn der SK von Kerze 1 kleiner als das Close ist
s1 = OPEN[2] < CLOSE[2] AND High[2] < High [1] AND High[1] < High AND Low[2] < Low[1] AND Low[1] < Low AND Close <= Close[2]
//Sell-Condition s2: Kerze vor 3 Perioden muss bearish sein und es müssen 3 Kerzen mit höheren hoch und hheren Tiefs und der SK der vorherigen Kerze ist kleiner als der SK's der ersten Kerze, wenn der SK von Kerze 1 kleiner als das Close ist
s2 =OPEN[2] > CLOSE[2] AND High[2] < High [1] AND High[1] < High AND Low[2] < Low[1] AND Low[1] < Low AND Close <= Open[2]
//Kauforder zur Eröffnung der nächsten Kerze wenn Konditionen l1 oder l2 erfüllt sind
IF l1 OR l2 AND Not OnMarket THEN //Not OnMarket will prevent SL & TP to be recalculated
SL = (close - low[1]) //difference between current price and LOW of candle 1
TP = (high[3] - close) //difference between the HIGH of candle 3 and current price (a lower current price is assumed)
BUY 1 SHARES AT MARKET //NextBarOpen
SET STOP LOSS SL
SET TARGET PROFIT TP
ENDIF
//Verkauforder zur Eröffnung der nächsten Kerze wenn Konditionen s1 oder s2 erfüllt sind
IF s1 OR s2 AND Not OnMarket THEN //Not OnMarket will prevent SL & TP to be recalculated
SL = (high[1] - close) //difference between current price and HIGH of candle 1
TP = (close - low[3]) //difference between the LOW of candle 3 and current price (a higher current price is assumed)
SELLSHORT 1 SHARE AT MARKET //NextBarOpen
SET STOP LOSS SL
SET TARGET PROFIT TP
ENDIF
did not realise that the most recently closed candle was candle zero.
but we say Close[1] when we want close of the most recently closed candle?? Or have I had it wrong all the time??? 🙂
did not realise that the most recently closed candle was candle zero.
but we say Close[1] when we want close of the most recently closed candle?? Or have I had it wrong all the time??? 🙂
The most recently closed candle is [0], or no brackets at all, (close, high, low, open, range,….), usually it is called the SETUP CANDLE.
Current Candle is always 0…this means that my calculations are based on candles 2,1,0…if condition is met market order is placed and SL/TP are calculated and linked to open position…
I have to rechek if the code is okay…I found a bug
Does this mean that my SL and TP are calculated based when postion is entered?
As an example:
candle 2,1,0 meet the condition and position will be opened on next candle…
for better understanding
candle 2 is now candle 3,
candle 1 is now candle 2,
candle 0 is now candle 1
and candle 0 is the one in which TPP and SL must be calculated…
Am I right?
I think that there is still abug within the code, but here an amended version
DEFPARAM CumulateOrders = false
//Buy-Condition l1: Kerze vor 3 Perioden muss bullish sein und es müssen 3 Kerzen mit tieferen Hochs und tieferen Tiefs folgen und der Schlusskurs der vorherigen Kerze muss größer sein als der Schlusskurs der ersten Kerze
l1 = OPEN[2] < CLOSE[2] AND High[2] > High [1] AND High[1] > High AND Low[2] > Low[1] AND Low[1] > Low AND Close >= Close[2]
//Buy-Condition l2: Kerze vor 3 Perioden muss bearish sein und es müssen 3 Kerzen mit tieferen Hochs und tieferen Tiefs folgen und der Schlusskurs der vorherigen Kerze ist größer als das Open der ersten Kerze
l2 = OPEN[2] > CLOSE[2] AND High[2] > High [1] AND High[1] > High AND Low[2] > Low[1] AND Low[1] > Low AND Close >= Open[2]
//Sell-Condition s1: Kerze vor 3 Perioden muss bullish sein und es müssen 3 Kerzen mit höheren Hochs und höheren Tiefs und der SK der vorherigen Kerze ist kleiner als der SK's der ersten Kerze, wenn der SK von Kerze 1 kleiner als das Close ist
s1 = OPEN[2] < CLOSE[2] AND High[2] < High [1] AND High[1] < High AND Low[2] < Low[1] AND Low[1] < Low AND Close <= Close[2]
//Sell-Condition s2: Kerze vor 3 Perioden muss bearish sein und es müssen 3 Kerzen mit höheren hoch und hheren Tiefs und der SK der vorherigen Kerze ist kleiner als der SK's der ersten Kerze, wenn der SK von Kerze 1 kleiner als das Close ist
s2 =OPEN[2] > CLOSE[2] AND High[2] < High [1] AND High[1] < High AND Low[2] < Low[1] AND Low[1] < Low AND Close <= Close[2]
//Kauforder zur Eröffnung der nächsten Kerze wenn Konditionen l1 oder l2 erfüllt sind
IF l1 OR l2 AND Not OnMarket THEN //Not OnMarket will prevent SL & TP to be recalculated
SL = (close - low[1]) //difference between current price and LOW of candle 1
TP = (high[3] - close) //difference between the HIGH of candle 3 and current price (a lower current price is assumed)
BUY 1 SHARES AT MARKET //NextBarOpen
SET STOP LOSS SL
SET TARGET PROFIT TP
ENDIF
//Verkauforder zur Eröffnung der nächsten Kerze wenn Konditionen s1 oder s2 erfüllt sind
IF s1 OR s2 AND Not OnMarket THEN //Not OnMarket will prevent SL & TP to be recalculated
SL = (high[1] - close) //difference between current price and HIGH of candle 1
TP = (close - low[3]) //difference between the LOW of candle 3 and current price (a higher current price is assumed)
SELLSHORT 1 SHARE AT MARKET //NextBarOpen
SET STOP LOSS SL
SET TARGET PROFIT TP
ENDIF
Current Candle is always 0…
Yes, but we have to exactly define what CURRENT means, NOT the candle being formed since it cannot be accessed, but the MOST RECENTLY closed one!
Even with MTF support candles can only be accessed at CLOSING time, the only advantage is that we can use lower TF’s to access data while the candle in the bigger picture is being formed!
So, to recap, [0], or no brackets at all, references the most recenty closed candle.
At lines 16-17, 25-26, SL & TP are calculated on CLOSE (or CLOSE[0]). It will become [1] when the new one (where a trade has been opened) will close thus becoming [0] itself. Whenever a candle closes there’s a shift in the numbering (referencing) system, so that [0] ALWAYS references the most recently closed one! That’s the reason you have to calculate SL & TP only once when entering a trade, otherwise they (since they reference CLOSE) would be recalculated each new bar!
I think that this code is now correct:
DEFPARAM CumulateOrders = true
//Buy-Condition l1: Kerze vor 3 Perioden muss bullish sein und es müssen 3 Kerzen mit tieferen Hochs und tieferen Tiefs folgen und der Schlusskurs der vorherigen Kerze muss größer sein als der Schlusskurs der ersten Kerze
l1 = OPEN[2] < CLOSE[2] AND High[2] > High [1] AND High[1] > High AND Low[2] > Low[1] AND Low[1] > Low AND Close >= Close[2]
//Buy-Condition l2: Kerze vor 3 Perioden muss bearish sein und es müssen 3 Kerzen mit tieferen Hochs und tieferen Tiefs folgen und der Schlusskurs der vorherigen Kerze ist größer als das Open der ersten Kerze
l2 = OPEN[2] > CLOSE[2] AND High[2] > High [1] AND High[1] > High AND Low[2] > Low[1] AND Low[1] > Low AND Close >= Open[2]
//Sell-Condition s1: Kerze vor 3 Perioden muss bullish sein und es müssen 3 Kerzen mit höheren Hochs und höheren Tiefs und der SK der vorherigen Kerze ist kleiner als der SK's der ersten Kerze, wenn der SK von Kerze 1 kleiner als das Close ist
s1 = OPEN[2] < CLOSE[2] AND High[2] < High [1] AND High[1] < High AND Low[2] < Low[1] AND Low[1] < Low AND Close <= Close[2]
//Sell-Condition s2: Kerze vor 3 Perioden muss bearish sein und es müssen 3 Kerzen mit höheren hoch und hheren Tiefs und der SK der vorherigen Kerze ist kleiner als der SK's der ersten Kerze, wenn der SK von Kerze 1 kleiner als das Close ist
s2 =OPEN[2] > CLOSE[2] AND High[2] < High [1] AND High[1] < High AND Low[2] < Low[1] AND Low[1] < Low AND Close <= Close[2]
//Kauforder zur Eröffnung der nächsten Kerze wenn Konditionen l1 oder l2 erfüllt sind
IF l1 OR l2 AND Not OnMarket THEN //Not OnMarket will prevent SL & TP to be recalculated
SL = (close[1] - low[1]) //difference between current price and LOW of candle 1
TP = (high[3] - close[1]) //difference between the HIGH of candle 3 and current price (a lower current price is assumed)
BUY 1 SHARES AT MARKET //NextBarOpen
SET STOP LOSS SL
SET TARGET PROFIT TP
ENDIF
//Verkauforder zur Eröffnung der nächsten Kerze wenn Konditionen s1 oder s2 erfüllt sind
IF s1 OR s2 AND Not OnMarket THEN //Not OnMarket will prevent SL & TP to be recalculated
SL = (high[1] - close[1]) //difference between current price and HIGH of candle 1
TP = (close[1] - low[3]) //difference between the LOW of candle 3 and current price (a higher current price is assumed)
SELLSHORT 1 SHARE AT MARKET //NextBarOpen
SET STOP LOSS SL
SET TARGET PROFIT TP
ENDIF
the coments within this codes must be amended from my side….
So, to recap, [0], or no brackets at all, references the most recenty closed candle.
When I use Close (same as Close[0] ) I always thought I was referring to the current / latest price of the candle which is currently forming?
When I want to refer to the close of the most recently closed / ended / finished candle I use Close[1]?
Am I correct or incorrect or have I only read half the above and I am talking at cross-purposes / confusing myself?
I will in any case use Graph to check out my assertions. Kinda basic / worrying I / we are discussing this … no wonder I’m not making any money on my Auto-Systems!!!!!????? 🙂 🙂
I am talking at cross-purposes / confusing myself?
I am confusing myself and I have been right all along!
It’s surprising, being a recent new coder and now having a break for a month or two basic assertions start to slip away.
Close / Close[0] is the current price (if bar not closed) OR closing price of the bar that just closed / same bar which caused my code to just be read (at the end of each closed bar).
If I want to refer to the close of the bar that closed immediately prior to this latest bar then it is Close[1].
Sheeesh … I think I’ll stick to my building and cars at least I can see what is going on!!! haahahaha
I think that some of the confusion may be due to the difference between coding an indicator compared to coding a strategy. In an indicator code bar[0] is the currently forming bar and in strategies it is the last closed bar due to the fact that a strategy does everything at the bar close and indicators change their output values on the fly and so do not wait for bar[0] to be closed.
Hi together,
As I can see there are still some issues.
I will try to handle these bugs during the weekend.
Rgds
Marc
Aloha @all,
Last question for my understanding…
I think it’s quite a little bit to hard for me to understand which candle is necessary for market entry…
I have three candle which have to meet conditions to form an entry. When conditions are correct than a market order incl. SL/TP are placed.
Perhaps attached image shows the way of calculation…and somebody can tell me/us the correct way of calculating.
Gracias
3 Candle Strategy
This topic contains 82 replies,
has 6 voices, and was last updated by Regan2020
6 years, 2 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 07/25/2018 |
| Status: | Active |
| Attachments: | 23 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.