コード例 #1
0
ファイル: GUtils.cs プロジェクト: gerryzhou/targetrichtrades
 public static void DisplayProperties <T>(T obj, GIndicatorBase indProxy)
 {
     indProxy.Print(string.Format("DisplayProperties GetType.Name = {0}", obj.GetType().Name));
     foreach (PropertyInfo info in obj.GetType().GetProperties())
     {
         indProxy.Print(string.Format("Name={0}, Val={1}", info.Name, info.GetValue(obj)));
     }
 }
コード例 #2
0
ファイル: GAlert.cs プロジェクト: gerryzhou/targetrichtrades
        public static void LoadAlerConfig(GIndicatorBase indProxy)
        {
            List <string> names = new List <string>()
            {
                "AlertBarsBack", "SoundFileName", "SoundPlayLoop"
            };
            Dictionary <string, object> dic = GConfig.GetConfigItems(GConfig.MainConfigFile, names);
            object altBarsBack, name = null, loop = null;

            if (dic.TryGetValue("AlertBarsBack", out altBarsBack) &&
                dic.TryGetValue("SoundFileName", out name) &&
                dic.TryGetValue("SoundPlayLoop", out loop))
            {
                SoundLoopFilePath = GConfig.GetSoundFileDir() + name.ToString();
                int.TryParse(altBarsBack.ToString(), out AlertBarsBack);
                int.TryParse(loop.ToString(), out SoundLoopCount);
                indProxy.Print(String.Format("LoadAlerConfig AlertBarsBackStr={0}, GetSoundFilePath={1}, SoundPlayLoopStr={2}",
                                             AlertBarsBack, SoundLoopFilePath, SoundLoopCount));
            }
        }
コード例 #3
0
ファイル: GAlert.cs プロジェクト: gerryzhou/targetrichtrades
        public static void PlaySoundFile(AlertMessage msg, GIndicatorBase indProxy)
        {
//			List<string> names = new List<string>(){"SoundFileName", "SoundPlayLoop"};
//			Dictionary<string,object> dic =	GConfig.GetConfigItems(GConfig.MainConfigFile, names);
            if (String.IsNullOrEmpty(SoundLoopFilePath))
            {
                LoadAlerConfig(indProxy);
            }
            SoundPlay soundplay = new SoundPlay(SoundLoopFilePath, SoundLoopCount);

            PlayAlert = true;
            indProxy.Print(String.Format("PlaySoundFile AlertBarsBackStr={0}, GetSoundFilePath={1}, SoundPlayLoopStr={2}",
                                         AlertBarsBack, SoundLoopFilePath, SoundLoopCount));

            Thread thdSoundPlay = new Thread(() => PlaySoundLoop(soundplay));
            Thread thdMsgShow   = new Thread(() => ShowMessage(msg));

            thdSoundPlay.Start();
            thdMsgShow.Start();
//			object name = null, loop = null;
//			if(dic.TryGetValue("SoundFileName", out name) &&
//				dic.TryGetValue("SoundPlayLoop", out loop)) {
//				string path = GConfig.GetSoundFileDir() + name.ToString();
//				indProxy.Print("GetSoundFilePath,SoundPlayLoop=" + path + ", " + loop);

//				SoundPlay soundplay = new SoundPlay(path, loop.ToString());

//				PlayAlert = true;

//				Thread thdSoundPlay = new Thread(() => PlaySoundLoop(soundplay));
//				Thread thdMsgShow = new Thread(() => ShowMessage(msg));

//				thdSoundPlay.Start();
//				thdMsgShow.Start();
//			}
        }
コード例 #4
0
ファイル: GConfig.cs プロジェクト: gerryzhou/targetrichtrades
        public static object ParseProperties(Dictionary <string, ArrayList> dict, string name, Type t, GIndicatorBase indProxy)
        {
            ArrayList list;

            dict.TryGetValue(name, out list);
            object val = null;            // = list[0];

            switch (t.Name)
            {
            case "Double":
                val = Double.Parse(list[0].ToString());
                break;

            case "Int32":
                val = Int32.Parse(list[0].ToString());
                break;

            case "String":
                //val = String.Parse(list[0].ToString());
                break;

            case "Boolean":
                val = Boolean.Parse(list[0].ToString());
                break;

            default:
                val = Enum.Parse(t, list[0].ToString());
                break;
            }
            indProxy.Print(string.Format("ParseProperties== t.Name={0}, Val={1}", t.Name, val));
//			foreach (KeyValuePair<string, ArrayList> pa in dict) {
//				indProxy.Print(string.Format("{0},{1},{2},{3},{4}",
//				pa.Key, pa.Value[0], pa.Value[1], pa.Value[2], val));
//			}
            return(val);
        }
