private void btnLoad_Click(object sender, EventArgs e) { List <Model.Idea> ideas = Common.GetIdeas(); List <Model.Technical> ti = new List <Model.Technical>(); foreach (var item in radCheckedListBox1.Items) { if (item.CheckState == Telerik.WinControls.Enumerations.ToggleState.On) { switch (item.Text) { case "SuperTrend": ti.Add(Model.Technical.SuperTrend); break; case "Simple Moving Average": ti.Add(Model.Technical.SimpleMovingAverage); break; case "MACD": ti.Add(Model.Technical.MACD); break; case "Bollinger Band": ti.Add(Model.Technical.BollingerBand); break; } } } Model.Idea newIdea = new Model.Idea { Interval = Convert.ToInt32(txtInterval.Text), Name = txtIdeaName.Text, Stoploss = radDropDownList1.SelectedIndex, TI = ti, EntryStartCandle = Convert.ToInt16(txtEntryStartCandle.Text), EntryFinishCandle = Convert.ToInt16(txtEntryFinishCandle.Text), TradePerSession = Convert.ToInt16(txtTradePerSession.Text), FilterByVolume = Convert.ToInt16(txtFilterByVolume.Text), CandleType = (Model.CandleType)radCandType.SelectedIndex, Range = (Model.Range)ddlRange.SelectedIndex, Sorting = (Model.Sorting)ddlSorting.SelectedIndex, OrderMultiples = (Model.OrderMultiples)ddlOrder.SelectedIndex, Risk = Convert.ToDouble(txtRisk.Text) }; if (ideas.Where(a => a.Name == newIdea.Name).Count() == 0) { ideas.Add(newIdea); } string json = JsonConvert.SerializeObject(ideas.ToArray()); File.WriteAllText(Common.strategyFileName, json); }
private void RadButton2_Click_1(object sender, EventArgs e) { // ConcurrentBag<List<Model.PNL>> consolidated = new ConcurrentBag<List<Model.PNL>>(); try { Parallel.ForEach((radDropDownList1.Items), (x) => { ProgressDelegate myProgres = ShowMyProgress; List <Model.Idea> myideas = Common.GetIdeas(); Model.Idea selectedIdea = myideas.Where(a => a.Name == x.Text).First(); StockOHLC stockOHLC = new StockOHLC(); int year = 2019; //for (int year = 2015; year <= 2019; year++) //{ //Load Data Task <Dictionary <string, List <Model.Candle> > > loadmydata = Task.Run <Dictionary <string, List <Model.Candle> > >(() => stockOHLC.GetOHLC(new DateTime(year, Convert.ToInt32(ddlStartMonth.SelectedItem.Text), Convert.ToInt32(ddlStartDate.SelectedItem.Text)), new DateTime(year + 1, Convert.ToInt32(ddlEndMonth.SelectedItem.Text), Convert.ToInt32(ddlEndDate.SelectedItem.Text)), selectedIdea.Interval, myProgres)); //Apply indicators loadmydata.ContinueWith((t0) => { SetText("Applying indicators"); Task <Dictionary <string, List <Model.Candle> > > withIndicators = Task.Run <Dictionary <string, List <Model.Candle> > >(() => TechnicalIndicators.AddIndicators(t0.Result, selectedIdea.TI, new DateTime(year, Convert.ToInt32(ddlStartMonth.SelectedItem.Text), Convert.ToInt32(ddlStartDate.SelectedItem.Text)), new DateTime(Convert.ToInt32(ddlEndYear.SelectedItem.Text), Convert.ToInt32(ddlEndMonth.SelectedItem.Text), Convert.ToInt32(ddlEndDate.SelectedItem.Text)))); Task getTradingStocks = withIndicators.ContinueWith((t1) => { Task <Dictionary <Guid, Model.StrategyModel> > getTradedStocks = Task.Run <Dictionary <Guid, Model.StrategyModel> >(() => stockOHLC.GetTopMostSolidGapOpenerDayWise(t1.Result, selectedIdea, myProgres)); Task tradeMyStocks = getTradedStocks.ContinueWith((t2) => { Task <List <Model.PNL> > calculation = Task <List <Model.PNL> > .Run(() => stockOHLC.TradeStocks(t2.Result, t1.Result, selectedIdea, myProgres)); calculation.ContinueWith((t3) => { consolidated.Add(t3.Result); //SetDataSource(t3.Result); //SetText("Idea ran successfully"); }); }); }); }); //} }); //while(consolidated.Count()< radDropDownList1.Items.Count) //{ // Thread.Sleep(10000); //} } catch (Exception ex) { File.AppendAllText(@"C:\Jai Sri Thakur Ji\Nifty Analysis\errors.txt", Environment.NewLine); File.AppendAllText(@"C:\Jai Sri Thakur Ji\Nifty Analysis\errors.txt", System.Reflection.MethodBase.GetCurrentMethod() + " :- " + ex.Message); File.AppendAllText(@"C:\Jai Sri Thakur Ji\Nifty Analysis\errors.txt", System.Reflection.MethodBase.GetCurrentMethod() + " :- " + ex.StackTrace); File.AppendAllText(@"C:\Jai Sri Thakur Ji\Nifty Analysis\errors.txt", System.Reflection.MethodBase.GetCurrentMethod() + " :- " + ex.InnerException); } }
public ActionResult Create(IdeaModel model) { if (ModelState.IsValid) { ProjectPlannerContext ctx = new ProjectPlannerContext(); User currentUser = ctx.Users.SingleOrDefault(u => u.Username.Equals(User.Identity.Name)); Idea idea = new Idea { Name = model.Name, BriefDescription = model.BriefDescription, Description = model.Description }; currentUser.Suggestions.Add(idea); ctx.SaveChanges(); return Json(idea.IdeaID); } return View(model); }
public StopTarget(StrategyModel current, Idea stoplossidea) { int stoploss = stoplossidea.Stoploss; if (stoploss == 0) { this.StopLossRange = (current.High - current.Low) / 2.0; this.Stoploss = (current.CandleType == "G") ? (current.Close - this.StopLossRange) : (current.Close + this.StopLossRange); this.BookProfit1 = (current.CandleType == "G") ? (current.Close + this.StopLossRange) : (current.Close - this.StopLossRange); this.BookProfit2 = (current.CandleType == "G") ? (current.Close + (2.0 * this.StopLossRange)) : (current.Close - (2.0 * this.StopLossRange)); } else if (stoploss == 1) { this.StopLossRange = (current.Trade == Trade.BUY) ? (current.High - current.Low) : (current.High - current.Low); this.Stoploss = (current.Trade == Trade.BUY) ? (current.Close - this.StopLossRange) : (current.Close + this.StopLossRange); this.BookProfit1 = (current.Trade == Trade.BUY) ? (current.Close + this.StopLossRange) : (current.Close - this.StopLossRange); this.BookProfit2 = (current.Trade == Trade.BUY) ? (current.Close + (2.0 * this.StopLossRange)) : (current.Close - (2.0 * this.StopLossRange)); } else if (stoploss == 2) { Candle highLow = this.GetDayHighLow(current.CurrentCandle); this.StopLossRange = (highLow.High - highLow.Low); this.Stoploss = (current.Trade == Trade.BUY) ? (highLow.Low) : (highLow.High); this.BookProfit1 = (current.Trade == Trade.BUY) ? (current.Close + this.StopLossRange) : (current.Close - this.StopLossRange); this.BookProfit2 = (current.Trade == Trade.BUY) ? (current.Close + (2.0 * this.StopLossRange)) : (current.Close - (2.0 * this.StopLossRange)); } else if (stoploss != 5) { if (true) { this.StopLossRange = (current.CandleType == "G") ? (current.Close - GetMin(current.CurrentCandle.AllIndicators.SuperTrend.SuperTrendValue)) : (GetMax(current.CurrentCandle.AllIndicators.SuperTrend.SuperTrendValue) - current.Close); } else { this.StopLossRange = (current.CandleType == "G") ? (current.Close - GetMin(current.CurrentCandle.AllIndicators.SMA20, current.CurrentCandle.AllIndicators.SMA50, current.CurrentCandle.AllIndicators.SMA200, current.CurrentCandle.AllIndicators.SuperTrend.SuperTrendValue)) : (GetMax(current.CurrentCandle.AllIndicators.SMA20, current.CurrentCandle.AllIndicators.SMA50, current.CurrentCandle.AllIndicators.SMA200, current.CurrentCandle.AllIndicators.SuperTrend.SuperTrendValue) - current.Close); } this.Stoploss = (current.CandleType == "G") ? (current.Close - this.StopLossRange) : (current.Close + this.StopLossRange); this.BookProfit1 = (current.CandleType == "G") ? (current.Close + this.StopLossRange) : (current.Close - this.StopLossRange); this.BookProfit2 = (current.CandleType == "G") ? (current.Close + (2.0 * this.StopLossRange)) : (current.Close - (2.0 * this.StopLossRange)); } else { Candle highLow = this.GetHighLow(current.CurrentCandle); this.StopLossRange = (current.CandleType == "G") ? (current.Close - highLow.Low) : (highLow.High - current.Close); this.Stoploss = (current.CandleType == "G") ? (current.Close - this.StopLossRange) : (current.Close + this.StopLossRange); this.BookProfit1 = (current.CandleType == "G") ? (current.Close + this.StopLossRange) : (current.Close - this.StopLossRange); this.BookProfit2 = (current.CandleType == "G") ? (current.Close + (2.0 * this.StopLossRange)) : (current.Close - (2.0 * this.StopLossRange)); } int interval = stoplossidea.Interval; if (interval <= 10) { if (interval == 5) { this.FinalCandle = 73; } else if (interval == 10) { this.FinalCandle = 0x24; } } else if (interval == 15) { this.FinalCandle = 0x17; } else if (interval == 30) { this.FinalCandle = 11; } else if (interval == 60) { this.FinalCandle = 5; } }