NexusFi: Find Your Edge


Home Menu

 





Variable not saving "previous" function values correctly?


Discussion in EasyLanguage Programming

Updated
    1. trending_up 260 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
shawnh
Montreal, Canada
 
Posts: 11 since Nov 2010
Thanks Given: 0
Thanks Received: 1

Greetings all, I have a function where within it I call the LinearRegValue function and save it to a variable, with the intention of course of saving the whole "series" of those values to that variable so I can access them as HLR[0], HLR[1], etc. Like so:


 
Code
Var:
   HLR(0.0);
.
.
.
hfx = 140;
HLR = LinearRegValue(Close, hfx, 0); 
FilterResult = C[0] < HLR AND HLR[0] < HLR[1];
I was getting some puzzling results so I added PRINT statements in the function to see what was getting saved in variable HLR. Turns out the value in HLR[0] is fine and always matches exactly with LinearRegValue[0], but what gets saved in HLR[1] is always very *slightly* off from what is LinearRegValue[1]. For example:

 
Code
1201231.00 1515.00 C[0]:   29.56  LRV(Close, hfx, 0)[0]: 29.2878  LRV(Close, hfx, 0)[1]: 29.2798  HLR[0]: 29.2878  HLR[1]: 29.2808 FilterResult:  FALSE
1201231.00 1530.00 C[0]:   29.57  LRV(Close, hfx, 0)[0]: 29.2952  LRV(Close, hfx, 0)[1]: 29.2868  HLR[0]: 29.2952  HLR[1]: 29.2878 FilterResult:  FALSE
1201231.00 1545.00 C[0]:   29.51  LRV(Close, hfx, 0)[0]: 29.3019  LRV(Close, hfx, 0)[1]: 29.2943  HLR[0]: 29.3019  HLR[1]: 29.2952 FilterResult:  FALSE
1201231.00 1600.00 C[0]:   29.59  LRV(Close, hfx, 0)[0]: 29.3104  LRV(Close, hfx, 0)[1]: 29.3011  HLR[0]: 29.3104  HLR[1]: 29.3019 FilterResult:  FALSE
1201231.00 1615.00 C[0]:   29.54  LRV(Close, hfx, 0)[0]: 29.3175  LRV(Close, hfx, 0)[1]: 29.3097  HLR[0]: 29.3175  HLR[1]: 29.3104 FilterResult:  FALSE
1201231.00 1630.00 C[0]:   29.59  LRV(Close, hfx, 0)[0]: 29.3254  LRV(Close, hfx, 0)[1]: 29.3170  HLR[0]: 29.3254  HLR[1]: 29.3175 FilterResult:  FALSE
1201231.00 1645.00 C[0]:   29.58  LRV(Close, hfx, 0)[0]: 29.3331  LRV(Close, hfx, 0)[1]: 29.3249  HLR[0]: 29.3331  HLR[1]: 29.3254 FilterResult:  FALSE
1201231.00 1700.00 C[0]:   29.56  LRV(Close, hfx, 0)[0]: 29.3416  LRV(Close, hfx, 0)[1]: 29.3327  HLR[0]: 29.3416  HLR[1]: 29.3331 FilterResult:  FALSE

It's a little bit weird... has anyone else ever encountered this? My function is set to "Auto-detect" and overall it returns a boolean value (ie. the value of "FilterResult").

Thanks!
Shawn

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
DOM in QTrader vs Bookmap
Platforms and Indicators
Equity Monaco download file?
Psychology and Money Management
How to get Large data indicators to print global
NinjaTrader
Time, Futures, Scalping, Treasurys
Treasury Notes and Bonds
Tech-Savvy Trader Seeking Collaboration with Trading Pla …
Emini and Emicro Index
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
The Program
8 thanks
HumbleTraders next chapter
7 thanks
L2Azimuth - FuturesAnalytica
4 thanks
Daytrading ES & NQ
4 thanks
Fighting Addiction and Stops
3 thanks
  #2 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,691 since Jul 2012
Thanks Given: 1,904
Thanks Received: 7,406


shawnh View Post
Greetings all, I have a function where within it I call the LinearRegValue function and save it to a variable, with the intention of course of saving the whole "series" of those values to that variable so I can access them as HLR[0], HLR[1], etc. Like so:


 
Code
Var:
   HLR(0.0);
