NexusFi: Find Your Edge


Home Menu

 





Struggling to understand WHY it doesn't update a variable during the session


Discussion in MultiCharts

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




 
Search this Thread

Struggling to understand WHY it doesn't update a variable during the session

  #1 (permalink)
Dvdkite
Trieste Italy
 
Posts: 162 since Feb 2018
Thanks Given: 131
Thanks Received: 25

Hello everyone,

I'm working on a strategy that basically has some levels and I need to know where the price is in relations to those levels.

For example I have 5 levels and I want to know when the price is between 1 and 2, 2 and 3, etc...

the snapcode of the interested part is:

 
Code
// at the beginning 
[IntrabarOrderGeneration = true]

.......some inputs...

variable:

intrabarpersist burntIndex(0),

..... 
..... here all level prices are defined ( example level_1 = 2780, level_2 = 2740, level_3 = 2700, level_4 = 2670,level_%= 2640 )
.....


if price < level_1  and price >= level_2 then begin  burntIndex = 1;  end;
if price < level_2  and price >= level_3 then begin  burntIndex = 2;  end;
if price < level_3  and price >= level_4 then begin  burntIndex = 3;  end;
if price < level_4  and price >= level_5 then begin  burntIndex = 4;  end;
if price < level_5  and price >= level_6 then begin  burntIndex = 5;  end;

With this code I was hoping to get the position of the price between levels by changing the burntIndex variable and UPDATING it in realtime...

But using a lot of prints to debug I discoved that it performs the operation succesfully ONLY at the start of the session (probably just the first time that the code is executed)... I tried to print the burntIndex value at several different hours of the day but it REMAIN THE SAME for ALL THE DAY... it just reset at the morning....

The code above should be executed on EVERY tick (IOG is true) so I think I'm really missing something stupid here but I can't come up to a solution.

btw: there are no ONCE piece in front of this code.

Any ideas on WHY it doesn't update the burntIndex during the day when the price is moving?

Any suggestions are appreciated,

Thanks and Best Regards

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
REcommedations for programming help
Sierra Chart
NexusFi Journal Challenge - May 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Bigger Wins or Fewer Losses?
24 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

Dvdkite,

without the full code or at least code that can be used to reproduce the behavior I am afraid it's hard to tell.
Check your level values and the value for price using print statements for a few bars to see if they actually hold the values that you think they do.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
Dvdkite
Trieste Italy
 
Posts: 162 since Feb 2018
Thanks Given: 131
Thanks Received: 25



ABCTG View Post
Dvdkite,

without the full code or at least code that can be used to reproduce the behavior I am afraid it's hard to tell.
Check your level values and the value for price using print statements for a few bars to see if they actually hold the values that you think they do.

Regards,

ABCTG

Hello ABCTG,

the piece of code with the 5 "if" is in the main part of the strategy and it is supposed to work indipendently to the other part of the code. I'll try to add the other parts without all details..

 
Code
[IntrabarOrderGeneration = true]

inputs:
	debugMode(true),
	Price( Close ),
	StopLoss( 30 ),
	ProfitTarget( 15 ),

// and some more inputs....

variables:
         intrabarpersist burntIndex(0)


//..... 
//..... here all level prices are defined ( example 
level_1 = 2780;
level_2 = 2740;
level_3 = 2700;
level_4 = 2670;
level_5= 2640;
//.....


if price < level_1  and price >= level_2 then begin  burntIndex = 1;  end;
if price < level_2  and price >= level_3 then begin  burntIndex = 2;  end;
if price < level_3  and price >= level_4 then begin  burntIndex = 3;  end;
if price < level_4  and price >= level_5 then begin  burntIndex = 4;  end;
if price < level_5  and price >= level_6 then begin  burntIndex = 5;  end;

// then if I try to print the burntIndex at different time of the day 

        if time = 815 then if debugMode then print(" burntIndex at 8:15 = ", NumToStr(burntIndex,2));
	if time = 1200 then if debugMode then print(" burntIndex at 12:00 = ", NumToStr(burntIndex,2));
	if time = 1600 then if debugMode then print(" burntIndex at 16:00 = ", NumToStr(burntIndex,2));	
	if time = 1900 then if debugMode then print(" burntIndex at 19:00 = ", NumToStr(burntIndex,2));

// it ALWAYS GIVE ME THE SAME VALUE FOR ALL THE DAY!!!!
I cannot find other relevant part of code because the other part are UNRELATED with those prints.
I need the burntIndex to perform diffentent kind of actions on the actual level...
But as I said it just print the burntIndex related to the price value at the opening of the sesssion..

Any idea??

Thanks

Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

Dvdkite,

I would check if the conditions are actually triggered and when by adding print statements within each begin... end block.

 
Code
if price < level_1  and price >= level_2 then begin  burntIndex = 1;  end;
if price < level_2  and price >= level_3 then begin  burntIndex = 2;  end;
if price < level_3  and price >= level_4 then begin  burntIndex = 3;  end;
if price < level_4  and price >= level_5 then begin  burntIndex = 4;  end;
if price < level_5  and price >= level_6 then begin  burntIndex = 5;  end;
You might want to add the print before you set the value for burntIndex as this would allow you to check for
if burntIndex <> 1 then Print... for the first check and so on for the other checks with adjusting the number of course. This should tell you when and which level triggers and not clutter the output too much.
Based on that you can investigate things further.

Did you check your level values and the value for price using print statements for a few bars to see if they actually hold the values that you think they do? What was the result?

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #5 (permalink)
Dvdkite
Trieste Italy
 
Posts: 162 since Feb 2018
Thanks Given: 131
Thanks Received: 25


ABCTG View Post
Dvdkite,

I would check if the conditions are actually triggered and when by adding print statements within each begin... end block.

 
Code
if price < level_1  and price >= level_2 then begin  burntIndex = 1;  end;
if price < level_2  and price >= level_3 then begin  burntIndex = 2;  end;
if price < level_3  and price >= level_4 then begin  burntIndex = 3;  end;
if price < level_4  and price >= level_5 then begin  burntIndex = 4;  end;
if price < level_5  and price >= level_6 then begin  burntIndex = 5;  end;
You might want to add the print before you set the value for burntIndex as this would allow you to check for
if burntIndex <> 1 then Print... for the first check and so on for the other checks with adjusting the number of course. This should tell you when and which level triggers and not clutter the output too much.
Based on that you can investigate things further.

Did you check your level values and the value for price using print statements for a few bars to see if they actually hold the values that you think they do? What was the result?

Regards,

ABCTG

UPDATE:

Hello again, I made one thing to solve the problem... I've removed all the code BEFORE those code above and surprisingly the burntIndex was working!!! So I checked the section where I set up the level values depending on the date... at the end I came up to the solution that was so so easy...

I had to put INTRABARPERSIST even in front of every level variables... that solved the problem!!


I didn't think it was necessary to declare also the level variables as intrabarpersist because they are values that are updated just once at the starting of the session... Now I know!

Thanks for the tips

Best Regards,

David

Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

David,

you are welcome and I am glad to hear that you figured it out.

Variables don't necessarily have to be intrabarpersist in an intrabar order generation strategy. However if you update them during the bar and want them to keep the value they have to be declared as intrabarpersist. Otherwise they will revert back to the previous value at the end of the code cycle.
That's why I suggested checking if the level variables actually hold the value that you think they do.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on November 8, 2018


© 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