MTF code trouble.
Forums › ProRealTime English forum › ProBuilder support › MTF code trouble.
- This topic has 11 replies, 3 voices, and was last updated 2 years ago by druby.
-
-
07/13/2022 at 5:48 PM #197240123456789101112131415161718Timeframe (1week,updateonclose)If(((range[1])+(range[2])+(range[3])+(range[4]))/4)< range[1] thenWsignal = -1elseWsignal = 0endifTimeframe (Daily)If(((range[1])+(range[2])+(range[3])+(range[4]+(range[5])))/5)< range thenDsignal = 1elseDsignal = 0endifreturn Wsignal, Dsignal
Hi All,
I am trying to code something simple indicator that shows the following on a Daily chart.
Weekly signal if the average range of the last 4 weeks is less than the range of the last week. (This signal should be valid for the whole next week).
Daily signal if the range of the last 5 days is less than the range of today.
If both of those are true then I get my signal.
The problem I am having is that although I have coded it several different ways I keep getting false readings when I put them together. I can put the weekly indicator on a weekly chart and it is correct but when I put it in combination with the daily signal on a daily chart it does not show correctly.
What am I doing wrong?
07/13/2022 at 5:58 PM #197241In line 3 you need to remove [1] from the rightmost RANGE, as UpdateOnClose grants it’s always the LAST closed candle, not the current one.
In line 12 the rightmost RANGE has no brackets and will refer to the current candle.1 user thanked author for this post.
07/13/2022 at 8:55 PM #197249Thank you Roberto,
Now the only problem I have is the weekly signal doesn’t got from Monday to Friday, but goes from Friday to Thursday. How do I rectify that?
Or maybe a better question is how would you code all this? I am new to this and trying to learn but I have a suspicion that my coding is not good 🙁07/15/2022 at 10:55 AM #197318I am not experiencing that issue.
07/15/2022 at 11:20 AM #197319That’s odd. Here is a screenshot, the weekly indicator goes from Friday to Thursday. However I have fiddled with it and if I return Wsignal[1], then it goes correctly from Monday to Friday. But I don’t understand why it is doing that??
Sorry to be a pain but could you explain it to me.
07/15/2022 at 11:30 AM #197321As you can see from the attached pics, it works fine for me.
Try contacting ProRealTime.
07/15/2022 at 11:58 AM #197325123456789101112131415161718Timeframe (1week,updateonclose)If(((range[1])+(range[2])+(range[3])+(range[4]+range[5]))/5)< range thenWsignal = -1elseWsignal = 0endifTimeframe (Daily)If(((range[1])+(range[2])+(range[3])+(range[4]+(range[5])))/5)< range thenDsignal = 1elseDsignal = 0endifreturn Wsignal, DsignalI get exactly that when I do it separately on daily and weekly charts like you have. the problem occurs when I put them together in one indicator.
07/15/2022 at 5:17 PM #197330Do you have free charts which are 1 bar behind? This might be source of your issue.
07/16/2022 at 1:31 AM #197334hi… had a look at your code to see if I could see any problems other than your love of ‘brackets’!
Couldn’t see anything other than the ‘brackets’, and the differences of line 3 and it seemed to work for me.
In trying to understand and verify it was correct I created an alternate version, while debugging, with line plots to see, when the range’s crossed over the average’s, the bar’s were in the right position. Also I wonder about using the stock average function, so I incorporated that in as well to compare with manual calculated version. This gave the added benefit of changing the average type to EMA and other’s. Then there were a few only things and then four hour’s later…
By adding 4 identical indicators and using different setting for each, see pic panel labels, you can see whats happening and make a comparison. When lines cross and different average’s. One thing I did find interesting, is the 5 daily values for the average calculation required a value of ‘6’ in the average function to make them the same, not sure why yet.
The variables in settings, ‘page’ switches between line/bar, ‘choice’ between manual/stock average calculation, ‘aveType’ set the type of average, ‘avetext’ turns on/off text for number type of ‘aveType’
Pic 1 shows price, and 2 sets of similar panels. The top 2 show the range/average range lines and the bars of the manual calculated SMA version while the bottom 2, are the same but using the Average function. Pic 2 is similar but the bottom 2 are set to ema.
The code file below is what I ended up with. When importing it should set the dynamic variable’s if not there listed at the top of the code. I’ve hard coded the colors and styles so it should look good out of the box, but there an alternate RETURN statement you can switch between if you want to set them in the indicator settings.
1 user thanked author for this post.
07/19/2022 at 8:54 AM #19749007/19/2022 at 9:13 AM #197492@druby Thank you.
I thank you for your generosity with your time,(when I see your code, I understand my bracket addiction, (ha)*2)
Your answer definitely falls into the category of being careful what you ask for .Just starting to code and it has taken me a couple of days just to begin understand it!1 user thanked author for this post.
07/19/2022 at 10:01 AM #197495Thanks a lot for your comments, your welcome.
Just came across this in a code file I wrote, here’s the bit I wan’t to point out. Good reminder!
The code help me understand ‘Round, Ceil, and ‘Floor’ commands and just posted else where, see link,. Also stuff regarding anchoring text, when you get wound up at that stage.
https://www.prorealcode.com/topic/affichage-ema-200-sur-ut-15-et-15-mn/
Best regards
123456789101112131415161718192021222324// Life's notes:// Nobody's perfect - question everything.// Why!, because the answer is only as good as the question.// e.g.// Question - Pick a number between 1 and 5 .// Thoughts - Did you pick a number.// - If you did, was it of type integer, decimal,...// - Was it in the number system form of denary, binary, hexadeciamal,...// - Are you shaking your head, in dis-belief// - Are you holding a number of fingers up at me.// - Other relavent criteria and responses.// New Question - Pick a integer number in denary form between 1 and 5, and tell me.// New thoughts - Does 'between', exclude '1' and '5', because their not between!// - Are you shaking your head, in dis-belief// - Are you holding a number of fingers up at me.// New Question - Pick a integer number in denary form between and including 1 and 5, and tell me// New thoughts - - Maybe there's other relavent criteria and responses to take into acount// Answer '3' -
AuthorPosts
Find exclusive trading pro-tools on