NexusFi: Find Your Edge


Home Menu

 





How to fix this problem ?


Discussion in NinjaTrader

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




 
Search this Thread

How to fix this problem ?

  #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?
ZombieSqueeze
Platforms and Indicators
Quantum physics & Trading dynamics
The Elite Circle
What broker to use for trading palladium futures
Commodities
REcommedations for programming help
Sierra Chart
MC PL editor upgrade
MultiCharts
 
  #3 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090



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


© 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