NexusFi: Find Your Edge


Home Menu

 





Drawing dots based on a condition


Discussion in NinjaTrader

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




 
Search this Thread
  #1 (permalink)
 rdh009 
Providenciales Turks and Caicos
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES
Posts: 3 since Apr 2014
Thanks Given: 0
Thanks Received: 0

Hi,

I am new to coding in NinjaTrader. I have done some coding in EasyLanguage, AmiBroker and Python, but I'm just a trial and error guy, not a 'proper' coder.

As a first foray into Ninja, I am trying to draw a dot beneath bars based on a condition being true.

if I make my condition as simple as possible, like this:

 
Code
if (Close[0] < Open[0])
-- the dots display correctly.

But, if I try to refer to previous bars, like this:

 
Code
if (Close[0] < Open[1])
-- the code does not work. So, I assume it is the condition itself which I am getting wrong.

Can anybody explain why this change would stop the code working, and how I would correctly refer to previous bars?

Any help appreciated.

Here's the rest of the code.

 
Code
protected override void OnBarUpdate()
        {

			{	
				
				if (Close[0] < Open[0]) 
				//if (Close[1] > Open[1])
				//if(Close[1] < Close[0] && Close[1] < Close[2])
					
					{ 
						myBarCloses=1;
					} else {
						myBarCloses=0;
					}
					
					if (myBarCloses==1) 
					{
						DrawDot(CurrentBar.ToString() +"BarCloseDot",true, 0, Low[0]*0.997, Color.Magenta);
					}
					
			}      
			
        }


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Zytrade: Devin Brady, CEO - Ask Me Anything (AMA)
Brokers
Khamenei Vetoes Uranium Transfer as Peace Odds Surge to …
Prediction Markets & Event Contracts
Rubios Good News Within Hours and the 30-Day Math: Why H …
Prediction Markets & Event Contracts
Bond Market Rout -- Worst Week Since Russias 2022 Invasi …
Treasury Notes and Bonds
CME Launches Bitcoin Volatility Futures June 1 -- First …
Cryptocurrency
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
23 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
  #3 (permalink)
 rdh009 
Providenciales Turks and Caicos
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES
Posts: 3 since Apr 2014
Thanks Given: 0
Thanks Received: 0


In case anybody else has a need for this information, it requires a check for enough bars in the data series you are accessing.

I don't know whether posting external links is permitted, so I'll assume it is not. A Google search should find the info.

I had to amend the code as below.


 
Code
protected override void OnBarUpdate()
{
    if (CurrentBar < 1)
        return;

    if (Close[0] < Open[1])
        // etc
}


Started this thread Reply With Quote
  #4 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,971 since Jun 2009
Thanks Given: 534
Thanks Received: 3,711

What do you mean "it does not work"? What exactly do you do and then what happens?
Is this for a strategy or an indicator?
Have you checked the "Log" tab in the "Control Center" for any runtime error messages? If so what do they say?


Follow me on X Visit my NexusFi Trade Journal Reply With Quote




Last Updated on June 7, 2016


© 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