Need some help for c sharp scripting - NinjaTrader Programming | futures trading

Go Back

> Futures Trading, News, Charts and Platforms > Platforms and Indicators > NinjaTrader > NinjaTrader Programming

Need some help for c sharp scripting
Started:July 9th, 2014 (10:06 PM) by hugebaozi Views / Replies:308 / 1
Last Reply:July 9th, 2014 (10:06 PM) Attachments:0

Welcome to

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Thread Tools Search this Thread

Need some help for c sharp scripting

Old July 9th, 2014, 10:06 PM   #1 (permalink)
Trading Apprentice
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: ES
Posts: 1 since Jul 2014
Thanks: 0 given, 0 received

Need some help for c sharp scripting

Hi all:
I am new to c# and ninjatrader.. and i tried to make some simple strategy work. Now i just to long SPY when sma(10)>sma(20) and sell the other way.
1. About Add(some indicators), could i also specify the color?
2. In my code , I first want to Add(sma10), it looks like i can't do this. So how could i initialize a indicator object?
3. In my code, I tried to call BackColorAll = Color.Green; Yet the backtest result does not show any green color on the chart though the trading log did execute some selling orders.
4. In general , my logic is to first check if my position is empty, if so, check the long condition. if my position is not empty, check the short condition.

Could someone help check where i goes wrong?
public class Crossover01 : Strategy
        #region Variables
        // Wizard generated variables
        private int myInput0 = 1; // Default setting for MyInput0
        // User defined variables (add any user defined variables below)

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
		private IOrder entryOrder = null;
        protected override void Initialize()
            CalculateOnBarClose = true;
			//global stop loss
			SetStopLoss(CalculationMode.Percent, 0.07);

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
			var sma10 = SMA(10);
			var sma20 = SMA(20);
			var sma50 = SMA(50);
			if(entryOrder == null)
				if(CrossAbove(sma10,sma20,1)&& Rising(sma50) == true)
					BackColorAll = Color.Red;
			else if (entryOrder != null)
				if (CrossBelow(sma10,sma20,1)|| Falling(sma50) == true)
					BackColorAll = Color.Green;
				entryOrder = null;

        #region Properties
        public int MyInput0
            get { return myInput0; }
            set { myInput0 = Math.Max(1, value); }

Reply With Quote

Old July 9th, 2014, 10:06 PM   #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.


Reply > Futures Trading, News, Charts and Platforms > Platforms and Indicators > NinjaTrader > NinjaTrader Programming > Need some help for c sharp scripting

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Upcoming Webinars and Events (4:30PM ET unless noted)

NinjaTrader 8: Programming Profitable Trading Edges w/Scott Hodson

Elite only

Anthony Drager: Executing on Intermarket Correlations & Order Flow, Part 2

Elite only

Adam Grimes: Five critically important keys to professional trading

Elite only

Machine Learning Concepts w/FIO member NJAMC

Elite only

MarketDelta Cloud Platform: Announcing new mobile features

Dec 1

NinjaTrader 8: Features and Enhancements

Dec 6

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting TWS on a Mac fritzybloch IB Trader Workstation 1 May 26th, 2016 10:56 AM
Does TWS Offer Built-In Scripting? TraitorX IB Trader Workstation 0 January 11th, 2014 11:50 PM
Sharp Slowdown in China Sparks Call for Fiscal Stimulus Quick Summary News and Current Events 0 May 14th, 2012 12:50 AM
Newbie scripter needs help scripting MT4 LWMA indicator kashix MetaTrader 1 April 27th, 2012 02:47 PM
IMF Says Threat of Sharp Global Slowdown Has Eased Quick Summary News and Current Events 0 March 2nd, 2012 12:40 AM

All times are GMT -4. The time now is 08:34 AM.

Copyright © 2016 by 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.
no new posts

Page generated 2016-10-28 in 0.07 seconds with 19 queries on phoenix via your IP