コード例 #5
0
ファイル: GConfig.cs プロジェクト: gerryzhou/targetrichtrades
        /// <summary>
        /// Update the properties for obj with the values in the dictionary
        /// </summary>
        /// <param name="obj">Target object</param>
        /// <param name="cmd_dict">dictionary holds the new values</param>
        /// <param name="indProxy">caller indicator/strategy</param>
        public static void UpdateProperties(object stg, Dictionary <string, object> cmd_dict, GIndicatorBase indProxy)
        {
            Dictionary <string, ArrayList> dict_new = ParseCmdJson(cmd_dict, indProxy);

            try{
                indProxy.Print("==UpdateProperties== " + stg.GetType().FullName);
                foreach (PropertyInfo p in stg.GetType().GetProperties())
                {
                    if (dict_new.Keys.Contains(p.Name))
                    {
                        indProxy.Print(string.Format("SetValue=={0},{1}",
                                                     p.Name, p.PropertyType));    //p.ReflectedType, p.DeclaringType, p.ToString(), GetValue(this, null)
                        p.SetValue(stg, ParseProperties(dict_new, p.Name, p.PropertyType, indProxy));
                    }
                }
            } catch (Exception ex) {
                indProxy.Print("Exception=" + ex.StackTrace);
            }
        }
コード例 #6
0
ファイル: GConfig.cs プロジェクト: gerryzhou/targetrichtrades
        public static bool LoadCtxDaily(ArrayList al_ori, out Dictionary <string, List <MarketContext> > dict_out, GIndicatorBase indProxy)
        {
            dict_out = new Dictionary <string, List <MarketContext> >();
            indProxy.Print("==LoadCtxDaily== " + al_ori.Count);
            foreach (Dictionary <string, object> ctx_daily in al_ori)             //CTX_Daily index=0
            {
                indProxy.Print(String.Format("ctx_daily in al_ori: {0}, {1}", ctx_daily.GetType().ToString(), ctx_daily.Count));
                foreach (KeyValuePair <string, object> date_al in ctx_daily)                 //Date_CTX arraylist (Key=Date, Value=ArrayList_TimeCtx)
                {
                    indProxy.Print(String.Format("date_al.key={0}, date_al.val={1}", date_al.Key, date_al.Value.ToString()));
                    foreach (Dictionary <string, object> dict_time_ctx in date_al.Value as ArrayList)                     //Time_CTX dict (Key=Time, Value=CTX)
                    {
                        indProxy.Print(String.Format("dict_time_ctx.type={0}, dict_time_ctx.count={1}", dict_time_ctx.GetType().ToString(), dict_time_ctx.Count));
                        foreach (KeyValuePair <string, object> time_ctx in dict_time_ctx)                         //Time_CTX item (Key=Time,CTX, Value=int,string)
                        {
                            indProxy.Print(String.Format("time_ctx.Value.type={0}, time_ctx.Key={1}, time_ctx.Value={2}", time_ctx.Value.GetType().ToString(), time_ctx.Key, time_ctx.Value));
                        }
                    }
                }
            }

            return(false);
        }
