NexusFi: Find Your Edge


Home Menu

 





How to fix this problem ?


Discussion in NinjaTrader

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




 
Search this Thread
  #1 (permalink)
 pooh 
Shanghai, China
 
Experience: Intermediate
Platform: MetaTrader, TWS
Trading: ES
Posts: 30 since Jul 2014
Thanks Given: 62
Thanks Received: 10

I coded a simple indicator for NT8. This indicator is supposed to plot a histogram bar when the previous candle is an up candle. It compiles without problem. However, it just doesn't plot anything. After attaching it to the chart, the indicator window shows blank. The code is very simple, the OnBarUpdate() section only consists of one line. How to fix it ? The source code under OnBarUpdate() is as following:

protected override void OnBarUpdate()
{
Value[0]=(Close[1]>Open[1] ? 1:0);
}

The complete source code file is as attached.

Thank you in advance for anyone that can help.


Attached Files
Elite Membership required to download: MyCustomIndicator1.cs
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
$4.5M Floods Russia Nuclear Contract in 24 Hours -- Krem …
Prediction Markets & Event Contracts
CFTC Opens First COT Report Review in 20 Years -- Asks W …
Traders Hideout
White House Drops First Alien Files Today -- Market Says …
Prediction Markets & Event Contracts
I Have a Thing Called Iran -- Trump Stays in DC as Airsp …
Prediction Markets & Event Contracts
Saylors 41-Month HODL Breaks: Strategy Sells 32 BTC as $ …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
8 thanks
Darmok and Jalad at Tanagra
1 thanks
  #3 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,099 since Jun 2009
Thanks Given: 877
Thanks Received: 8,098



pooh View Post
I coded a simple indicator for NT8. This indicator is supposed to plot a histogram bar when the previous candle is an up candle. It compiles without problem. However, it just doesn't plot anything. After attaching it to the chart, the indicator window shows blank. The code is very simple, the OnBarUpdate() section only consists of one line. How to fix it ? The source code under OnBarUpdate() is as following:

protected override void OnBarUpdate()
{
Value[0]=(Close[1]>Open[1] ? 1:0);
}

The complete source code file is as attached.

Thank you in advance for anyone that can help.

this is a common mistake of first time coder make, you need to wait for the bar data to be there first
In this case you need to wait for bar[1] before the code can be executed successful
thus;

protected override void OnBarUpdate()
{
if (CurrentBar < 1 ) return; // skip if not bar[1] yet


Value[0]=(Close[1]>Open[1] ? 1:0);
}


Reply With Quote
Thanked by:
  #4 (permalink)
 pooh 
Shanghai, China
 
Experience: Intermediate
Platform: MetaTrader, TWS
Trading: ES
Posts: 30 since Jul 2014
Thanks Given: 62
Thanks Received: 10


cory View Post
this is a common mistake of first time coder make, you need to wait for the bar data to be there first
In this case you need to wait for bar[1] before the code can be executed successful
thus;

protected override void OnBarUpdate()
{
if (CurrentBar < 1 ) return; // skip if not bar[1] yet


Value[0]=(Close[1]>Open[1] ? 1:0);
}

Thank you so much Cory ! I tried your solution and it works ! I pulled all my hair out over that problem and your simple solution fixed it. Really appreciate it.


Started this thread Reply With Quote




Last Updated on February 17, 2019


© 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