MTF code trouble.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #197240 quote
    blackwing
    Participant
    New

     

    Timeframe (1week,updateonclose)
    
    If(((range[1])+(range[2])+(range[3])+(range[4]))/4)< range[1] then
    
    Wsignal = -1
    else
    Wsignal = 0
    endif
    
    Timeframe (Daily)
    
    If(((range[1])+(range[2])+(range[3])+(range[4]+(range[5])))/5)< range then
    
    Dsignal = 1
    else
    Dsignal = 0
    endif
    return 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?

    #197241 quote
    robertogozzi
    Moderator
    Master

    In 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.

    blackwing thanked this post
    #197249 quote
    blackwing
    Participant
    New

    Thank 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 🙁

    #197318 quote
    robertogozzi
    Moderator
    Master

    I am not experiencing that issue.

    #197319 quote
    blackwing
    Participant
    New

    That’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.

    #197321 quote
    robertogozzi
    Moderator
    Master

    As you can see from the attached pics, it works fine for me.

    Try contacting ProRealTime.

    #197325 quote
    blackwing
    Participant
    New
    Timeframe (1week,updateonclose)
    
    If(((range[1])+(range[2])+(range[3])+(range[4]+range[5]))/5)< range then
    
    Wsignal = -1
    else
    Wsignal = 0
    endif
    
    Timeframe (Daily)
    
    If(((range[1])+(range[2])+(range[3])+(range[4]+(range[5])))/5)< range then
    
    Dsignal = 1
    else
    Dsignal = 0
    endif
    return Wsignal, Dsignal
    

    I 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.

    #197330 quote
    robertogozzi
    Moderator
    Master

    Do you have free charts which are 1 bar behind? This might be source of your issue.

    #197334 quote
    druby
    Participant
    New

    hi…   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’

    [attachment file=”197335″]

    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.

    [attachment file=”197336″]

    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.

    blackwing thanked this post
    #197490 quote
    blackwing
    Participant
    New

    No I don’t think so. It works fine when just using a single timeframe.

    #197492 quote
    blackwing
    Participant
    New

    @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!

    druby thanked this post
    #197495 quote
    druby
    Participant
    New

    Thanks 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

    // 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'
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

MTF code trouble.


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
blackwing @blackwing1 Participant
Summary

This topic contains 11 replies,
has 3 voices, and was last updated by druby
3 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/13/2022
Status: Active
Attachments: 7 files
Logo Logo
Loading...