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 guillembm, Yesterday, 11:25 AM
    2 responses
    9 views
    0 likes
    Last Post guillembm  
    Started by junkone, 04-21-2024, 07:17 AM
    9 responses
    68 views
    0 likes
    Last Post jeronymite  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    4 responses
    18 views
    0 likes
    Last Post trilliantrader  
    Started by mgco4you, Yesterday, 09:46 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by wzgy0920, Yesterday, 09:53 PM
    0 responses
    10 views
    0 likes
    Last Post wzgy0920  
    Working...
    X