in Search

Can someone code this, please?

Last post 10-22-2009, 19:51 by johnl. 10 replies.
Sort Posts: Previous Next
  •  10-13-2009, 17:40 30937

    Can someone code this, please?

    Hi, how should I code if I want to buy shares when the price increases like 5% and close out when it goes down 10% in like 2 yrs.

    I am sure this is simple for you. I am a new user, so if you can code this, please give me some hints. Many thanks.
  •  10-13-2009, 20:00 30939 in reply to 30937

    Re: Can someone code this, please?


     Use function LLV() or TROUGH() to find the low to start the calculation, then
     use an if statement like:
     
     If((C>1.05*LLV(C,20)),1,0)  to find the any 5% move from the low of the previous
     20 days.

  •  10-13-2009, 21:50 30941 in reply to 30939

    Re: Can someone code this, please?

    Thank you johnl.

    But what I want is, For example:

    Day1 price: $1.0 Day2 price: $1.01, Day 3: $1.02, Day 4: $1.10, then buy some shares on Day4.

    When Day5 price is still $1.10, i dont want to buy more.
    What I want is to place my second when the price pn>=1.10*1.05=1.155, and so on.

    Can this function make this? Please let me know.
    Thanks.
  •  10-14-2009, 15:39 30945 in reply to 30941

    Re: Can someone code this, please?

    What are you defining as "Day 1"?  In other words, there has to be some way to identify a starting point.  i.e. the first bar loaded into the chart, etc.
  •  10-14-2009, 16:15 30947 in reply to 30945

    Re: Can someone code this, please?

    Yes, we can define Day1 as the first bar loaded into the chart
  •  10-20-2009, 0:13 30970 in reply to 30947

    Re: Can someone code this, please?

    I will repeat my question to make it more clear.

    Every time when the close price goes up >=10%, I want to buy.

    For example:

    Day1 (The first bar loaded in the chart) close price: 10
    Day 2: 9.5
    Day 3: 9
    Day 4: 9.6
    Day 5: 9.9 (Here, I want to buy as 9*1.1=9.9)
    Day 6: 9
    Day7: 9.9 (Another buy )
    Day 8: 10.89 (=9.9*1.1, so another buy)
    and so on for a long period.

    If I just code:
    {buy:} cross(c, trough(1,c,1)*1.1)

    is it correct?

    I am thinking if I can loop the above formula every time when the buy order is executed, like on day5,7,8, then it maybe correct. But I dont know how to code that.

    Regarding to LLV() mentioned by Johnl, for example, if Day 8 CLOSE is 10, it is still >9*1.1 (On Day 6), but i dont want to buy here.

    If you have any ideas about this, please help me. Thanks very much.
  •  10-20-2009, 19:08 30973 in reply to 30970

    Re: Can someone code this, please?


     Here is my problem:

    Day1 (The first bar loaded in the chart) close price: 10
    Day 2: 9.5
    Day 3: 9
    Day 4: 9.6
    Day 5: 9.9 (Here, I want to buy as 9*1.1=9.9)
    Day 6: 9
    Day7: 9.9 (Another buy )
    Day 8: 10.86 (<9.9*1.1, so not another buy) but (>9*1.1=9.9) so another buy
    Day 9: 10.84 ( <9.9*1.1, so not another buy) but (>9*1.1=9.9) so another buy
    Etc:

    Every day is going to be a buy just as long as the price is above (9*1.1)
    Not sure that is that what you want??

  •  10-20-2009, 22:14 30974 in reply to 30973

    Re: Can someone code this, please?

    Hi Johnl

    Thank you for your kind reply.

    How about I explain like this:

    Every time after my previous buy order, if the most recent trough price goes up >=10%, I would like to have another buy.

    Same example as above:

    Day 5: is my first buy order

    Then in Day6, the price goes down to 9 (or any number =10%, I want another buy.

    So I have another buy on Day 7 because the price in Day 7>=the first trough (in Day6)*1.1 after my last buy order (in Day 5).

    Same, if Day 7: 9.9
    Day8: 10.86
    Day9: 11

    Price goes up form Day 7 to Day 9, Then Day 7 is the lowest price since my last buy order on Day 7.

    Not buy on Day 8 because 10.86
    So in a word, every time after my previous order, if the most recent trough goes up 10%, then place another buy order.

    Sorry for confusing you, hope i explain it more clearly this time.

    Please let me know if you have any ideas about it. Thank you again.
  •  10-21-2009, 20:19 30978 in reply to 30974

    Re: Can someone code this, please?

        Unfortunately, someone with better programming skills will have to attempt this.
       What you want to do is start a calculation on some condition and then stop the
       calculation on another condition, then repeat. Sort of a FromTo(from this,to this,do this)  
       function. I  always thought I could spec it out and suggest it to equis but even the
       spec'ing gets messy.

  •  10-22-2009, 16:37 30985 in reply to 30978

    Re: Can someone code this, please?

    Thank you very much, Johnl.

    I have another question about general settings.

    If I want to execute my first buy order on the first bar during the period no matter what condition is on that day. What should I do?

    Thanks.
  •  10-22-2009, 19:51 30987 in reply to 30985

    Re: Can someone code this, please?


     I have to answer your question with another question.
     What do you mean by "period"? If you think in terms of a data sequence a period
     could be anything you make it. 
View as RSS news feed in XML