logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages12>
Options
Go to last post Go to first unread
WmWaster  
#1 Posted : Sunday, April 16, 2006 6:51:51 PM(UTC)
WmWaster

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/20/2006(UTC)
Posts: 53

Hi. 1) Does anyone know any formula which can calculate how a stock reacts over a period of time when the market is moving: - up - sideway (eg within +/-0.3%) - down ?? 2) Beta Formula I receive the following error - "Division by zero: 938" My formula is as follows: [code:1:079ceb090b] Period:=Input("Period:",1,9999,21); SecurityA:=Security("[i][color=blue]file_location[/color][/i]",C); ((Period * Sum(ROC(C,1,%) * ROC(SecurityA,1,%),Period))- (Sum(ROC(C,1,%),Period) * Sum(ROC(SecurityA,1,%),Period))) / ((Period * Sum(Pwr(ROC(SecurityA,1,%),2),Period)) - Pwr(Sum(ROC(SecurityA,1,%),Period),2)) [/code:1:079ceb090b] What's up? :evil: Thank you. :)
wabbit  
#2 Posted : Sunday, April 16, 2006 7:25:56 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
WmWaster wrote:
I receive the following error - "Division by zero: 938" What's up?
Well I'd say, at a guess, the denominator portion of your code returns a value o zero 938 times! Try this instead: --8<------------------------ Period:=Input("Period:",1,9999,21); SecurityA:=Security("file_location",C); num:=((Period * Sum(ROC(C,1,%) * ROC(SecurityA,1,%),Period)) - (Sum(ROC(C,1,%),Period) * Sum(ROC(SecurityA,1,%),Period))); den:=Max(0.00001,((Period * Sum(Pwr(ROC(SecurityA,1,%),2),Period)) - Pwr(Sum(ROC(SecurityA,1,%),Period),2))); num/den; --8<------------------------ wabbit :D
wabbit  
#3 Posted : Sunday, April 16, 2006 7:37:20 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
or even speed it up a little bit by reducing the number of computations.... --8<------------------------- prd:=Input("Period:",1,9999,21); thisSec:=ROC(C,1,%); SecA:=ROC(Security("file_location",C),1,%); num:=(prd*Sum(thisSec*SecA,prd)) - (Sum(thisSec,prd)*Sum(SecA,prd)); den:=Max(0.00001,(prd*Sum(Pwr(SecA,2),prd)) - Pwr(Sum(SecA,prd),2)); num/den; --8<------------------------- wabbit :D
WmWaster  
#4 Posted : Sunday, April 16, 2006 7:43:42 PM(UTC)
WmWaster

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/20/2006(UTC)
Posts: 53

Thanks. But it seems the formula doesn't work fine. The situation is as follows: - When I just open the chart and apply this indicator, the indicator works fine (see 2nd graph - a.gif). - But if I change the loaded dates (of the data), the indicator will get screwed up (see 1st graph - b.gif). It won't help even if I switch back to the same set of loaded dates. I need to close and reopen the chart, attach the indicator to make it work again (returns to a.gif). What's wrong with the formula? It seems to have some bugs. #-o
wabbit  
#5 Posted : Sunday, April 16, 2006 8:48:48 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Don't quote me on this, but I think you will find the error is caused when the chart is opened and the indicator applied, MS gets the values of the data from the open chart and the Security() values, but only for the dates that are common in both data sets. If you modify the dates then you are changing the relationship between the two data files, and I believe the only way to cure this is to either set the x-axis properties back to default , or close and re-open the chart. On the other hand, why are you changing the data periods?? If you know it causes a problem, then don't do it! BTW - after several attempts, I could only generate the error once! wabbit :D
WmWaster  
#6 Posted : Sunday, April 16, 2006 9:37:50 PM(UTC)
WmWaster

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/20/2006(UTC)
Posts: 53

