Candlestick calculation doesn’t seem to work
Forums › ProRealTime English forum › ProOrder support › Candlestick calculation doesn’t seem to work
- This topic has 9 replies, 4 voices, and was last updated 6 months ago by ATCOtrader.
-
-
06/05/2024 at 8:05 AM #233507
Hi,
This is my first post here! I’m trying to backtest an idea where I calculate and measure the different parts of the candlesticks. I want to calculate the lower wick and if it is bigger than the higher wick it’s an entry signal. However it doesent seem to be working, it gives random results. This is the code:
1234567891011121314151617181920212223body=close-openif body>0 thenbodytop=closebodybottom=openelsebodytop=openbodybottom=closeendifshadowtop=high-bodytopshadowbottom=bodybottom-lowHammer= Shadowbottom > ShadowtopExit= (BarIndex - TradeIndex) = 1IF Hammer THENBUY 1 CONTRACTS AT MARKETENDIFIf LongOnMarket THENSELL AT MARKETENDIFI have created an indicator with the same calculation of the wick and this seem to be working fine, see attached picture. You can also see in the attached picture that entries is not according to my expected behaviour. What am I missing?
Best regards
06/05/2024 at 9:27 AM #233521Hi. The problem with your code comes when you have two or more bars “hammer” type.
When a hammer bar appears the system buy 1 contract in the next bar open and sells after 1 bar.
If you have 2 consecutive hammer bars the second one doesn’t exits for the system.
In order to avoid it we can change the code like this:1234567891011IF Hammer and not onmarket THENBUY 1 CONTRACT AT MARKETENDIFif onmarket thenif hammer thenbuy 1 contract AT MARKETsell 1 contract at marketelsesell at marketENDIFendifif there are 3 consecutive candles with hammer type you should be on market 3 bars.
2 users thanked author for this post.
06/05/2024 at 9:27 AM #233522Is the Timeframe your displaying in image, the same as the running backtest code , image suggests no.
What was your expected behaviour for the result.
1 user thanked author for this post.
06/05/2024 at 10:44 AM #233524Thank you very much for your replies!
It still doesn’t seem to work though. The picture is the same timeframe as the backtest.
What I want to achieve is to have a backtest that buys when the wick under the body is x times as big as the wick above the body. I have updated my code with the input from above and also added the criteria that the wick under the body should be 3 times bigger than the one above in order for it to be easier to spot if it works or not.
candlesticks123456789101112131415161718192021222324252627body=close-openif body>0 thenbodytop=closebodybottom=openelsebodytop=openbodybottom=closeendifshadowtop=high-bodytopshadowbottom=bodybottom-lowHammer= Shadowbottom > 3 * ShadowtopExit= (BarIndex - TradeIndex) = 1IF Hammer and not onmarket THENBUY 1 CONTRACT AT MARKETENDIFif onmarket thenif hammer thenbuy 1 contract AT MARKETsell 1 contract at marketelsesell at marketENDIFendif06/05/2024 at 11:56 AM #233527Try this,
Comment out lines 15, 22 and 23 by placing // at the beginning of these lines
15. Exiting after 1 bar seems to go against staying in.
22,23 If in market, buying and then selling same qty is the same as staying in market at current qty.
25. Then only sell if in market and closing bar is not a hammer.
The logic appears to be ,
If not on market, Buy at Market on a Hammer,
If on market sell Market on NOT hammer
1 user thanked author for this post.
06/05/2024 at 1:55 PM #233538Thank you, I have tried this but with no luck. There seems to something else that is off… I have made the code even more basic to prove the point -> buy all times condition is met. Result is that the system is buying at correct points mostly but sometimes it’s off. Sometimes it indicates two orders same day but with different execution dates (see picture). There must be something that is not in sync?
candle123456789101112131415161718body=close-openif body>0 thenbodytop=closebodybottom=openelsebodytop=openbodybottom=closeendifshadowtop=high-bodytopshadowbottom=bodybottom-lowHammer= Shadowbottom > 3 * ShadowtopIF Hammer THENBUY 1 CONTRACT AT MARKETENDIF06/05/2024 at 3:30 PM #233548Hi,
What you show (two orders/day) probably only happens on Friday…?
1 user thanked author for this post.
06/05/2024 at 4:07 PM #233551Yes, that is correct – it’s on a friday. Why is it that way? It shows entry the date day after (saturday), that must be wrong?
06/05/2024 at 4:13 PM #233552Hi,
Is IG that is “out of sync”…
IG has a very nasty “Sunday candle”…
What happens is: buy on Friday and then again on Sunday and then again on Monday… And when the option “don’t show weekend dates” is enabled, then the Sunday order shifts to Friday, hence the two orders on one day…
1 user thanked author for this post.
06/05/2024 at 4:53 PM #233557Thank you very much for that insight, explaines a whole lot for my strategies.. Thanks again!
1 user thanked author for this post.
-
AuthorPosts