Discussions
»
Product and Service Development
»
Formula Assistance
»
Replicating "for" statement and referencing past values keeping the current close fixed
Rank: Newbie
Groups: Registered, Registered Users Joined: 3/17/2009(UTC) Posts: 2
|
Hey guys,
I want to sum a history of say the close today less the close for each of the last 10 days.
In Tradestation i would use,
For number = 1 to 10 begin
total = (close-close[value]);
sum=sum+total;
end;
In MS if i use the sum(c-prev(c,-1),10) it looks at each previous days close less the day befores close.
But what i want is to keep the current close and reference that to each previous days close over the
last 10 days...
There must be a simple way to do this ??? Can anyone help.
|
|
|
|
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)
|
Hi ASnake,
Welcome to the Forum.
Rethink your maths. If you were adding the expression in the TS code (which wouldn't have worked btw, unless you replaced "number" with "value" [:)] ) then your result would comprise the sum of, ten close value less the sum of the previous bars close values.
In MS speak, this might help:
---------------------------------------- num:=10; data:=close;
(num*data) - sum(ref(data,-1),num); ----------------------------------------
Hope this helps.
wabbit [:D]
|
|
|
|
Rank: Newbie
Groups: Registered, Registered Users Joined: 3/17/2009(UTC) Posts: 2
|
Wow that was fast, thanks wabbit.
yep your right about the TS code, i did actually have value1=1 to count etc but changed it for the post...i was just trying to explain myself...guess i goofed haha.
Yes it works, i have to try and get my head around MS way of referencing the past, and your logic is spot on.
I just need to get it into my head.
I have TS in the past and i am trying to port some code to MS.
Thanks for your help.
|
|
|
|
Users browsing this topic |
Guest (Hidden)
|
Discussions
»
Product and Service Development
»
Formula Assistance
»
Replicating "for" statement and referencing past values keeping the current close fixed
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.