moving average on excel

Discussion in 'Automated Trading' started by travis, Apr 23, 2010.

  1. travis

    travis

    Thanks for the thoughtful and detailed feedback, even though I might prove unworthy of your help. Also, I must mention that I noticed you didn't entirely read my post and it slightly bothered me.

    I can understand your advice about the subroutine name, and I've changed the name from "myroutine" to "copy_print", because - as I wrote in my previous post which you didn't fully read - it first copies the previous value and then prints the new one.

    Instead, I have a problem understanding (and therefore implementing) the other changes you suggested, because:

    1) obviously I am not that good with VBA code, and I wouldn't want to write something I can't quickly and thoroughly understand.

    2) obviously I am not an expert but I feel that your complex code will tire the cpu (and my small brain) just as much as my code. Instead of saying "do these 9 things", I'd be saying "do these x things for x equal to...". It would make sense - in my humble and ignorant opinion - if I were to change that number continuously in the future, but such number will be very static, with my 9 symbols traded (probably 13 in the future).

    To answer your question, the value on row 500 - as I wrote in my previous post which you didn't entirely read - is simply the last printed price, the last value of the moving average. It gets printed there only after the previous value is copied to the row above (and the same happens to all the earlier values, that shift one row higher per minute, or whatever the update interval).

    For some reason, I am not gifted at programming and I have to keep everything as simple as possible, which might be an advantage in some ways, but it gives me many limits. I've always felt pretty stupid among the users of this forum, and that is why I talk about having a "small" brain. Probably it doesn't have anything to do with the size of my brain, but with teachers and parents busting my balls too much as i was growing up, and making me hate Math and homework, to the point that when I see a formula i get some kind of allergic reaction that knocks out my reasoning capabilities.

    Sorry about polemically pointing out that you didn't read completely my previous post, but you asked two questions that revealed such truth to me. Obviously you're quite talented at writing code and I am a moron at writing code, but I put effort into writing my posts, so I feel they should be read. I mean... you were actually commenting on a post which you hadn't read in its entirey, and asking me questions that were answered by the post itself. Maybe that's why you're so good with code, because you can't read anything other than programming code, so I guess you won't be reading this post either.
     
    #11     Apr 25, 2010
  2. byteme

    byteme

    I regret offering my assistance.

    I did in fact read your post and the ones before it.

    My first question was rhetorical. You know, to help you try to think for yourself - what would be a good name for that subroutine? The name you have chosen demonstrates that you still don't really understand what the code is doing or why.

    As for the 500 question, you didn't, and still haven't, said why it is 500 and not 35 or 678 or 26 million. Do you understand the question now?

    I suspect you don't know the answer hence you try to divert attention by attacking me instead.

    Frankly, I find your response bizarre.
     
    #12     Apr 25, 2010
  3. travis

    travis

    Yeah, I understand what you are saying, but that's not the case. I kept "myroutine" because it was the name my friend had given it 5 years ago, and I am sure you would agree that it's not ideal to keep on changing subroutine names all the time (other modules referring to it might not find the subroutine any more). Anyway, the new name, "copy_print" is a good name and I believe I understand what it does. If I keep the code simple, I can understand it. I am quite confident I do understand what it does.

    Regarding the 500 question: the row is row 500 because I am not running my workbook for longer than one day, and with 1 minute prints or even not as frequent, I will not need more than 500 rows/price updates: price is printed once per minute, so with 500 prints I cover 500 minutes. I don't mind explaining it again if it's not clear.

    Sorry for blaming you for not reading my post, since you just wrote you had read it.
     
    #13     Apr 25, 2010
  4. travis

    travis

    Small change in the first macro, because I decided that, should I not have enough price prints to get a good moving average (e.g.: I want the average of the last 3 hours, but I only have price prints for the last 2 hours), I want the average to be equally affected by all the prices I do have, rather than it being affected so much by the first price. I don't know why my friend had it that way, but it wasn't a good idea. Yes, always better than having a 0, but it's better to have an empty cell, so that it won't affect the average at all.

    Or maybe... was he thinking that if we're missing one hour, that one hour would have been closer to the first price? That could be good reasoning... but still, giving the same weight to all price prints seems better to me.

    Sub mav()
    For i = 250 To 500
    ma.Cells(i, 1).ClearContents
    ma.Cells(i, 2).ClearContents
    ma.Cells(i, 3).ClearContents
    ma.Cells(i, 4).ClearContents
    ma.Cells(i, 5).ClearContents
    ma.Cells(i, 6).ClearContents
    ma.Cells(i, 7).ClearContents
    ma.Cells(i, 8).ClearContents
    ma.Cells(i, 9).ClearContents
    Next
    TimerID = SetTimer(0, 0, 120000, AddressOf copy_print)
    End Sub

    Oh, another thing: the timer was wrong. I am having it run every 2 minutes, so it's 120k milliseconds.
     
    #14     Apr 26, 2010