wabbit wrote:
Don't quote me on this, but I think you will find the error is caused when the chart is opened and the indicator applied, MS gets the values of the data from the open chart and the Security() values, but only for the dates that are common in both data sets. If you modify the dates then you are changing the relationship between the two data files, and I believe the only way to cure this is to either [color=red:5e72ea8749]set the x-axis properties back to default [/color], or close and re-open the chart.
The solution marked as red won't work. Once change, the indicator will be always void. :( This behaviour doesn't seemingly justify the explanation. If the security() value just contains the default data sets, it should work again when I change back to the default dates. The workaround is to reopen the chart & reapply the indicator, as said in my previous post. I wonder the same problem might occur if I change some other things too. But I've to check for sure about that.
Quote:
On the other hand, why are you changing the data periods?? If you know it causes a problem, then don't do it!
I have many templates, and I apply templates to open my charts. Very often the default dates are wrong :evil: and I need correct them.
Quote:
BTW - after several attempts, I could only generate the error once!
Hmm... So you can get it work even when you change the loaded dates?! If so, that's strange since I can reduplicate this bug all the time. Does it mean it's just the problem of my computer? #-o
WmWaster  
#7 Posted : Sunday, April 16, 2006 9:56:31 PM(UTC)
WmWaster

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/20/2006(UTC)
Posts: 53

wabbit wrote:
--8<------------------------ Period:=Input("Period:",1,9999,21); SecurityA:=Security("file_location",C); num:=((Period * Sum(ROC(C,1,%) * ROC(SecurityA,1,%),Period)) - (Sum(ROC(C,1,%),Period) * Sum(ROC(SecurityA,1,%),Period))); den:=Max(0.00001,((Period * Sum(Pwr(ROC(SecurityA,1,%),2),Period)) - Pwr(Sum(ROC(SecurityA,1,%),Period),2))); num/den; --8<------------------------
wabbit wrote:
or even speed it up a little bit by reducing the number of computations.... --8<------------------------- prd:=Input("Period:",1,9999,21); thisSec:=ROC(C,1,%); SecA:=ROC(Security("file_location",C),1,%); num:=(prd*Sum(thisSec*SecA,prd)) - (Sum(thisSec,prd)*Sum(SecA,prd)); den:=Max(0.00001,(prd*Sum(Pwr(SecA,2),prd)) - Pwr(Sum(SecA,prd),2)); num/den; --8<------------------------- wabbit :D
They are not the same. :?: I have created these 2 indicators and plotted it on the same chart. The first one is a normal line which fluctuating up and down. The second one is just a line moving narrowly around 0. What's wrong? :|
StorkBite  
#8 Posted : Monday, April 17, 2006 2:07:41 AM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Try this: [code:1:044bc8fabe] i1:=Input("Periods:",1,252,21); c1:=ROC(Security("C:\\MetaStock Data\\My Trades\\SP500\\AAPL",C),1,%); c2:=ROC(Security("C:\\MetaStock Data\\BM Data\\US&PRIME",C),1,%); n:=i1*Sum(c1*c2,i1)-Sum(c2,i1)*Sum(c2,i1); d:=i1*Sum(Pwr(c2,2),i1)-Pwr(Sum(c2,i1),2); n/max(d,0.00001)[/code:1:044bc8fabe] Change the security and index paths to something containing your own local data. This will plot the same as your original code without the divide by zero error.
wabbit  
#9 Posted : Monday, April 17, 2006 2:24:44 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Well in the first code, you have umpteen nested brackets..... rationalising them was always going to be fraut with danger! Re-count the brackets and group the operations that need to be grouped. Start with no brackets except around the functions that specifically require them.... and go from there. num:=prd*Sum(thisSec*SecA,prd) - Sum(thisSec,prd)*Sum(SecA,prd); den:=prd*Sum(Pwr(SecA,2),prd) - Pwr(Sum(SecA,prd),2); The order of operations is clearly spelled out in the MS Users Manual, so you don't a zillion brackets.... just read the notes and implement cleaner code. See if that helps. wabbit :D P.S. A couple of simple points have just been highlighted here: [list:06681b0ea3][*:06681b0ea3]NEVER accept anyone else's code unles you 100% understand every line of code. My repsonses were written a 04:30 as I couldn't sleep... and am very tired. Been working on the mean, median, moded thing all night..... for you. (How's the testing coming along? Haven't seen any results posted yet?) [*:06681b0ea3]You need to be able to resolve some of your own problems, without relying on everyone here. We are sharing a lot of information with you for free. We are not infallable, we sometimes make mistakes. You should have been in a position to sort this minor problem out for your self without having to post what I call a "sook" post! The proper thing to do would have been to to sort the problem out yourself, then post the correct version with a message saying, "Thankyou for your efforts, but you made a mistake. Here is the correct code." [*:06681b0ea3]the MS Users Manual, has been and always wil be the MS Bible [/soapbox][/list:u:06681b0ea3]
WmWaster  
#10 Posted : Monday, April 17, 2006 10:23:58 AM(UTC)
WmWaster

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/20/2006(UTC)
Posts: 53

