protected override void OnBarUpdate() { if (BarsPeriod.BarsPeriodType != BarsPeriodType.Day && BarsInProgress == 0 && warningText == null) { warningText = Draw.TextFixed(this, "warning", "SRM works best on daily equities or equity indices", TextPosition.TopLeft); return; } if (CurrentBars[0] < LBP || CurrentBars[1] < LBP || CurrentBars[2] < LBP || CurrentBars[3] < LBP || CurrentBars[4] < LBP || CurrentBars[5] < LBP) { return; } double bull01 = (Closes[1][0] - Closes[1][LBP]) / Closes[1][LBP]; double bull02 = (Closes[2][0] - Closes[2][LBP]) / Closes[2][LBP]; double bear01 = (Closes[3][0] - Closes[3][LBP]) / Closes[3][LBP]; double bear02 = (Closes[4][0] - Closes[4][LBP]) / Closes[4][LBP]; double bear03 = (Closes[5][0] - Closes[5][LBP]) / Closes[5][LBP]; double bear = (bear01 + bear02 + bear03) / 3; double bull = (bull01 + bull02) / 2; Oscillator[0] = bull - bear; }
protected override void OnBarUpdate() { var message = "\t" + Line1 + "\n\t" + Line2 + "\n\t" + Line3 + "\n\t" + Line4; // Instantiate a TextFixed object TextFixed myTF = Draw.TextFixed(this, "tag1", message, TextPosition.TopLeft); // Draw.TextFixed(this, // Change the object's TextPosition //myTF.AreaBrush = }
protected void setTextBox(string textInBox) { /// show market condition TextFixed myTF = Draw.TextFixed(this, "tradeStat", textInBox, TextPosition.BottomLeft); myTF.TextPosition = TextPosition.BottomLeft; myTF.AreaBrush = Brushes.Black; myTF.AreaOpacity = 80; myTF.TextBrush = Brushes.Black; }
protected void setTextBox(string textInBox) { /// show market condition TextFixed myTF = Draw.TextFixed(this, "MC", textInBox, TextPosition.TopRight); myTF.TextPosition = TextPosition.TopLeft; myTF.AreaBrush = Brushes.DimGray; myTF.AreaOpacity = 50; myTF.TextBrush = Brushes.White; }
protected override void OnBarUpdate() { if (Count - 2 == CurrentBar) //Calculate cycle on last finished, closed bar { string APIresultContent = ""; //Get and prepare the close data array int seriesCount = Close.Count - 1; List <double> closeList = new List <double>(); for (int i = 0; i <= seriesCount; i++) { closeList.Add(Close.GetValueAt(i)); } //Call the WhenToTrade Cycles API endpoint POST CycleExplorer using (var client = new HttpClient()) { //WhenToTrade API URL client.BaseAddress = new Uri("https://api.marketcycles.online/"); //Load the close dataset for HTTP API POST call var contents = JsonConvert.SerializeObject(closeList.ToArray()); StringContent POSTcontent = new StringContent(contents, Encoding.UTF8, "application/json"); //POST API CALL var response = client.PostAsync("/api/CycleExplorer?minCycleLength=" + minCycleLength + "&maxCycleLength=" + maxCycleLength + "&plotForward=" + plotForward + "&includeTimeseries=true&api_Key=" + apiKey, POSTcontent).Result; //Check for network errors if (response.IsSuccessStatusCode) { APIresultContent = response.Content.ReadAsStringAsync().Result; } else { string msg = response.Content.ReadAsStringAsync().Result; Draw.TextFixed(this, "apierror", "API ERROR:" + msg, TextPosition.TopLeft); return; } } // Decode the cycle data from API call var dominantCycle = JsonConvert.DeserializeObject <dynamic>(APIresultContent); // Test for return errors from API? string statusCode = dominantCycle.StatusCode != null ? dominantCycle.StatusCode : ""; bool error = statusCode.IndexOf("error", StringComparison.OrdinalIgnoreCase) >= 0; if (error) { Draw.TextFixed(this, "apierror", "API ERROR:" + statusCode, TextPosition.TopLeft); return; } //get key cycle information from return object var cyclelength = dominantCycle.length; var currentPrice = dominantCycle.currentPrice; var timeSeries = dominantCycle.TimeSeries; // DEBUG: Print return values to log Print(dominantCycle); // Fill cycle indicator values from timeSeries API return array (info: called just once for the full chart) for (int i = 0; i <= CurrentBar; i++) { try { Value[CurrentBar - i] = timeSeries[i + plotForward].dominantCycle; if (timeSeries[i + plotForward].cycleHighlighter != null) { Values[1][CurrentBar - i] = timeSeries[i + plotForward].cycleHighlighter; } } catch (Exception ex) { //should never happen, but in case lets ignore them and only print to log Print("Error: " + i + " - " + ex.Message); } } // Plot Dominant Cycle Information TextFixed myTF = Draw.TextFixed(this, "dctext", "Cycle Length: " + cyclelength.ToString("0") + Environment.NewLine + "Next Low: " + dominantCycle.nextlow.ToString("0.00") + Environment.NewLine + "Next Top: " + dominantCycle.nexttop.ToString("0.00") + Environment.NewLine + "Status: " + dominantCycle.phase_status, TextPosition.TopLeft); // Plot the dot at current bar cycle position double doty = timeSeries[CurrentBar].dominantCycle; NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Wingdings", 12) { Size = 12 }; Draw.Text(this, "dot", true, "l", 0, doty, 0, Brushes.Green, myFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0); } }