NexusFi: Find Your Edge


Home Menu

 





Been at it for hours...Definitely something simple!!! AHHHHH


Discussion in NinjaTrader

Updated
    1. trending_up 4,456 views
    2. thumb_up 7 thanks given
    3. group 2 followers
    1. forum 23 posts
    2. attach_file 4 attachments




 
Search this Thread

Been at it for hours...Definitely something simple!!! AHHHHH

  #1 (permalink)
 
Tanju23's Avatar
 Tanju23 
Riverview Fl
 
Experience: Intermediate
Platform: Ninja Trader
Broker: Mirus Futures
Trading: ES, TF
Posts: 37 since Dec 2009
Thanks Given: 24
Thanks Received: 4



I literally have been at this for hours. I have managed to get the line to be 2 solid colors no matter what I try and the fact that I know its something simple is killing me.
I trying to get the average to change colors when one of two conditions are met, then change if the opposite first or second condition is met.
Please help if its something simple, if its not let me know and ill keep trying. Maybe just some insight to get me in the right direction.

on a side note, I didn't know how to get the code on my post in the little code window that I see all over the forum. How do you do that?

{
if (High[0] > Swing(swings).SwingHigh[0]);
else if (Low[0] >= EMA(keltner)[0] + Spread * TickSize);

{
PlotColors[0][0] = sMAUp;
}
}

{
if (Low[0] < Swing(swings).SwingLow[0]);
else if (High[0] <= EMA(keltner)[0] - Spread * TickSize);

{
PlotColors[0][0] = sMADn;
}
}

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Increase in trading performance by 75%
The Elite Circle
MC PL editor upgrade
MultiCharts
Trade idea based off three indicators.
Traders Hideout
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
18 thanks
GFIs1 1 DAX trade per day journal
16 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
  #3 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623


@Tanju23,

To fix your code remove the semicolon ";" from your if/else if lines:

 
Code
if (High[0] > Swing(swings).SwingHigh[0])
{
    // something
}
else if (Low[0] >= EMA(keltner)[0] + Spread * TickSize)
{
    PlotColors[0][0] = sMAUp;
}
if (Low[0] < Swing(swings).SwingLow[0])
{
    // something
}
else if (High[0] <= EMA(keltner)[0] - Spread * TickSize)
{
    PlotColors[0][0] = sMADn;
}
to put the code in the code box - there is a hash "#" button in the toolbar (that's where you change the fonts) - this will give you the right tags for code.

Reply With Quote
  #4 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623

If you are rather new to programming then I would also recommend to ALWAYS use curly braces with conditions ie: never leave the if, else if and else without accompanying curly braces. So that after closing bracket there are always curly braces (even if empty!):

 
Code
if (someCondition == true)
{
}
else 
{
}
This will help you to avoid many problems at the start.

Reply With Quote
  #5 (permalink)
 
Tanju23's Avatar
 Tanju23 
Riverview Fl
 
Experience: Intermediate
Platform: Ninja Trader
Broker: Mirus Futures
Trading: ES, TF
Posts: 37 since Dec 2009
Thanks Given: 24
Thanks Received: 4

Thanks for the response. When I try what you say....
 
Code
{
				// If high breaks a swing high
				if (High[0] > Swing(swings).SwingHigh[0])
				// If low is greater than Keltner MB a certain # of ticks
				else if (Low[0] >= EMA(keltner)[0] + Spread * TickSize)
				
				{
					PlotColors[0][0] = sMAUp;
				}
			}
			
			{
				// If low breaks a swing low
				if (Low[0] < Swing(swings).SwingLow[0])
				// If high is less than Keltner MB a certain # of ticks
				else if (High[0] <= EMA(keltner)[0] - Spread * TickSize)
				
				{
					PlotColors[0][0] = sMADn;
				}
			}

It displays these errors. Am i not using the else if in the proper function for a comparison of the 2 conditions?

Started this thread Reply With Quote
  #6 (permalink)
 
Tanju23's Avatar
 Tanju23 
Riverview Fl
 
Experience: Intermediate
Platform: Ninja Trader
Broker: Mirus Futures
Trading: ES, TF
Posts: 37 since Dec 2009
Thanks Given: 24
Thanks Received: 4

just saw your most recent response, i will try that.

Started this thread Reply With Quote
  #7 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623

It is not clear from your code but it seems to me that this is what you were trying to achieve:
 
Code
// If high breaks a swing high
if (High[0] > Swing(swings).SwingHigh[0])
{
    // If low is greater than Keltner MB a certain # of ticks
    if (Low[0] >= EMA(keltner)[0] + Spread * TickSize)
    {
        PlotColors[0][0] = sMAUp;
     }
}		
// If low breaks a swing low
if (Low[0] < Swing(swings).SwingLow[0])
{
    // If high is less than Keltner MB a certain # of ticks
    if (High[0] <= EMA(keltner)[0] - Spread * TickSize)
    {
        PlotColors[0][0] = sMADn;
    }
}
Also, you have some superfluous braces used for separation of the code (eg. before your if statement) - this is not a good practice either for a beginner - use the braces after a condition/method etc. not before:

 
Code
//Bad:
{
if(something)
}

//Good:
if(something)
{
}

Reply With Quote
Thanked by:
  #8 (permalink)
 
Tanju23's Avatar
 Tanju23 
Riverview Fl
 
Experience: Intermediate
Platform: Ninja Trader
Broker: Mirus Futures
Trading: ES, TF
Posts: 37 since Dec 2009
Thanks Given: 24
Thanks Received: 4

After separating with brackets like you said I am actually making progress.



It initially changes to magenta and should stay until one of the"up" conditions are met. Is there something that i am missing that would keep the 2 sets of conditions separate? And you guessed it, I am new to programming. Just starting to get my feet wet.


Started this thread Reply With Quote
  #9 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623

If you want the condition to trigger to either of the 2 - you need to use or: "||"

 
Code
if (condition1 || condition2)
{
    //change color
}

Reply With Quote
Thanked by:
  #10 (permalink)
 
Tanju23's Avatar
 Tanju23 
Riverview Fl
 
Experience: Intermediate
Platform: Ninja Trader
Broker: Mirus Futures
Trading: ES, TF
Posts: 37 since Dec 2009
Thanks Given: 24
Thanks Received: 4


Thank you, gonna give that a try now.

Started this thread Reply With Quote




Last Updated on April 16, 2015


© 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