.
.
.
hfx = 140;
HLR = LinearRegValue(Close, hfx, 0); 
FilterResult = C[0] < HLR AND HLR[0] < HLR[1];
I was getting some puzzling results so I added PRINT statements in the function to see what was getting saved in variable HLR. Turns out the value in HLR[0] is fine and always matches exactly with LinearRegValue[0], but what gets saved in HLR[1] is always very *slightly* off from what is LinearRegValue[1]. For example:

 
Code
1201231.00 1515.00 C[0]:   29.56  LRV(Close, hfx, 0)[0]: 29.2878  LRV(Close, hfx, 0)[1]: 29.2798  HLR[0]: 29.2878  HLR[1]: 29.2808 FilterResult:  FALSE
1201231.00 1530.00 C[0]:   29.57  LRV(Close, hfx, 0)[0]: 29.2952  LRV(Close, hfx, 0)[1]: 29.2868  HLR[0]: 29.2952  HLR[1]: 29.2878 FilterResult:  FALSE
1201231.00 1545.00 C[0]:   29.51  LRV(Close, hfx, 0)[0]: 29.3019  LRV(Close, hfx, 0)[1]: 29.2943  HLR[0]: 29.3019  HLR[1]: 29.2952 FilterResult:  FALSE
1201231.00 1600.00 C[0]:   29.59  LRV(Close, hfx, 0)[0]: 29.3104  LRV(Close, hfx, 0)[1]: 29.3011  HLR[0]: 29.3104  HLR[1]: 29.3019 FilterResult:  FALSE
1201231.00 1615.00 C[0]:   29.54  LRV(Close, hfx, 0)[0]: 29.3175  LRV(Close, hfx, 0)[1]: 29.3097  HLR[0]: 29.3175  HLR[1]: 29.3104 FilterResult:  FALSE
1201231.00 1630.00 C[0]:   29.59  LRV(Close, hfx, 0)[0]: 29.3254  LRV(Close, hfx, 0)[1]: 29.3170  HLR[0]: 29.3254  HLR[1]: 29.3175 FilterResult:  FALSE
1201231.00 1645.00 C[0]:   29.58  LRV(Close, hfx, 0)[0]: 29.3331  LRV(Close, hfx, 0)[1]: 29.3249  HLR[0]: 29.3331  HLR[1]: 29.3254 FilterResult:  FALSE
1201231.00 1700.00 C[0]:   29.56  LRV(Close, hfx, 0)[0]: 29.3416  LRV(Close, hfx, 0)[1]: 29.3327  HLR[0]: 29.3416  HLR[1]: 29.3331 FilterResult:  FALSE

It's a little bit weird... has anyone else ever encountered this? My function is set to "Auto-detect" and overall it returns a boolean value (ie. the value of "FilterResult").

Thanks!
Shawn

You'd have to dig into the LRV function to see what values it is using, but my guess is that is the LRV [1] calculation is using the current close, and not the previous close.
What do you get, for example, with this LRV(Close[1], hfx, 0) ? Does that return same value as HLR[1]?


And if you are saving LRV result in HLR, why do you need to use LRV(Close, hfx, 0)[1] at all? I would just use HLR[1], since that works correctly.

Follow me on Twitter Reply With Quote
  #3 (permalink)
shawnh
Montreal, Canada
 
Posts: 11 since Nov 2010
Thanks Given: 0
Thanks Received: 1



kevinkdog View Post
You'd have to dig into the LRV function to see what values it is using, but my guess is that is the LRV [1] calculation is using the current close, and not the previous close.
What do you get, for example, with this LRV(Close[1], hfx, 0) ? Does that return same value as HLR[1]?


And if you are saving LRV result in HLR, why do you need to use LRV(Close, hfx, 0)[1] at all? I would just use HLR[1], since that works correctly.


Thanks Kevin... I found the problem - I simply tried the "fast calculation" version of LinearRegValue (ie. LinearRegValueFC) and left everything else as is, and it worked perfect! Weird eh? Must be an indexing issue or something in the regular LinearRegValue...

Thank You!
Shawn

Reply With Quote
  #4 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,691 since Jul 2012
Thanks Given: 1,904
Thanks Received: 7,406


shawnh View Post
Thanks Kevin... I found the problem - I simply tried the "fast calculation" version of LinearRegValue (ie. LinearRegValueFC) and left everything else as is, and it worked perfect! Weird eh? Must be an indexing issue or something in the regular LinearRegValue...

Thank You!
Shawn

Awesome!

How are you using Tradestation as a Canadian, since they do not allow accounts there anymore? Are you paying a monthly fee for the platform and data?

Just curious...

Follow me on Twitter Reply With Quote




Last Updated on August 17, 2024


© 2025 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Sitemap - Downloads - Top
no new posts