NexusFi: Find Your Edge


Home Menu

 





Need some help for c sharp scripting


Discussion in NinjaTrader

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




 
Search this Thread

Need some help for c sharp scripting

  #1 (permalink)
hugebaozi
Chicago
 
Posts: 1 since Jul 2014
Thanks Given: 0
Thanks Received: 0

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?
 
Code
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)
        #endregion

        /// <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);
			SetProfitTarget(CalculationMode.Percent,0.1);
			//Add(sma10);
			//Add(sma20);
			Add(SMA(10));
			Add(SMA(20));
        }

        /// <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)
				{
					EnterLong();
					BackColorAll = Color.Red;
				}
			}
			else if (entryOrder != null)
			{
				if (CrossBelow(sma10,sma20,1)|| Falling(sma50) == true)
				{
					EnterShort();
					BackColorAll = Color.Green;
				}
				entryOrder = null;
			}
        }

        #region Properties
        [Description("")]
        [GridCategory("Parameters")]
        public int MyInput0
        {
            get { return myInput0; }
            set { myInput0 = Math.Max(1, value); }
        }
        #endregion
    }

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
About a successful futures trader who didnt know anythin …
Psychology and Money Management
REcommedations for programming help
Sierra Chart
Cheap historycal L1 data for stocks
Stocks and ETFs
Better Renko Gaps
The Elite Circle
 




Last Updated on July 9, 2014


© 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