Rank: Member
Groups: Registered, Registered Users Joined: 10/12/2009(UTC) Posts: 13
|
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.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/7/2005(UTC) Posts: 602
|
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.
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 10/12/2009(UTC) Posts: 13
|
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.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Unverified Users Joined: 9/13/2004(UTC) Posts: 673 Location: Salt Lake City, UT
|
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.
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 10/12/2009(UTC) Posts: 13
|
Yes, we can define Day1 as the first bar loaded into the chart
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 10/12/2009(UTC) Posts: 13
|
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.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/7/2005(UTC) Posts: 602
|
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??
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 10/12/2009(UTC) Posts: 13
|
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 <9.9 on Day5), so there must be another trough, right? So if the most recent trough goes up >=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<9.9*1.1, but another buy on Day 9.
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.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/7/2005(UTC) Posts: 602
|
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.
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 10/12/2009(UTC) Posts: 13
|
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.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/7/2005(UTC) Posts: 602
|
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.
|
|
|
|
Users browsing this topic |
Guest (Hidden)
|
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.