+ Reply to Thread
Results 1 to 7 of 7

Thread: IF function

  1. #1
    Registered User
    Join Date
    01-24-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    4

    Question IF function

    Hi there,

    I was wondering if anyone knows if it is possible to create a forumla for the following information:

    I have daily share prices for a company for 10 years and have the following criterion to know when to buy and sell the share:

    If the share price moves up at least x% from a subsequent low, buy and hold the share until its price moves down at least x% from a subsequent high and at that time sell. Moves less than x% in either direction are ignored.

    I really want a formula to be able to do this as it has been taking me ages to do this manually and I've tried various IF functions but they don't work. Maybe it isn't possible but I thought I'd ask anyway.

    Thanks for anyone that gives it a go!
    Last edited by Jiglian; 01-25-2010 at 02:54 AM. Reason: Problem Solved

  2. #2
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,759

    re: IF function

    If the share price moves up at least x% from a subsequent low,
    Assume you mean from a prior low? You don't know what it will do susequently. Ditto for the next sentence.

    Maybe an example would help.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-24-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: IF function

    Sorry yes I realise the first part of that was a bit misleading. Should have been:

    If the share price moves up at least x% buy and hold the share until its price moves down at least x% from a subsequent high (from when you bought it) and then sell it. Then buy it again when the price moves up at least x% from a subsquent low (from when you sold it).

    I've attached an example of what I want to be able to do with a formula.

    The idea behind the criterion is that the share price will move up and beyond the price that you buy it at and below the price which you sell it at. Therefore after you have bought a share you calculate the fall in price using the highest price it achieved and the drop from that, if it is bigger than your filter (of say 1%) then you sell it and vice versa.

    I start by just buying the share at the start of the period I want.

    Hope that helps!
    Attached Files Attached Files
    Last edited by Jiglian; 01-24-2010 at 04:29 PM.

  4. #4
    Forum Guru
    Join Date
    10-28-2008
    Location
    Not here anymore
    MS-Off Ver
    irrelevant
    Posts
    10,150

    Re: IF function

    Make sure that you put the word "Buy" in E3, then put this formula in E4 and copy down

    =IF(ISBLANK(C4),"",IF(AND(C4>0.01,COUNTIF($E$3:E3,"SELL")=COUNTIF($E$3:E3,"BUY")),"BUY",IF(AND(C4<-0.01,COUNTIF($E$3:E3,"SELL")<COUNTIF($E$3:E3,"BUY")),"SELL","")))
    hth
    Last edited by teylyn; 01-24-2010 at 05:17 PM.

  5. #5
    Registered User
    Join Date
    01-24-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: IF function

    Thank you so much for your help.

    The formula works well (it gets just about the same answers as I did manually). However there was a few buy and sells it missed. I think it is because it didn't use the lowest or highest value within the range...... probably easier if I show you in the worksheet attached.
    There is probably little probability that a formula could be created to do this but I thought I'd ask for any ideas anyway just incase.

    Thanks so much for that formula though...... it may definetely be the way forward!
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    10-28-2008
    Location
    Not here anymore
    MS-Off Ver
    irrelevant
    Posts
    10,150

    Re: IF function

    Have a look at the attached.

    I've created three new columns
    - column D finds out if the price goes up or down
    - column E applies consecutive numbers
    - column F calculates the percentage change since the last up/down change

    The Buy/Sell column now looks at column F instead of column C

    You can hide columns D to F if you want.

    I find they now match your manually entered markers, except for row 57-58, where I believe you sold too late
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    01-24-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    4

    Thumbs up Re: IF function

    Thank you so much, yes indeed I did sell too late in 57-58. This will save me so much time and probably my sanity too!

    Problem Solved yey!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0