Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Plot Value "Data Window" / Programatic discrepancy
I'm hoping someone can answer this for me. I'm programming a very simple indicator. It plots two simple moving averages over price. When I hover my mouse over the bar where the moving averages cross I can see the values in the Data Window and / or the "hint" window. I want to write some code to take action when some conditions are met using the values of the two moving average plots. The issue is that the value of the plots is not _always_ the same programatically as it is on the screen. For examle if I print (plot1); and compare the values will match for a series of bars but occasionally they are different by a tick one way or ther other.... For my strategy a tick actually makes a difference and I want to know why there is a discrepancy. A values a value and I know which value I want. I've tried using the bar status to get the value on the first tick but that doesn't seem to work on historical data (and I want to backtest). I also tried using the last tick, but thats not the value I want either. I'm using MC 7 beta 4 ( which rocks by the way)... Any ideas? I would really appreciate any advice.
Thanks
Wolfie (the werewolf) Wolf
Can you help answer these questions from other members on NexusFi?
It's a pleasure to finally meet you; I've been lurking. Hopefully I can start contributing now. After I posted, and you responded, I spent a considerable amount of time on this on Sunday. (I know, I know, get a like Wolfie Wolf).
Without getting into too many specifics of my code, which I'm not comfortable posting in it's entirety, here is a high level explanation of the issue and the resolution. Interestingly, "resolution" is an important factor here because the problem is a rounding issue which only appears when the resolution is set to a specific time frame and the moving averages are set to specific values. (I've changed the values in the sample below). I tried to reproduce this using alternate settings, so I could provide a detailed example, but I wasn't successful in the time I had. I don't have time to hammer on this right now. If you're really keen Mike I could PM you on this. It's important to note that this issue appeared while evaluating my code against CL N1, which is what I thought you would find most interesting.
I found one comment in the following thread that tweaked me to the idea that the number of decimal places and therefore rounding of values stored in variables may be different from the values being plotted n the chart and displayed in the data window. Better documentation for MC would be beneficial, most of what I have been learning from is Tradestation related.
"take values and string them and then print them because of the 2 dec place limit for float in the output bar
just a print tip since your coding problem was solved".
you get a two decimal output which may or may not be the same as what's in the output window. If you do as the poster above suggested:
BlueString = NumToStr(Plot1,4);
and then:
print ("BlueString ", BlueString);
you get a 4 decimal value that, when rounded, will match the value in the output window _every_ time. So I did the following:
MyBLue=StrToNum(BlueString);
MyRoundedBlue=round(MyBlue,2);
then when you print or compare the MyRoundedBlue the value matches the output window. I coded this right in your forum editor so I hope I didn't mess anything up.
At first I thought my "offset" of the average was creating the issue but that wasn't the case at all. I hope this helps someone.
I've had a chance to play around with your suggestion. Your tip works great for formatting the output to the output bar, thanks. It doesn't, however, do anything for the values in the variables. When I compare value1 and value2 with a logical expression like "if value1 = value2" it compares just the first two decimals, not all 4. How can I let MC know when I call a variable that contains 4 decimal places that I want to use all 4 decimal places without first converting it to a string and then converting it back as I demonstrated above? I don't actually want to use all 4 decimals but I do want to round the second decimal using the third decimal place.
at the moment i dont really know exactly what you want to do. The inline codes always compares all available decimalplaces of the variables, that means if
value1=Average(value,16)[2]; is i.e. 1.4735665688 the code uses all 10 decimalplaces, regardless what the plot or print statement says, even if the plot says
1.4736.
If you want to use less decimalplaces you need to round the variable and not the print ot plot statement with value1 = round (Average(value,16)[2] , X ); with X as your
decimals.