NexusFi: Find Your Edge


Home Menu

 





Variable assignment changes output?


Discussion in EasyLanguage Programming

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




 
Search this Thread

Variable assignment changes output?

  #1 (permalink)
TahuPhoenix
Lund Sweden
 
Posts: 4 since Feb 2015
Thanks Given: 1
Thanks Received: 0

Dear Forums,

I recently wrote a bit of code which purpose is to calculate Intraday-Turnover no matter what resolution you're looking at. The results:

 
Code
Vars:
	Intrabarpersist Turnover(0),
	countDays(0);


Turnover = Turnover + (Close * Ticks);
countDays = countDays + 1;
if(Date <> Date[countDays]) then
begin
	Turnover = Close * Ticks;
	countDays = 0;
end;

Plot1(Turnover, "Turnover");
The code calculates the intraday value of all contracts which was sold and resets until the next day, and it seems to work fine.

Out of curiosity and learning, I wanted to make an array which stored the Close of the last bar of each day, no matter the resolution. I figured that since I've got some code that already figures out when the next day comes, this shouldn't be a problem.

New Code:

 
Code
Vars:
	Intrabarpersist Turnover(0),
        count(0),
	countDays(0);

Arrays:
	daysArray[] (0);



Turnover = Turnover + (Close * Ticks);
countDays = countDays + 1;
if(Date <> Date[countDays]) then
begin
	Turnover = Close * Ticks;
	countDays = 0;
	daysArray[count] = Close[currentbar];
        count = count + 1;
end;
	
Plot1(Turnover, "Turnover");

And now the results are completely different. As soon as I try to assign any variable to "Close[currentbar]", the rest of my code stop working properly. How come this is? It's driving me nuts. I know I can use different data series, but for this experiment I'm trying to fit it into the same.


All the best,
TahuPhoenix

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627


TahuPhoenix,

when you index a reserved word or variable to get the value from X bars back the values start from the current bar and go up. Currentbar = 0, 1 = the bar on the left from the currentbar etc.

With Close[CurrentBar] you are likely trying to look at a bar that is not even accessible. Assume you are at CurrentBar = 100, with Close[100] you try to access the 100th bar left from the current bar. Which means you'd need 101 bars on the chart, but only have 100 at current bar 100.
Long story short you have to use Close[0] to get the current close at the moment of the code calculation.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on March 21, 2015


© 2024 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 - Downloads - Top
no new posts