NexusFi: Find Your Edge


Home Menu

 





Drawing dots based on a condition


Discussion in NinjaTrader

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




 
Search this Thread

Drawing dots based on a condition

  #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?
REcommedations for programming help
Sierra Chart
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
43 thanks
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
21 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,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709

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 Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on June 7, 2016


© 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