Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Adding buy/sell signals to SMI indicator/newbie help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Adding buy/sell signals to SMI indicator/newbie help

    Hi,

    I've been staring at the screen for hours and out of ideas. Desperate for help

    I'd like to add simple up triangles when the fast smi crosses over the average smi and down triangles when it crosses lower. so when the SMI is > SMI average for the previous bar, and then the current bar SMI < SMI average hits for the current bar, the next bar will issue a sell signal.

    Where I should start?


    Code:
    		protected override void Initialize()
    		{
    			Add(new Plot(new Pen(Color.Green,2), PlotStyle.Line, "SMI"));//Plot0
    			Add(new Plot(new Pen(Color.Red,2), PlotStyle.Line, "AvgSMI"));//Plot1
    			
    			Add(new Line(Color.Gray, -40, "Lower"));
    			Add(new Line(Color.Gray, 40, "Upper"));
    			
    			rel_diff	= new DataSeries(this);
    			diff		= new DataSeries(this);
    			
    			CalculateOnBarClose = false;
    			AutoScale 			= false;
    		}
    
    		/// <summary>
    		/// Calculates the indicator value(s) at the current index.
    		/// </summary>
    		protected override void OnBarUpdate()
    		{
    			if(CurrentBar < percentKLength || CurrentBar < percentDLength)return;
    			
    			double min_low = MIN(Low, percentKLength)[0];
    			double max_high = MAX(High, percentKLength)[0];
    			rel_diff.Set(Close[0] - (max_high + min_low)/2);
    			diff.Set(max_high - min_low);
    			
    			double avgrel = EMA(EMA(rel_diff, percentDLength), percentDLength)[0];
    			double avgdiff = EMA(EMA(diff, percentDLength), percentDLength)[0];
    			
    			smi.Set(avgrel/(avgdiff/2)*100);
    			AvgSMI.Set(EMA(smi, percentDLength)[0]);
    			
    			
    		}

    #2
    Hello big_leon,

    Thank you for your note.

    I would suggest seeing the SampleMACrossOver strategy preloaded on NinjaTrader for an example of how you could build a strategy which would buy/sell when two plots calculated in an indicator cross. To view this strategy go to Control Center>Tools>Edit NinjaScript>Strategy>SampleMACrossOver.

    In the sample strategy, CrossAbove would imply that Fast was below the Slow on the previous bar.

    I’ve provided a link to the strategy wizard youtube which covers setting up a cross strategy,
    Understand the fundamentals of basic strategy creation by developing an actual strategy using the NinjaTrader Strategy Wizard.3:23 Strategy Wizard Overview7:...


    I’ve also included a link to our helpguide which covers building a simple moving average cross,
    Helpguide: http://ninjatrader.com/support/helpG..._cross_ove.htm

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,606 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    9 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    19 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    6 views
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    15 views
    0 likes
    Last Post Javierw.ok  
    Working...
    X