Several other questions. - does extra spacing, paragraphing, characters, or brackets etc. slow down the calculation? - does this help to speed the computation up: Instead of: 1+(a*b+c) + 2+(a*b+c) + 3+(a*b+c) Replace with: SameFml:(a*b+c) 1+SameFml + 2+SameFml + 3+SameFml
Quote:
[list]
  • NEVER accept anyone else's code unles you 100% understand every line of code. My repsonses were written a 04:30 as I couldn't sleep... and am very tired. Been working on the mean, median, moded thing all night..... for you. (How's the testing coming along? Haven't seen any results posted yet?)
  • Thanks for your reminder. I was in the same status as yours - sleepy mode! :)
    Quote:
  • You need to be able to resolve some of your own problems, without relying on everyone here. We are sharing a lot of information with you for free. We are not infallable, we sometimes make mistakes. You should have been in a position to sort this minor problem out for your self without having to post what I call a "sook" post! The proper thing to do would have been to to sort the problem out yourself, then post the correct version with a message saying, "Thankyou for your efforts, but you made a mistake. Here is the correct code."
  • If I have known the correct code, I could have posted it out already. As you say, it might be caused by the "MS getting both data sets when opening the chart". But it might be not. Still figuring it #-o
    StorkBite  
    #11 Posted : Monday, April 17, 2006 5:56:59 PM(UTC)
    StorkBite

    Rank: Advanced Member

    Groups: Registered, Registered Users
    Joined: 3/19/2005(UTC)
    Posts: 2,995

    Was thanked: 14 time(s) in 10 post(s)
    WW, did you try the code I posted for you? It should have resolved your original problem. As a good coding practice, you want to avoid extra spaces and braces when possible. You will quickly reach character limits otherwise. Brackets and parentheses are used to override the natural operator precedence. Non-judicious use serves no purpose and clutters up the code. Please read the forum rules thoroughly. It would be good for you to start with the general information outlined in the comprehensive User's Manual. When you get ready to start with the formulas, download the Formula Primer and work the solutions in it... a few times. Finally, check out the Training Videos that are available to you free here on the forum. As Wabbit stated, try to help yourself first. Then, when you need help, please adhere to the forum rules and you will find that responses flow pretty smoothly. Thanks, George
    WmWaster  
    #12 Posted : Sunday, April 23, 2006 3:56:03 PM(UTC)
    WmWaster

    Rank: Advanced Member

    Groups: Registered, Registered Users, Subscribers
    Joined: 3/20/2006(UTC)
    Posts: 53

    I have tried your code. It does work to bypass the computation error, but the problem stated in 3rd post of this thread is left unsolved. As to coding extra spaces and brackets are sometimes used to help me understand the code. Provided that I won't reach the character limit, it seems it shouldn't be too much of a problem. After all, I'll try not to add too many unnecessary character. Do the characters of the comments (ie the statements surrounded by {} ) count towards the character limit? PS: Really strange. I should have sent this reply long time ago. But it's not here. Maybe my browser or my Internet connection encounter some problems. Or I have illusion. #-o
    StorkBite  
    #13 Posted : Sunday, April 23, 2006 8:48:23 PM(UTC)
    StorkBite

    Rank: Advanced Member

    Groups: Registered, Registered Users
    Joined: 3/19/2005(UTC)
    Posts: 2,995

    Was thanked: 14 time(s) in 10 post(s)
    Quote:
    Do the characters of the comments (ie the statements surrounded by {} ) count towards the character limit?
    yes.
    Quote:
    - When I just open the chart and apply this indicator, the indicator works fine (see 2nd graph - a.gif). - But if I change the loaded dates (of the data), the indicator will get screwed up (see 1st graph - b.gif). It won't help even if I switch back to the same set of loaded dates. I need to close and reopen the chart, attach the indicator to make it work again (returns to a.gif).
    I am unable to duplicate this error either on individual charts or those loaded on a preset template. Clearly, you are experiencing some difficulty based on your screen shots, but I could not do anything to upset the original Beta plot. I use 'Retain Scale' on the x-axis. Also, I prefer to use the Equis Beta formula which can be found on the main web site, or if you dig deep enough, you might uncover it here in the forum. It is here somewhere... Basically it involves dragging your index security price plot into an empty inner window of the security in which you are wishing to examine the Beta relationship. Then you drag the Beta indicator on top of that inner window index price line. The code is essentially the same, except that the external reference called by Security() is replaced with the INDICATOR reference. Maybe you can try that and see what happens. If that doesn't work for you, I'm stuck. HTH, George
    WmWaster  
    #14 Posted : Monday, May 1, 2006 4:24:02 PM(UTC)
    WmWaster

    Rank: Advanced Member

    Groups: Registered, Registered Users, Subscribers
    Joined: 3/20/2006(UTC)
    Posts: 53

    Sorry for my belated reply.
    g_stockman wrote:
    I am unable to duplicate this error either on individual charts or those loaded on a preset template. Clearly, you are experiencing some difficulty based on your screen shots, but I could not do anything to upset the original Beta plot. I use 'Retain Scale' on the x-axis.
    So it implies there may be something wrong with my computer. I may try it on another computer.
    Quote:
    Also, I prefer to use the Equis Beta formula which can be found on the main web site, or if you dig deep enough, you might uncover it here in the forum. It is here somewhere... Basically it involves dragging your index security price plot into an empty inner window of the security in which you are wishing to examine the Beta relationship. Then you drag the Beta indicator on top of that inner window index price line. The code is essentially the same, except that the external reference called by Security() is replaced with the INDICATOR reference. Maybe you can try that and see what happens. If that doesn't work for you, I'm stuck.
    As to Equis Beta Forumla, here's how it says about plotting Beta: ============================= 1. Open a chart of the desired security. 2. Drag the price plot of the index your are comparing, into the chart of the security. 3. Drag this custom indicator from the QuickList and drop it onto the price plot of the index. ============================= I'm not sure if I understand what it says. I opened the security chart. I opened the index chart. I dragged the index price to the security chart. I dragged the Equis Beta Forumla to the security chart. Actual Result: The beta line is always at 1. (see graph for details)
    wabbit  
    #15 Posted : Tuesday, May 2, 2006 12:47:10 AM(UTC)
    wabbit

    Rank: Advanced Member

    Groups: Registered, Registered Users, Subscribers, Unverified Users
    Joined: 10/28/2004(UTC)
    Posts: 3,111
    Location: Perth, Western Australia

    Was thanked: 16 time(s) in 16 post(s)
    WmWaster, The answer to this problem is obvious. If you had read the code for the Beta indicator, and taken the time to try and understand exactly what is going on with it (as I have suggested to you previously) then you will know the Beta will return a value of 1 when it is comparing the OHLCV data in the primary array to nothing. What this means is that you have not followed the instructions on how to plot this indicator correctly, and have not read the in the MS Users Manual about dealing with multiple plots on one chart, and referencing using the Indicator or 'P' functions. When you open a chart, this is the primary data source; when you drag another price data array onto the already open chart, this is a secondary data array. When you try to drag the Beta indicator from your indicator quicklist onto the chart, when the mouse initially enters the chart you will see the primary data becomes highlighted in pink (mauve?). If you drop the Beta indicator then, it will not be able to reference the secondary data and so will return a value of 1 for all time. Keep moving the mouse until it is over the secondary data; this data array will now highlight in pink. Now you can drop the Beta indicator and it will operate correctly. I point out to you again the necessity to fully understand the indicators which you are going to be using to trade, and the wealth of information contained in the MS Users Manual and the Equis Formula Primer. wabbit :D
    WmWaster  
    #16 Posted : Tuesday, May 2, 2006 8:55:18 AM(UTC)
    WmWaster

    Rank: Advanced Member

    Groups: Registered, Registered Users, Subscribers
    Joined: 3/20/2006(UTC)
    Posts: 53

    Dear wabbit, I did read the instruction (you can see I have posted the instruction on my previous post). I suppose it is ok if I drag the "Beta" indicator and simply mouse over the secondary data. I don't know the data needs to turn pink before it works. Sometimes the secondary data doesn't turn into pink even if you mouse over. You may need to move back and forth a bit to turn the secondary data into pink. However I encountered some strange outcomes. I have tested on several charts. If it works, the indicator works as normal. It's true even if I change the loaded date. If it doesn't, the "beta" indicator simply disappears after I drag it down. I still can't figure why it could sometimes fail. #-o My computer has all sorts of strange problems. :cry:
    wabbit  
    #17 Posted : Tuesday, May 2, 2006 1:42:29 PM(UTC)
    wabbit

    Rank: Advanced Member

    Groups: Registered, Registered Users, Subscribers, Unverified Users
    Joined: 10/28/2004(UTC)
    Posts: 3,111
    Location: Perth, Western Australia

    Was thanked: 16 time(s) in 16 post(s)
    Do the charts have more than minimum required amount of data loaded? ie 21 days? You have mentioned before that you often change the loaded dates? I never change mine and I never seem to have any troubles that you have. Loading the maximum amount of data will ensure that any exponential indicators are as accurate as possible, and will also give that wider 'global view' of the stock price. You can zoom in and out to DISPLAY different time intervals, but all of the data is loaded into memory and used in the computations. The maximum value is 65500 bars. In my default view I see one year of data. wabbit :D
    StorkBite  
    #18 Posted : Tuesday, May 2, 2006 3:34:01 PM(UTC)
    StorkBite

    Rank: Advanced Member

    Groups: Registered, Registered Users
    Joined: 3/19/2005(UTC)
    Posts: 2,995

    Was thanked: 14 time(s) in 10 post(s)
    So are we back to the problem with the indicator getting messed up when the loaded dates change? Maybe the solution is not to change the loaded dates?! Or, just know that you'll have to replot the indicator afterwards. There are other methods to perform these types of comparisons. If Beta is giving you too many headaches and you just have to have it, then the URSC would be worth a look.
    WmWaster  
    #19 Posted : Wednesday, May 10, 2006 3:36:59 PM(UTC)
    WmWaster

    Rank: Advanced Member

    Groups: Registered, Registered Users, Subscribers
    Joined: 3/20/2006(UTC)
    Posts: 53

    wabbit wrote:
    Do the charts have more than minimum required amount of data loaded? ie 21 days? You have mentioned before that you often change the loaded dates? I never change mine and I never seem to have any troubles that you have. Loading the maximum amount of data will ensure that any exponential indicators are as accurate as possible, and will also give that wider 'global view' of the stock price. You can zoom in and out to DISPLAY different time intervals, but all of the data is loaded into memory and used in the computations. The maximum value is 65500 bars. In my default view I see one year of data. wabbit :D
    Yes, it has more than 21 days loaded.
    g_stockman wrote:
    So are we back to the problem with the indicator getting messed up when the loaded dates change? Maybe the solution is not to change the loaded dates?! Or, just know that you'll have to replot the indicator afterwards. There are other methods to perform these types of comparisons. If Beta is giving you too many headaches and you just have to have it, then the URSC would be worth a look.
    Yes, the best workaround. :D What's the full forn of URSC? I couldn't find it in the Help file, nor the indicator drop-down list.
    StorkBite  
    #20 Posted : Wednesday, May 10, 2006 7:59:25 PM(UTC)
    StorkBite

    Rank: Advanced Member

    Groups: Registered, Registered Users
    Joined: 3/19/2005(UTC)
    Posts: 2,995

    Was thanked: 14 time(s) in 10 post(s)
    Users browsing this topic
    Guest (Hidden)
    2 Pages12>
    Forum Jump  
    You cannot post new topics in this forum.
    You cannot reply to topics in this forum.
    You cannot delete your posts in this forum.
    You cannot edit your posts in this forum.
    You cannot create polls in this forum.
    You cannot vote in polls in this forum.