Script assistance please

Optuma Forums Optuma Scripting Script assistance please

This topic contains 15 replies, has 2 voices, and was last updated by Avatar Karen 2 weeks, 3 days ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #54667
    Avatar
    Karen
    • Topics: 9
    • Replies: 17
    • Posts: 26

    Hi, I am not sure why this coding is not working for the code AC8. Can someone please help on a weekly chart.

    (if((BARCOUNT()>=200), ((CLOSE() > MA(BARS=100, STYLE=Simple)) or (CLOSE() > MA(BARS=200, STYLE=Simple))),(CLOSE() > MA(BARS=100, STYLE=Simple))))

     

    I am trying to show a bar where there are more than 200 weekly bars where close is either higher that the 100MA or 200MA and if there are less than 200 weekly bars I am trying to show a bar for where the close is higher than the weekly 100MA.  Nothing is being plotted on my chart when I believe it should be showing the show bars.

    When I apply the formulas separately ie

    ((CLOSE() > MA(BARS=100, STYLE=Simple)) or (CLOSE() > MA(BARS=200, STYLE=Simple))) shows the bar when there are more than 200 bars; and

    CLOSE() > MA(BARS=100, STYLE=Simple) shows the bar when there are more than 100 bars

    but when combined in the function they do not work – I am trying to get the combined effect using the if function but instead no show bars are showing at the beginning of the chart.

    Can someone please let me know what I am doing wrong. Thanks.

    Karen

    #54671
    Avatar
    Trevor R
    • Topics: 51
    • Replies: 155
    • Posts: 206

    Hi Karen,

    when chasing these types of problems I break each part down into individual scripts. So using your scripts I can to V1, V2 and V3 = (V1 or V2). I then apply each individual script to SHOWBARs and here is the chart with them all on:

    20190914 Karen's Ticket #54667

    The final v3 (the magenta SHOWBAR) script is:

    The workbook with the individual scripts is attached.

    Cheers

    Trevor

    Attachments:
    #54685
    Avatar
    Karen
    • Topics: 9
    • Replies: 17
    • Posts: 26

    Thanks for that. The problem I was actually having was when there are less than 200 bars which is the case for the code AC8 (ASX) on a weekly chart the arrows were not showing up when I combined the formula and was using the Barcount function yet they were when I did the formulas individually. Can you please assist with that formula?

    Thanks,

    Karen

    #54687
    Avatar
    Trevor R
    • Topics: 51
    • Replies: 155
    • Posts: 206

    Hi Karen,

    Please post the script code you are trying to use, otherwise we are only guess at what you are trying to do.

    Cheers

    Trevor

    #54723
    Avatar
    Karen
    • Topics: 9
    • Replies: 17
    • Posts: 26

    Hi I posted it above in my first line of code.

    (if((BARCOUNT()>=200), ((CLOSE() > MA(BARS=100, STYLE=Simple)) or (CLOSE() > MA(BARS=200, STYLE=Simple))),(CLOSE() > MA(BARS=100, STYLE=Simple))))

     

    Thanks,

    Karen

    #54725
    Avatar
    Karen
    • Topics: 9
    • Replies: 17
    • Posts: 26

    Further to the email above I have attached 3 charts of AC8.

    1. The left chart I have tried to use show bars to calculate how many bars there are in the weekly graph. I used the formula: (if((BARCOUNT()>=200),BARCOUNT(),0))                             Clearly there are 314 bars (ie more than 200).  I don’t think the results coming back are correct – I would have thought that it would have counted up from 1 to 114 straight after the first 200 bars.  Also from the time price label you can see that the count of the bars are clearly more than 200 bars.
    2. The middle chart I have then used the same formula in the show bar as above: (if((BARCOUNT()>=200),1,0)) and instead have drawn an arrow where the 314 was showing in the first chart. This isn’t correct – it should show an arrow for 114 bars after the first 200 bars.
    3. <li style=”text-align: left;”>The third chart I have used in the show bar formula: (if((BARCOUNT()>=200), ((CLOSE() > MA(BARS=100, STYLE=Simple)) or (CLOSE() > MA(BARS=200, STYLE=Simple))),(CLOSE() > MA(BARS=100, STYLE=Simple))))                                    This formula brings back no bars.

    Please let me know what I am doing wrong as I don’t think the formulas are working properly and I cannot understand why the results are coming back the way they are.

    Ultimately I am trying to get the formula in item 3 to work but if the formulas in item 1 and 2 are not working then the formula in item 3 will not work. Please assist with this.

    Thanks,

    Karen

    #54727
    Avatar
    Karen
    • Topics: 9
    • Replies: 17
    • Posts: 26

    File attached

    File attached.

    Attachments:
    #54731
    Avatar
    Trevor R
    • Topics: 51
    • Replies: 155
    • Posts: 206

    Hi Karen,

    The first problem is I think you misunderstand what the BARCOUNT() function does.

    As stated in the Knowledge Base article https://help.optuma.com/kb/faq.php?id=961 describing the function it “will return either the total number of data bars that are available for a symbol, or the total number of bars on the screen at the time“.  Thus your script (if((BARCOUNT()>=200),BARCOUNT(),0)) will return the total number of bars in the code, that the 314 Bars on the Weekly Chart of AC8. If you apply that script to a SHOWVIEW it reflects that result.

    Your script (if((BARCOUNT()>=200),1,0)) will, because the BARCOUNT is greater than 200, return a result of 1. However, if you change the 200 to 400 you’ll find it return 0, which is to be expected as the BARCOUNT = 314. Again, using a SHOWVIEW will demonstrate this.

    So, I conclude that using BARCOUNT is not the appropriate function for what you are attempting to achieve, which I understand from your first post to be:

    Show those bars bars that:

    1      occur after the signal of a Close crossing above, and remaining above, the MA200 for longer than 200 bars, ie the first SHOWBAR will be 200 Bars past the first Close above the MA200 and SHOWBARS will show for all Bars thereafter until the Close crosses below the MA200, or

    2     occur after the signal of a Close crossing above, and remaining above, the MA 100 for longer than 200 bars, ie the first SHOWBAR will be 200 Bars past the first Close above the MA100 and SHOWBARS will show for all Bars thereafter until the Close crosses below the MA100, and

    if that criteria is not met then show those bars less than 200 bars that:

    3     occur after the signal of a Close crossing above, and remaining above, the MA 100 for less than 200 bars, ie the first SHOWBAR will be signal the first Close above the MA100 and SHOWBARS will show for all Bars thereafter until the Close crosses below the MA100

    The following script applies the criteria 1 and 2 above with the result shown in the first chart below (Note: I’ve use Daily Charts, the criteria are not met on a Weekly Chart):

     

    20190922 -1 Karen's Ticket 54667

    Adding the 3rd criteria listed above results in this script, which produces the result on the chart below:

    20190922 -2 Karen's Ticket 54667

    Is that what you are looking for Karen?

    Cheers

    Trevor

    #54749
    Avatar
    Karen
    • Topics: 9
    • Replies: 17
    • Posts: 26

    Thanks Trevor, I’ll have to work through the formula.  The key for me was what function do I use to count the number of bars since a stock has listed (but not just the current bar)? ie I would want the 1st bar to show a number of 1 using the show bar, the 2nd bar to show the number of 2 etc. ie I want the BARCOUNT() function to be able to effectively apply to each bar from listing not just the current bar.

    Is the relevant function COUNTMATCHSINCESIGNAL to do that?

    Thanks,

    Karen

    #54755
    Avatar
    Trevor R
    • Topics: 51
    • Replies: 155
    • Posts: 206

    Hi Karen,

    I’m unsure as to exactly what the result is that you are looking to see. You haven’t mentioned if the script I given you thus far is going some way towards the result you desire. Can you manually annotate a chart to provide a picture of how you are expecting the Showbars from the script is to be displayed and numbered. You know the old saying ” A picture is worth a thousand words”.

    Cheers

    Trevor

     

    #54797
    Avatar
    Karen
    • Topics: 9
    • Replies: 17
    • Posts: 26

    Hi Trevor, I’m just looking for the function that would return a number for each bar (including the current day’s bar) for what number bar it is from the date the stock listed.  I understand that BARCOUNT() function only works for the current bar so what function will I need to use to get a number returned for each bar? Please see attached chart for what I mean.

    Thanks again,

    Karen

    #54799
    Avatar
    Karen
    • Topics: 9
    • Replies: 17
    • Posts: 26

    Please see attached chart.

    Attachments:
    #54807
    Avatar
    Trevor R
    • Topics: 51
    • Replies: 155
    • Posts: 206

    Hi Karen,

    Now I understand what you are looking for – the actual bar number from the start of the chart data, I would call this the BARNUMBER.

    Unfortunately as I understand the situation at present there is no BARNUMBER function within the Scripting module, which is the data you, and I from time too time, are looking for. (It is data available in the Optuma Programming Module, if you are into Pascal programming.) The nearest you can get at present is the BARDATE, which might do what you want to try, but be careful because BARDATE returns the date and when used to calculate periods between dates the result includes weekends and holidays, ie the result is “calendar days”, not the number of Bars.

    I’ve run into the need  for a BARNUMBER function from time to time in my script creation, including one script I was working on yesterday, so I’ve asked for it on the Optuma Feature Requests Forum. You might like to support that request of mine.

    Cheers

    Trevor

    #54809
    Avatar
    Karen
    • Topics: 9
    • Replies: 17
    • Posts: 26

    Hi Trevor, thanks for your reply. Yes I think it would be a good idea that the function exist as it does in other packages and without it makes it difficult to calculate basic equations.

    How do we go about getting Optuma to develop that function quickly as it can’t be that difficult to do if t is just counting the number of bars from the listing date? Will they read this post or do we need to submit it elsewhere?

    Thanks,

    Karen

    #54813
    Avatar
    Trevor R
    • Topics: 51
    • Replies: 155
    • Posts: 206

    Hi Karen,

    I see you’ve supported my request on the Feature Requests Forum. I’m sure the smart Optuma Guys will see it there and respond appropriately.

    Cheers

    Trevor

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.

Pin It on Pinterest

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close