コード例 #1
0
        protected override void OnCalculate()
        {
            //get the indicator
            Example_Indicator_SMA_CrossOver_Basic Example_Indicator_SMA_CrossOver_Basic = LeadIndicator.Example_Indicator_SMA_CrossOver_Basic();

            //get the value
            double returnvalue = Example_Indicator_SMA_CrossOver_Basic[0];

            //Condition should be drawn on a seperate panel
            this.IsOverlay = false;

            //set the value
            Occurred.Set(returnvalue);
        }
コード例 #2
0
        /// <summary>
        /// Basic indicator example for SMA crossover
        /// </summary>
        public Example_Indicator_SMA_CrossOver_Basic Example_Indicator_SMA_CrossOver_Basic(IDataSeries input)
        {
            var indicator = CachedCalculationUnits.GetCachedIndicator <Example_Indicator_SMA_CrossOver_Basic>(input);

            if (indicator != null)
            {
                return(indicator);
            }

            indicator = new Example_Indicator_SMA_CrossOver_Basic
            {
                RequiredBarsCount    = RequiredBarsCount,
                CalculateOnClosedBar = CalculateOnClosedBar,
                InSeries             = input
            };
            indicator.SetUp();

            CachedCalculationUnits.AddIndicator2Cache(indicator);

            return(indicator);
        }
コード例 #3
0
        protected override void OnCalculate()
        {
            string uniqueOrderName;

            //get the indicator
            Example_Indicator_SMA_CrossOver_Basic Example_Indicator_SMA_CrossOver_Basic = LeadIndicator.Example_Indicator_SMA_CrossOver_Basic();

            //get the value
            double returnvalue = Example_Indicator_SMA_CrossOver_Basic[0];

            //Entry
            if (returnvalue == 1)
            {
                //define a unique name for the order. in this example the current bars timestamp
                uniqueOrderName = "Long_SMA_CrossOver" + Bars[0].Time.ToString();

                //create the long order with quantity "1" and our unique OrderName
                IOrder _orderenterlong = OpenLong(1, uniqueOrderName);

                //set a stop loss for our order. we set it 1% below the current price
                SetUpStopLoss(_orderenterlong.Name, CalculationMode.Price, Bars[0].Close * 0.99, false);

                //set a target for our order. we set it 1% above the current price
                SetUpProfitTarget(_orderenterlong.Name, CalculationMode.Price, Bars[0].Close * 1.01);
            }
            else if (returnvalue == -1)
            {
                //define a unique name for the order. in this example the current bars timestamp
                uniqueOrderName = "Short_SMA_CrossOver" + Bars[0].Time.ToString();

                //create the short order with quantity "1" and our unique OrderName
                IOrder _orderentershort = OpenShort(1, uniqueOrderName);

                //set a stop loss for our order. we set it 1% above the current price
                SetUpStopLoss(_orderentershort.Name, CalculationMode.Price, Bars[0].Close * 1.01, false);

                //set a target for our order. we set it 1% below the current price
                SetUpProfitTarget(_orderentershort.Name, CalculationMode.Price, Bars[0].Close * 0.99);
            }
        }