コード例 #7
0
ファイル: GConfig.cs プロジェクト: gerryzhou/targetrichtrades
        /// <summary>
        //"MktCtxDaily":[
        //      {
        //         "Date":"20170607",
        //         "TimeCtxs":[
        //            {
        //               "Time":8401151,
        //               "ChannelType":"UpTight",
        //			   "Support":8600.75, "Resistance":9600.75,
        //               "MinUp":12, "MaxUp":16, "MinDn":3, "MaxDn":5
        //            },
        //            {
        //               "Time":11521459,
        //               "ChannelType":"RngTight",
        //			   "Support":8978.25, "Resistance":9270.75,
        //               "MinUp":10, "MaxUp":16, "MinDn":4, "MaxDn":6
        //            }
        //         ]
        //      },
        //	......
        // ]
        /// </summary>
        /// <param name="dict_ori"></param>
        /// <returns></returns>
        public static Dictionary <string, List <MarketContext> > ParseCTXJson(Dictionary <string, object> dict_ori, GIndicatorBase indProxy)
        {
            Dictionary <string, List <MarketContext> > dict_new = null;          // = new Dictionary<string, List<MarketContext>>();
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            indProxy.Print("==ParseCTXJson== " + dict_ori.Count);
            //Get the array for parameter row at CMD JSON file
            try{
                foreach (ArrayList val in dict_ori.Values)
                {
                    indProxy.Print(string.Format("{0}, {1}", val.ToString(), val.Count));

                    //List<MarketContext> list = serializer.Deserialize<List<MarketContext>>(val.ToString());
                    //				foreach(Dictionary<string, object> obj in val) {
                    //					indProxy.Print(string.Format("{0},{1}",	obj.GetType(), obj.Count));
                    //					foreach (KeyValuePair<string, object> pa in obj) {
                    //						dict_new.Add(pa.Key, pa.Value as List<MarketContext>);
                    //					}
                    //					//Dictionary<string, object> dict = serializer.Deserialize<Dictionary<string, object>>(obj.ToString());
                    //				}
                    LoadCtxDaily(val, out dict_new, indProxy);
                    if (dict_new != null)
                    {
                        indProxy.Print("==dict_new== " + dict_new.Count);
                        foreach (KeyValuePair <string, List <MarketContext> > pa in dict_new)
                        {
                            indProxy.Print(string.Format("{0},{1}", pa.Key, pa.Value[0]));
                        }
                    }
                }
            } catch (Exception ex) {
                indProxy.Print("Exception=" + ex.StackTrace);
            }

            return(dict_new);
        }
コード例 #8
0
ファイル: GConfig.cs プロジェクト: gerryzhou/targetrichtrades
        /// <summary>
        /// Transfer the key/value from the original CMD JSON into a new dictionary
        /// "Indicator":[
        /// {"EnBarsBeforeInflection":[ "2", "Int32", "Bars count before inflection for entry"]},
        /// {"BarsLookback":[ "2", "Int32", "Bars count before inflection for entry"]}
        /// ],
        /// </summary>
        /// <param name="dict_ori"></param>
        /// <returns></returns>
        public static Dictionary <string, ArrayList> ParseCmdJson(Dictionary <string, object> dict_ori, GIndicatorBase indProxy)
        {
            Dictionary <string, ArrayList> dict_new   = new Dictionary <string, ArrayList>();
            JavaScriptSerializer           serializer = new JavaScriptSerializer();

            indProxy.Print("==ParseCmdJson== " + dict_ori.Count);
            //Get the array for parameter row at CMD JSON file
            try{
                foreach (ArrayList val in dict_ori.Values)
                {
                    indProxy.Print(string.Format("dict_ori.val: {0}, {1}", val.ToString(), val.Count));
                    //List<object> list = serializer.Deserialize<List<object>>(val.ToString());
                    foreach (Dictionary <string, object> obj in val)
                    {
                        indProxy.Print(string.Format("dict_ori.val.dict: {0}, {1}", obj.GetType(), obj.Count));
                        foreach (KeyValuePair <string, object> pa in obj)
                        {
                            dict_new.Add(pa.Key, pa.Value as ArrayList);
                        }
                        //Dictionary<string, object> dict = serializer.Deserialize<Dictionary<string, object>>(obj.ToString());
                    }
                }
            } catch (Exception ex) {
                indProxy.Print("Exception=" + ex.StackTrace);
            }

            indProxy.Print("==dict_new== " + dict_new.Count);
            foreach (KeyValuePair <string, ArrayList> pa in dict_new)
            {
                indProxy.Print(string.Format("{0},{1}", pa.Key, pa.Value[0]));
            }

            return(dict_new);
        }
コード例 #9
0
 /// <summary>
 /// Check if divergence occurs in this indicator;
 /// </summary>
 /// <returns></returns>
 public virtual DivergenceType CheckDivergence(GIndicatorBase indicator)
 {
     return(DivergenceType.UnKnown);
 }
コード例 #10
0
 /// <summary>
 /// Direction is to tell up/down, buy or sell;
 /// </summary>
 /// <returns></returns>
 public virtual Direction GetDirection(GIndicatorBase indicator)
 {
     return(null);
 }