NexusFi: Find Your Edge


Home Menu

 





Sharing Int values between indicators


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Caveman with 2 posts (1 thanks)
    2. looks_two Eubie with 2 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 rsmN with 1 posts (0 thanks)
    1. trending_up 1,582 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 4 posts
    2. attach_file 2 attachments




 
Search this Thread

Sharing Int values between indicators

  #1 (permalink)
 Eubie 
Prague, Czech republic
 
Experience: Beginner
Platform: NinjaTrader/ZF
Trading: ES, TF
Posts: 140 since Jul 2010
Thanks Given: 292
Thanks Received: 97

Hello traders,

I ran into a problem when developing further SwingRays2 here on futures.io (formerly BMT). The problem: I need one indicator to make an Int value public. So I write SharingIndi, which has a private int and the value of this int is shown to the rest of the world.

 
Code
#region Variables
	private int currBar;
#endregion

...

       protected override void OnBarUpdate()
        {
            currBar = CurrentBar * 2;
	    Print("Indi   -> Bar=" + CurrentBar + " Value=" + CurrBar );
        }
...
        #region Properties
        [Browsable(false)]	
        [XmlIgnore()]		
        public int CurrBar
        {
            get { return currBar; }
        }

        #endregion
Now I want to see whether those CurrBar values are really accesible from outside, so I write another indi.

 
Code
      #region Variables
		private SharingIndi Indi;
       #endregion

	protected override void OnStartUp()
	{
		Indi = SharingIndi();
	}

        protected override void OnBarUpdate()
        {
		Print("Checker -> Bar=" + CurrentBar + " Value=" + Indi.CurrBar );
        }
and running both on the same chart reveals that Indi.CurrBar returns 0 all the time. Namely, the output is like

Quoting 
Indi -> Bar=27 Value=54
Indi -> Bar=28 Value=56
Indi -> Bar=29 Value=58
Indi -> Bar=30 Value=60
Checker -> Bar=0 Value=0
Checker -> Bar=1 Value=0
Checker -> Bar=2 Value=0
Checker -> Bar=3 Value=0
Checker -> Bar=4 Value=0

What am I doing wrong? Support does not help despite I have a live license...Attached are both indis.
Many thanks for any hint,
Daniel

Attached Files
Elite Membership required to download: Sharing_BMT.zip
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
What broker to use for trading palladium futures
Commodities
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
How to apply profiles
Traders Hideout
 
  #3 (permalink)
 Caveman 
Edmond,Oklahoma,United States
 
Experience: Beginner
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: ES, CL
Posts: 19 since Sep 2010
Thanks Given: 6
Thanks Received: 30


I have imported this zip, and it appears to be working as expected on my end. Are you refreshing your output window? Otherwise the call is proper and the output is as expected.

You have an if statement in the SharingIndi which states to return(quit) if the CurrentBar < 5. You have 5 examples listed. What was the 6th bar output? With this statement intact, the first 5 bars will return 0 since it never gets to the currBar calculation and hence, any reference to the Indi.CurrBar will return 0 WHILE CurrentBar < 5.

Any time you reference something in one indicator from within another, the conditions set within that reference indicator have to be met before variables will be anything other than what they are set to during the Variable or Initialize region.

Reply With Quote
  #4 (permalink)
 Eubie 
Prague, Czech republic
 
Experience: Beginner
Platform: NinjaTrader/ZF
Trading: ES, TF
Posts: 140 since Jul 2010
Thanks Given: 292
Thanks Received: 97

Hello Caveman,

yes Im refreshing my Output window. Attached is a video of how the results appear on my end, mind the TV in the back

In have added a

 
Code
if ( CurrentBar < 5 )
   return;
line into the Checker indi. As Im attaching both indis to an empty chart, I have no idea what might be going wrong.
Thanks again!
Daniel

Attached Files
Elite Membership required to download: Sharing2.mp4
Started this thread Reply With Quote
  #5 (permalink)
 Caveman 
Edmond,Oklahoma,United States
 
Experience: Beginner
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: ES, CL
Posts: 19 since Sep 2010
Thanks Given: 6
Thanks Received: 30

What you are seeing is the back-data on your data series "Days to load" being ran through the indicator. As these contain no real bar update calls they get fed through your indicator without meeting the CurrentBar rule.

Bottom line is, the information from the sharing indi is making it to the checker. You need to run live data through it to get the 0's to go away. I saw the same behavior on mine, but it cleared as soon as data was being fed in. Back data loaded into a chart is considered historical and is handled differently than live data by the OnBarUpdate method.

Hope this helps.

Reply With Quote
Thanked by:




Last Updated on May 8, 2012


© 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