NexusFi: Find Your Edge


Home Menu

 





Variable assignment changes output?


Discussion in EasyLanguage Programming

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




 
Search this Thread
  #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?
$500M Riding on World Cup 2026: France/Spain Co-Favored …
Prediction Markets & Event Contracts
ATFX Suspends Prop Trading Unit ATFunded -- Full Review …
Funded Trading Evaluation Firms
Warsh Drops Easing Bias, December Hike Now Above 50% -- …
Prediction Markets & Event Contracts
After $87M Settles NO: Irans Nuclear Redline Sets Up the …
Prediction Markets & Event Contracts
Thursday May 28: GDP + Core PCE + Jobless Claims All at …
Traders Hideout
 
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643


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 X Reply With Quote
Thanked by:




Last Updated on March 21, 2015


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