Exemple #1
0
 public void Initialize(HostPanelForIndicator panelNamedFolding)
 {
     this.HostPanelForIndicator       = panelNamedFolding;
     this.closesProxyEffective_cached = null;
     this.barsEffective_cached        = null;
     this.BuildParametersFromAttributes();
     this.OwnValuesCalculated.Clear();
     //this.OwnValuesCalculated.Description = this.Name;	//appears after .BuildParametersFromAttributes();
     this.OwnValuesCalculated.Description = this.NameWithParameters;
 }
Exemple #2
0
        public void IndicatorsInstantiateStoreInSnapshot()
        {
            this.Executor.ExecutionDataSnapshot.Indicators.Clear();
            Type myChild = this.GetType();

            PropertyInfo[] lookingForIndicators = myChild.GetProperties();
            foreach (PropertyInfo propertyIndicator in lookingForIndicators)
            {
                Type hopefullyIndicatorChildType = propertyIndicator.PropertyType;
                bool isIndicatorChild            = typeof(Indicator).IsAssignableFrom(hopefullyIndicatorChildType);
                if (isIndicatorChild == false)
                {
                    continue;
                }

                Indicator indicatorInstance = null;
                var       expectingNull     = propertyIndicator.GetValue(this, null);
                if (expectingNull != null)
                {
                    indicatorInstance = expectingNull as Indicator;
                    //Debugger.Break();
                    //continue;
                }
                else
                {
                    object indicatorInstanceUntyped = Activator.CreateInstance(hopefullyIndicatorChildType);
                    indicatorInstance = indicatorInstanceUntyped as Indicator;
                    if (indicatorInstance == null)
                    {
                        Debugger.Break();
                        continue;
                    }
                }

                indicatorInstance.Name = propertyIndicator.Name;
                //MORE_EFFECTIVE_IN_Indicator.NotOnChartBarsKey_get()  indicatorInstance.OwnValuesCalculated.ScaleInterval = this.Bars.ScaleInterval;

                //indicatorInstance.BuildParametersFromAttributes();	//indicatorInstance.Initialize() invokes BuildParametersFromAttributes();
                HostPanelForIndicator priceOrItsOwnPanel = this.Executor.ChartShadow.GetHostPanelForIndicator(indicatorInstance);
                indicatorInstance.Initialize(priceOrItsOwnPanel);

                #region overwriting IndicatorParameters from Strategy attributes; similar to Indicator.BuildParametersFromAttributes()
                object[] attributes             = propertyIndicator.GetCustomAttributes(typeof(IndicatorParameterAttribute), true);
                string   attributesAllAvailable = "";
                foreach (object attrObj in attributes)
                {
                    IndicatorParameterAttribute attr = attrObj as IndicatorParameterAttribute;
                    if (attributesAllAvailable.Length > 0)
                    {
                        attributesAllAvailable += ",";
                    }
                    attributesAllAvailable += attr;
                }
                foreach (object attrObj in attributes)
                {
                    IndicatorParameterAttribute attr  = attrObj as IndicatorParameterAttribute;
                    IndicatorParameter          param = new IndicatorParameter(attr);

                    if (indicatorInstance.ParametersByName.ContainsKey(param.Name) == false)
                    {
                        string msg = "SCRIPT_SETS_ATTRIBUTE_FOR_INDICATOR_WHICH_IT_DOESNT_HAVE#1 param[" + param + "] attributesAllAvailable[" + attributesAllAvailable + "]";
                        Assembler.PopupException(msg);
                        continue;
                    }
                    // strategy has an Indicator and an attribute for that indicator; find matching property in the indicator & overwrite
                    PropertyInfo   propertyIndicatorFoundUnique  = null;
                    PropertyInfo[] lookingForIndicatorParameters = indicatorInstance.GetType().GetProperties();
                    foreach (PropertyInfo propertyIndicatorInstance in lookingForIndicatorParameters)
                    {
                        if (propertyIndicatorInstance.Name != param.Name)
                        {
                            continue;
                        }
                        propertyIndicatorFoundUnique = propertyIndicatorInstance;
                        break;
                    }
                    if (propertyIndicatorFoundUnique == null)
                    {
                        string msg = "SCRIPT_SETS_ATTRIBUTE_FOR_INDICATOR_WHICH_IT_DOESNT_HAVE#2 param[" + param + "] attributesAllAvailable[" + attributesAllAvailable + "]";
                        Assembler.PopupException(msg);
                        continue;
                    }
                    object valueCurrentCasted = param.ValueCurrent;
                    if (propertyIndicatorFoundUnique.PropertyType.Name == "Int32")
                    {
                        valueCurrentCasted = (int)Math.Round(param.ValueCurrent);
                    }
                    propertyIndicatorFoundUnique.SetValue(indicatorInstance, valueCurrentCasted, null);
                    indicatorInstance.ParametersByName[param.Name] = param;
                }
                // resetting it for fair recalculation to include parameters into this.NameWithParameters; it isn't redundant!
                indicatorInstance.parametersAsStringShort = null;
                #endregion
                propertyIndicator.SetValue(this, indicatorInstance, null);
                this.Executor.ExecutionDataSnapshot.Indicators.Add(propertyIndicator.Name, indicatorInstance);
            }
        }
		public void Initialize(HostPanelForIndicator panelNamedFolding) {
			this.HostPanelForIndicator = panelNamedFolding;
			this.closesProxyEffective_cached = null;
			this.barsEffective_cached = null;
			this.BuildParametersFromAttributes();
			this.OwnValuesCalculated.Clear();
			//this.OwnValuesCalculated.Description = this.Name;	//appears after .BuildParametersFromAttributes();
			this.OwnValuesCalculated.Description = this.NameWithParameters;
		}