private double GetH() { string home_currency = Account.Currency; string symbol = Symbol.Code; string base_currency = symbol.Substring(0, 3); string quote_currency = symbol.Substring(3, 3); double home_rate; //int margin_ratio; //double units; //double margin_required; if (home_currency == base_currency || home_currency == quote_currency) { home_rate = MarketData.GetSymbol(symbol).Bid; } else { home_rate = GetHomeRate(home_currency, base_currency); } //margin_ratio = Account.Leverage; //units = (double)Symbol.LotSize * lots; //margin_required = RoundUp(((home_rate) * units) / margin_ratio, 2); return(home_rate); }
protected override void Initialize() { symbol2 = MarketData.GetSymbol(Symbol2); symbol3 = MarketData.GetSymbol(Symbol3); symbol4 = MarketData.GetSymbol(Symbol4); symbol5 = MarketData.GetSymbol(Symbol5); symbol6 = MarketData.GetSymbol(Symbol6); symbol7 = MarketData.GetSymbol(Symbol7); symbol8 = MarketData.GetSymbol(Symbol8); symbol9 = MarketData.GetSymbol(Symbol9); symbol10 = MarketData.GetSymbol(Symbol10); series2 = MarketData.GetSeries(symbol2, TimeFrame); series3 = MarketData.GetSeries(symbol3, TimeFrame); series4 = MarketData.GetSeries(symbol4, TimeFrame); series5 = MarketData.GetSeries(symbol5, TimeFrame); series6 = MarketData.GetSeries(symbol6, TimeFrame); series7 = MarketData.GetSeries(symbol7, TimeFrame); series8 = MarketData.GetSeries(symbol8, TimeFrame); series9 = MarketData.GetSeries(symbol9, TimeFrame); series10 = MarketData.GetSeries(symbol10, TimeFrame); ma1 = Indicators.MovingAverage(MarketSeries.Close, Period, MaType); ma2 = Indicators.MovingAverage(series2.Close, Period, MaType); ma3 = Indicators.MovingAverage(series3.Close, Period, MaType); ma4 = Indicators.MovingAverage(series4.Close, Period, MaType); ma5 = Indicators.MovingAverage(series5.Close, Period, MaType); ma6 = Indicators.MovingAverage(series6.Close, Period, MaType); ma7 = Indicators.MovingAverage(series7.Close, Period, MaType); ma8 = Indicators.MovingAverage(series8.Close, Period, MaType); ma9 = Indicators.MovingAverage(series9.Close, Period, MaType); ma10 = Indicators.MovingAverage(series10.Close, Period, MaType); }
TriState _OpenPosition(double magicIndex, bool noOrders, string symbolCode, TradeType tradeType, double lots, double slippage, double?stopLoss, double?takeProfit, string comment) { Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode); if (noOrders && Positions.Find("FxProQuant_" + magicIndex.ToString("F0"), symbol) != null) { return(new TriState()); } if (stopLoss < 1) { stopLoss = null; } if (takeProfit < 1) { takeProfit = null; } if (symbol.Digits == 5 || symbol.Digits == 3) { if (stopLoss != null) { stopLoss /= 10; } if (takeProfit != null) { takeProfit /= 10; } slippage /= 10; } int volume = Convert.ToInt32(lots * 100000); if (!ExecuteMarketOrder(tradeType, symbol, volume, "FxProQuant_" + magicIndex.ToString("F0"), stopLoss, takeProfit, slippage, comment).IsSuccessful) { Thread.Sleep(400); return(false); } return(true); }
TriState _ClosePosition(double magicIndex, string symbolCode, double lots) { Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode); var pos = Positions.Find("FxProQuant_" + magicIndex.ToString("F0"), symbol); if (pos == null) { return(new TriState()); } TradeResult result; if (lots == 0) { result = ClosePosition(pos); } else { int volume = (int)(lots * 100000); result = ClosePosition(pos, volume); } if (!result.IsSuccessful) { Thread.Sleep(400); return(false); } return(true); }
TriState _ModifyPosition(double magicIndex, string symbolCode, int slAction, double slValue, int tpAction, double tpValue) { Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode); var pos = Positions.Find("FxProQuant_" + magicIndex.ToString("F0"), symbol); if (pos == null) { return(new TriState()); } double?sl, tp; if (slValue == 0) { sl = null; } else { switch (slAction) { case 0: sl = pos.StopLoss; break; case 1: if (pos.TradeType == TradeType.Buy) { sl = pos.EntryPrice - slValue * symbol.TickSize; } else { sl = pos.EntryPrice + slValue * symbol.TickSize; } break; case 2: sl = slValue; break; default: sl = pos.StopLoss; break; } } if (tpValue == 0) { tp = null; } else { switch (tpAction) { case 0: tp = pos.TakeProfit; break; case 1: if (pos.TradeType == TradeType.Buy) { tp = pos.EntryPrice + tpValue * symbol.TickSize; } else { tp = pos.EntryPrice - tpValue * symbol.TickSize; } break; case 2: tp = tpValue; break; default: tp = pos.TakeProfit; break; } } if (!ModifyPosition(pos, sl, tp).IsSuccessful) { Thread.Sleep(400); return(false); } return(true); }
protected override void Initialize() { _xbrsymbol = MarketData.GetSymbol("XBRUSD"); _xtisymbol = MarketData.GetSymbol("XTIUSD"); _xbrseries = MarketData.GetSeries(_xbrsymbol, TimeFrame); _xtiseries = MarketData.GetSeries(_xtisymbol, TimeFrame); _nocorel = Colors.Gray; }
protected override void OnBar() { MarketSeries data = MarketData.GetSeries(Symbol, TimeFrame.Minute15); DataSeries series = data.Close; int index = series.Count - 1; close = data.Close[index]; high = data.High[index]; low = data.Low[index]; open = data.Open[index]; // Int32 opentime = (Int32)(data.OpenTime[index].Subtract(new DateTime(1970, 1, 1))).TotalSeconds; var longPosition = Positions.Find(label, Symbol, TradeType.Buy); var shortPosition = Positions.Find(label, Symbol, TradeType.Sell); var currentSlowMa = slowMa.Result.Last(0); var currentFastMa = fastMa.Result.Last(0); var previousSlowMa = slowMa.Result.Last(1); var previousFastMa = fastMa.Result.Last(1); Symbol1 = MarketData.GetSymbol("EURUSD"); if (shortPosition == null && longPosition == null && previousFastMa < open && previousFastMa < close) { Print("BUY MA " + previousFastMa + " O " + open + " C " + close); Position position = Positions.Find(label, Symbol, TradeType.Sell); double vol = Quantity; if (position.NetProfit > 0) { vol = vol * 2; } long Volume = Symbol.QuantityToVolume(vol); ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label, 222, 50); //ExecuteMarketOrder(TradeType.Sell, Symbol1, VolumeInUnitsBuy, label, 111, 50); } if (longPosition == null && shortPosition == null && previousFastMa > open && previousFastMa > close) { Print("SELL MA " + previousFastMa + " O " + open + " C " + close); Position position = Positions.Find(label, Symbol, TradeType.Buy); double vol = Quantity; if (position.NetProfit > 0) { vol = vol * 2; } long Volume = Symbol.QuantityToVolume(vol); ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label, 222, 50); // ExecuteMarketOrder(TradeType.Buy, Symbol1, VolumeInUnitsBuy, label, 111, 50); } }
protected override void Initialize() { _ratio = 80; _xausymbol = MarketData.GetSymbol("XAUUSD"); _xagsymbol = MarketData.GetSymbol("XAGUSD"); _xauseries = MarketData.GetSeries(_xausymbol, TimeFrame); _xagseries = MarketData.GetSeries(_xagsymbol, TimeFrame); _nocorel = Colors.Gray; }
protected override void OnStart() { var eurJpySeries = MarketData.GetSeries("EURJPY", TimeFrame); var eurUsdSeries = MarketData.GetSeries("EURUSD", TimeFrame); eurJpyRSI = Indicators.RelativeStrengthIndex(eurJpySeries.Close, Periods); eurUsdRSI = Indicators.RelativeStrengthIndex(eurUsdSeries.Close, Periods); eurUsd = MarketData.GetSymbol("EURUSD"); }
// Main function to process positions private void DoWork() { if (--ticks > 0 && Math.Abs(last - MarketSeries.Close.LastValue) < symbol.PipSize / 2) { return; } RefreshData(); ticks = 10; last = MarketSeries.Close.LastValue; foreach (Position position in Positions) { if (!ManageThisPosition(position)) { continue; } symbol = MarketData.GetSymbol(position.SymbolCode); Bid = symbol.Bid; Ask = symbol.Ask; // Set initial stops if necessary if ((StopLoss_Initial > 0 && position.StopLoss == null) || (TakeProfit_Initial > 0 && position.TakeProfit == null)) { SetStops(position); } // BreakEven if (BreakEven_After > 0 && position.Pips >= BreakEven_After) { BreakEven(position, BreakEven_Profit); } // BreakEven2 if (BreakEven2_After > 0 && position.Pips >= BreakEven2_After) { BreakEven(position, BreakEven2_Profit); } // Partial Closure at Take Profit 1 if (TakeProfit_1 > 0) { TakeProfit1(position); } // Jumping StopLoss. SL jumps every X pips. Also keeps a distance of Y pips below market price before setting a new SL // Only triggers if we're in profit if (Jumping_Stop > 0 && position.Pips >= Jumping_Stop + Jumping_Distance && position.Pips >= 0) { JumpingStop(position); } } }
bool _OrderStatus(double magicIndex, string symbolCode, int test) { Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode); var pos = Positions.Find("FxProQuant_" + magicIndex.ToString("F0"), symbol); if (pos != null) { if (test == 0) { return(true); } if (test == 1) { return(true); } if (test == 3) { return(pos.TradeType == TradeType.Buy); } if (test == 4) { return(pos.TradeType == TradeType.Sell); } } var po = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol); if (po != null) { if (test == 0) { return(true); } if (test == 2) { return(true); } if (test == 3) { return(po.TradeType == TradeType.Buy); } if (test == 4) { return(po.TradeType == TradeType.Sell); } if (test == 5) { return(po.OrderType == PendingOrderType.Limit); } if (test == 6) { return(po.OrderType == PendingOrderType.Stop); } } return(false); }
protected override void Initialize() { // Fetch market series for second symbol this.SecondSymbol = MarketData.GetSymbol(SecondPair); this.SecondSeries = MarketData.GetSeries(this.SecondSymbol, this.TimeFrame); // Now create a stochastic for both this.FirstStoch = Indicators.StochasticOscillator(this.MarketSeries, this.kPeriods, this.kSlowing, this.dPeriods, MovingAverageType.Simple); this.SecondStoch = Indicators.StochasticOscillator(this.SecondSeries, this.kPeriods, this.kSlowing, this.dPeriods, MovingAverageType.Simple); }
protected override void Initialize() { ma = Indicators.MovingAverage(MarketSeries.Close, 200, MovingAverageType.Simple); if (Symbol2 != "") { symbol2 = MarketData.GetSymbol(Symbol2); series2 = MarketData.GetSeries(symbol2, TimeFrame); } multiplier = Symbol.Ask / symbol2.Ask; }
TriState _DeletePending(double magicIndex, string symbolCode) { Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode); var po = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol); if (po == null) { return(new TriState()); } if (!CancelPendingOrder(po).IsSuccessful) { Thread.Sleep(400); return(false); } return(true); }
public override void Calculate(int index) { int error_code = 0; Colors font_color; // are the color input strings valid? try { font_color = (Colors)Enum.Parse(typeof(Colors), text_color, true); } catch { error_code = 1; font_color = Colors.Red; } string home_currency = Account.Currency; string symbol = Symbol.Code; string base_currency = symbol.Substring(0, 3); string quote_currency = symbol.Substring(3, 3); double home_rate; int margin_ratio; double units; double margin_required; if (home_currency == base_currency || home_currency == quote_currency) { home_rate = MarketData.GetSymbol(symbol).Bid; } else { home_rate = GetHomeRate(home_currency, base_currency); } if (error_code == 0) { margin_ratio = Account.Leverage; units = (double)Symbol.LotSize * lots; margin_required = RoundUp(((home_rate) * units) / margin_ratio, 2); ChartObjects.DrawText("marginRequired", "Margin required for " + lots + " lots is " + margin_required, StaticPosition.TopCenter, font_color); } else { if (error_code == 1) { ChartObjects.DrawText("marginRequired", "Error Code 1: Specified Text Color is not a valid option", StaticPosition.TopCenter, font_color); } } }
//used with GetHomeRate() private Symbol TryGetSymbol(string symbolCode) { try { Symbol symbol = MarketData.GetSymbol(symbolCode); if (symbol.Bid == 0.0) { return(null); } return(symbol); } catch { return(null); } }
public OrderData(string[] raw_pieces, MarketData market_data) { try { this.label = raw_pieces[0].Trim(); this.symbol = market_data.GetSymbol(raw_pieces[1].Trim()); this.setType(Convert.ToInt32(raw_pieces[2].Trim())); this.lot = Convert.ToInt64(this.parseDouble(raw_pieces[3]) * mt_lot_coefficient); double price = this.parseDouble(raw_pieces[4]); this.sl = this.getPipDistance(price, this.parseDouble(raw_pieces[5])); this.tp = this.getPipDistance(price, this.parseDouble(raw_pieces[6])); } catch (Exception e) { this.initialized_properly = false; } }
private void OnClose_Click() { var list_p = _threadhandler.positionParam(); var p_symbol = MarketData.GetSymbol(list_p[0]); var p_label = list_p[1]; var p_volume = p_symbol.NormalizeVolumeInUnits(Convert.ToDouble(list_p[2]), RoundingMode.ToNearest); var p_comment = list_p[3]; //if (string.IsNullOrEmpty(p_label)) //{ // this.closeAllPositions(); //} if (!string.IsNullOrEmpty(p_label)) { this.closeAllLabel(p_label); } }
protected override void OnStart() { if (PositionId == DefaultPositionIdParameterValue) { PrintErrorAndStop("You have to specify \"Position Id\" in cBot Parameters"); } if (TriggerPips < AddPips + 2) { PrintErrorAndStop("\"Trigger Pips\" must be greater or equal to \"Add Pips\" + 2"); } var position = FindPositionOrStop(); _symbol = MarketData.GetSymbol(position.SymbolCode); BreakEvenIfNeeded(); }
//used with GetMMvol() private double GetH() { string home_currency = Account.Currency; string symbol = Symbol.Code; string base_currency = symbol.Substring(0, 3); string quote_currency = symbol.Substring(3, 3); double home_rate; if (home_currency == base_currency || home_currency == quote_currency) { home_rate = MarketData.GetSymbol(symbol).Bid; } else { home_rate = GetHomeRate(home_currency, base_currency); } return(home_rate); }
/// <summary>Return the symbol for a given symbol code or null if invalid or unavailable</summary> public Symbol GetSymbol(string symbol_code) { // Quick out if the requested symbol is the one this bot is running on if (symbol_code == Symbol.Code) { return(Symbol); } // Otherwise, request the other symbol data return(m_sym_cache.Get(symbol_code, c => { Symbol res = null; using (var wait = new ManualResetEvent(false)) { BeginInvokeOnMainThread(() => { res = MarketData.GetSymbol(symbol_code); wait.Set(); }); wait.WaitOne(TimeSpan.FromSeconds(30)); return res; } })); }
//Select statement public List <string>[] SelectOpenPositions() { Int32 TimeStamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; string query = "SELECT * FROM opensignal where time >= NOW() - INTERVAL " + LastHours + " HOUR ORDER BY id DESC LIMIT " + MaxPositions; //Create a list to store the result List <string>[] list = new List <string> [9]; string[][] arr = new string[MaxPositions][]; for (int x = 0; x < arr.Length; x++) { arr[x] = new string[8]; } MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); int nr = 0; while (dataReader.Read()) { // Console.WriteLine("\t{0}\t{1}", reader.GetInt32(0), reader.GetString(1)); /// SET POSITION HERE DONT INSERT IN ARRAY /// create file with position or check is exist position with label in history or open positions arr[nr][0] = "" + dataReader["id"]; arr[nr][1] = "" + dataReader["symbol"]; arr[nr][2] = "" + dataReader["volume"]; arr[nr][3] = "" + dataReader["type"]; arr[nr][4] = "" + dataReader["opent"]; arr[nr][5] = "" + dataReader["openp"]; arr[nr][6] = "" + dataReader["sl"]; arr[nr][7] = "" + dataReader["tp"]; //Print("Exist in history " + (string)dataReader["id"] + "CopexFxStar" + " " + existInHistory((string)dataReader["id"] + "CopexFxStar")); if (!FileExists("" + dataReader["id"])) { if (!CreateFile("" + dataReader["id"])) { Symbol sym = MarketData.GetSymbol("" + dataReader["symbol"]); //ExecuteMarketOrder(TradeType.Buy, sym, (Int32)dataReader["volume"], (string)dataReader["id"]); if (arr[nr][3] == "BUY") { double vol = Int32.Parse(arr[nr][2].ToString()) * Multiply; if ((Int32)vol < sym.VolumeMin || (Int32)vol > sym.VolumeMax) { Print("ERROR Position volume " + (string)dataReader["id"] + "CopexFxStar" + " " + sym); } var result = ExecuteMarketOrder(TradeType.Buy, sym, (Int32)vol, (string)dataReader["id"] + "CopexFxStar"); if (result.IsSuccessful) { Print("=========> BUY Marker Order Open " + dataReader["id"] + " " + dataReader["symbol"] + " " + vol + " " + dataReader["type"]); // Add StopLossPips for position if (StopLossPips > 10) { var position = result.Position; Print("Position SL price is {0}", position.StopLoss); var stopLoss = position.EntryPrice - StopLossPips * Symbol.PipSize; ModifyPosition(position, stopLoss, position.TakeProfit); Print("New Position {1} SL price is {0}", position.StopLoss, position.Id); } // Add TakeProfitPips for position if (TakeProfitPips > 10) { var position = result.Position; Print("Position TP price is {0}", position.TakeProfit); var takeProfit = position.EntryPrice + TakeProfitPips * Symbol.PipSize; ModifyPosition(position, position.StopLoss, takeProfit); Print("New Position {1} TP price is {0}", position.TakeProfit, position.Id); } } // if open position error delete position file if (!result.IsSuccessful) { DeleteFile("" + dataReader["id"]); } } if (arr[nr][3] == "SELL") { double vol = Int32.Parse(arr[nr][2].ToString()) * Multiply; if ((Int32)vol < sym.VolumeMin || (Int32)vol > sym.VolumeMax) { Print("ERROR Position volume " + (string)dataReader["id"] + "CopexFxStar" + " " + sym); } var result = ExecuteMarketOrder(TradeType.Sell, sym, (Int32)vol, (string)dataReader["id"] + "CopexFxStar"); if (result.IsSuccessful) { Print("=========> SELL Marker Order Open " + dataReader["id"] + " " + dataReader["symbol"] + " " + vol + " " + dataReader["type"]); // Add StopLossPips for position if (StopLossPips > 10) { var position = result.Position; Print("Position SL price is {0}", position.StopLoss); var stopLoss = position.EntryPrice + StopLossPips * Symbol.PipSize; ModifyPosition(position, stopLoss, position.TakeProfit); Print("New Position {1} SL price is {0}", position.StopLoss, position.Id); } // Add TakeProfitPips for position if (TakeProfitPips > 10) { var position = result.Position; Print("Position TP price is {0}", position.TakeProfit); var takeProfit = position.EntryPrice - TakeProfitPips * Symbol.PipSize; ModifyPosition(position, position.StopLoss, takeProfit); Print("New Position {1} TP price is {0}", position.TakeProfit, position.Id); } } // if open position error delete position file if (!result.IsSuccessful) { DeleteFile("" + dataReader["id"]); } } } } nr++; } dataReader.Close(); return(list); }
TriState _ModifyPending(double magicIndex, string symbolCode, int slAction, double slValue, int tpAction, double tpValue, int priceAction, double priceValue, int expirationAction, DateTime?expiration) { Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode); var po = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol); if (po == null) { return(new TriState()); } double targetPrice; double?sl, tp; if (slValue == 0) { sl = null; } else { switch (slAction) { case 0: sl = po.StopLoss; break; case 1: if (po.TradeType == TradeType.Buy) { sl = po.TargetPrice - slValue * symbol.TickSize; } else { sl = po.TargetPrice + slValue * symbol.TickSize; } break; case 2: sl = slValue; break; default: sl = po.StopLoss; break; } } if (tpValue == 0) { tp = null; } else { switch (tpAction) { case 0: tp = po.TakeProfit; break; case 1: if (po.TradeType == TradeType.Buy) { tp = po.TargetPrice + tpValue * symbol.TickSize; } else { tp = po.TargetPrice - tpValue * symbol.TickSize; } break; case 2: tp = tpValue; break; default: tp = po.TakeProfit; break; } } switch (priceAction) { case 0: targetPrice = po.TargetPrice; break; case 1: targetPrice = priceValue; break; case 2: targetPrice = po.TargetPrice + priceValue * symbol.TickSize; break; case 3: targetPrice = po.TargetPrice - priceValue * symbol.TickSize; break; case 4: targetPrice = symbol.Bid - priceValue * symbol.TickSize; break; case 5: targetPrice = symbol.Bid + priceValue * symbol.TickSize; break; case 6: targetPrice = symbol.Ask - priceValue * symbol.TickSize; break; case 7: targetPrice = symbol.Ask + priceValue * symbol.TickSize; break; default: targetPrice = po.TargetPrice; break; } if (expiration.HasValue && (expiration.Value.Ticks == 0 || expiration.Value == DateTime.Parse("1970.01.01 00:00:00"))) { expiration = null; } if (expirationAction == 0) { expiration = po.ExpirationTime; } if (!ModifyPendingOrder(po, targetPrice, sl, tp, expiration).IsSuccessful) { Thread.Sleep(400); return(false); } return(true); }
TriState _SendPending(double magicIndex, bool noOrders, string symbolCode, PendingOrderType poType, TradeType tradeType, double lots, int priceAction, double priceValue, double?stopLoss, double?takeProfit, DateTime?expiration, string comment) { Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode); if (noOrders && PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol) != null) { return(new TriState()); } if (stopLoss < 1) { stopLoss = null; } if (takeProfit < 1) { takeProfit = null; } if (symbol.Digits == 5 || symbol.Digits == 3) { if (stopLoss != null) { stopLoss /= 10; } if (takeProfit != null) { takeProfit /= 10; } } int volume = (int)(lots * 100000); double targetPrice; switch (priceAction) { case 0: targetPrice = priceValue; break; case 1: targetPrice = symbol.Bid - priceValue * symbol.TickSize; break; case 2: targetPrice = symbol.Bid + priceValue * symbol.TickSize; break; case 3: targetPrice = symbol.Ask - priceValue * symbol.TickSize; break; case 4: targetPrice = symbol.Ask + priceValue * symbol.TickSize; break; default: targetPrice = priceValue; break; } if (expiration.HasValue && (expiration.Value.Ticks == 0 || expiration.Value == DateTime.Parse("1970.01.01 00:00:00"))) { expiration = null; } if (poType == PendingOrderType.Limit) { if (!PlaceLimitOrder(tradeType, symbol, volume, targetPrice, "FxProQuant_" + magicIndex.ToString("F0"), stopLoss, takeProfit, expiration, comment).IsSuccessful) { Thread.Sleep(400); return(false); } return(true); } else if (poType == PendingOrderType.Stop) { if (!PlaceStopOrder(tradeType, symbol, volume, targetPrice, "FxProQuant_" + magicIndex.ToString("F0"), stopLoss, takeProfit, expiration, comment).IsSuccessful) { Thread.Sleep(400); return(false); } return(true); } return(new TriState()); }
private void InitializeSeries(string symbolCode) { _symbol2 = MarketData.GetSymbol(symbolCode); _series2 = MarketData.GetSeries(_symbol2, TimeFrame); }
private Symbol GetSymbol(Position position) { return(MarketData.GetSymbol(position.SymbolCode)); }
protected override void Initialize() { symbol1 = MarketData.GetSymbol(Symbol1); symbol2 = MarketData.GetSymbol(Symbol2); symbol3 = MarketData.GetSymbol(Symbol3); }
protected override void OnStart() { _filePath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\cAlgo\\cbotset\\"; _fileName = _filePath + "cbotset.json"; Print("fiName=" + _fileName); SetParams(); _istrade = !_stopTrade; Print("IsTrade: " + _istrade.ToString() + "-" + _istrade.GetType().ToString()); if (_magnify != 1) { Print("Please choose the MACS_Magnify."); this.Stop(); } Positions.Opened += OnPositionsOpened; Positions.Closed += OnPositionsClosed; _mac = Indicators.GetIndicator <Metals_MAC>(_resultperiods, _averageperiods, _sub); _mas = Indicators.GetIndicator <Metals_MAS>(_resultperiods, _averageperiods, _sub, _break); _ratio = 80; _xausymbol = MarketData.GetSymbol("XAUUSD"); _xagsymbol = MarketData.GetSymbol("XAGUSD"); if (_openCross) { _abovecross = true; _belowcross = true; Print("abovecross: " + _abovecross.ToString()); Print("belowcross: " + _belowcross.ToString()); } else { _abovecross = false; _belowcross = false; Print("abovecross: " + _abovecross.ToString()); Print("belowcross: " + _belowcross.ToString()); } _risk = false; Print("risk: " + _risk.ToString()); _abovelabel = "Above" + "-" + "XAUXAG" + "-" + MarketSeries.TimeFrame.ToString(); _belowlabel = "Below" + "-" + "XAUXAG" + "-" + MarketSeries.TimeFrame.ToString(); _init = new OrderParams(null, null, null, null, null, null, null, null, null, new System.Collections.Generic.List <double> { }); #region Get Mark Position[] pos_above = this.GetPositions(_abovelabel); Position[] pos_below = this.GetPositions(_belowlabel); var poss = pos_above.Length == 0 ? pos_below : pos_above; if (poss.Length != 0) { foreach (var p in poss) { var idx = p.Comment.IndexOf("M_") + 2; if (!_marklist.Contains(p.Comment.Substring(idx, 13))) { _marklist.Add(p.Comment.Substring(idx, 13)); } } } if (_marklist.Count != 0) { foreach (var mar in _marklist) { Print(mar); } } #endregion Print("Done OnStart()"); }
void Calc_Exposure() { string _used = ""; string n = "\n"; int _max_pairs = 0; int i = 0; double[] _exposure = new double[MAX_PAIRS]; for (i = 0; i < MAX_PAIRS; i++) { _exposure[i] = 0; } for (i = (Positions.Count - 1); i >= 0; i--) { Symbol symbol = MarketData.GetSymbol(Positions[i].SymbolCode); string _pair = Positions[i].SymbolCode.Substring(0, 3); int _pi = _used.IndexOf(_pair, 0, _used.Length); if (_pi >= 0) { _pi /= 3; } else { _pi = _used.Length / 3; _used = string.Concat(_used, _pair); _max_pairs++; } if (Positions[i].TradeType == TradeType.Buy) { _exposure[_pi] += Positions[i].Volume * symbol.TickSize; } else { _exposure[_pi] -= Positions[i].Volume * symbol.TickSize; } _pair = Positions[i].SymbolCode.Substring(3, 3); _pi = _used.IndexOf(_pair, 0, _used.Length); if (_pi >= 0) { _pi /= 3; } else { _pi = _used.Length / 3; _used = string.Concat(_used, _pair); _max_pairs++; } if (Positions[i].TradeType == TradeType.Sell) { _exposure[_pi] += Positions[i].Volume * symbol.TickSize * symbol.Bid; } else { _exposure[_pi] -= Positions[i].Volume * symbol.TickSize * symbol.Ask; } } ChartObjects.DrawText("Mijo_Exposure", n + "-=Exposure=-", StaticPosition.TopLeft, Colors.Yellow); for (i = 0; i < _max_pairs; i++) { n = n + "\n"; _exposure[i] = _exposure[i] * 1000; if (_used.Substring(i * 3, 3) == "JPY") { _exposure[i] = _exposure[i] * 0.01; } if (_exposure[i] > 0) { ChartObjects.DrawText("Mijo_Exposure_" + _used.Substring(i * 3, 3), n + " " + _used.Substring(i * 3, 3) + ": " + _exposure[i].ToString("0"), StaticPosition.TopLeft, Colors.Lime); } else { if (_exposure[i] < 0) { ChartObjects.DrawText("Mijo_Exposure_" + _used.Substring(i * 3, 3), n + " " + _used.Substring(i * 3, 3) + ": " + _exposure[i].ToString("0"), StaticPosition.TopLeft, Colors.BlueViolet); } else { ChartObjects.DrawText("Mijo_Exposure_" + _used.Substring(i * 3, 3), n + " " + _used.Substring(i * 3, 3) + ": " + _exposure[i].ToString("0"), StaticPosition.TopLeft, Colors.Yellow); } } } }
//Select statement public List <string>[] Select() { string query = "SELECT * FROM opensignal"; //Create a list to store the result List <string>[] list = new List <string> [9]; string[][] arr = new string[20][]; for (int x = 0; x < arr.Length; x++) { arr[x] = new string[8]; } list[0] = new List <string>(); list[1] = new List <string>(); list[2] = new List <string>(); list[3] = new List <string>(); list[4] = new List <string>(); list[5] = new List <string>(); list[6] = new List <string>(); list[7] = new List <string>(); list[8] = new List <string>(); MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); int nr = 0; while (dataReader.Read()) { // Console.WriteLine("\t{0}\t{1}", reader.GetInt32(0), reader.GetString(1)); /// SET POSITION HERE DONT INSERT IN ARRAY /// create file with position or check is exist position with label in history or open positions arr[nr][0] = "" + dataReader["id"]; arr[nr][1] = "" + dataReader["symbol"]; arr[nr][2] = "" + dataReader["volume"]; arr[nr][3] = "" + dataReader["type"]; arr[nr][4] = "" + dataReader["opent"]; arr[nr][5] = "" + dataReader["openp"]; arr[nr][6] = "" + dataReader["sl"]; arr[nr][7] = "" + dataReader["tp"]; if (!CreateFile("" + dataReader["id"])) { Symbol sym = MarketData.GetSymbol("" + dataReader["symbol"]); //ExecuteMarketOrder(TradeType.Buy, sym, (Int32)dataReader["volume"], (string)dataReader["id"]); Print("Utwórz pozycję" + dataReader["id"]); } //Print(arr[nr][1]); nr++; //Print(dataReader["id"]); list[0].Add(dataReader["id"] + ""); list[1].Add(dataReader["symbol"] + ""); list[2].Add(dataReader["volume"] + ""); list[3].Add(dataReader["type"] + ""); list[4].Add(dataReader["opent"] + ""); list[5].Add(dataReader["sl"] + ""); list[6].Add(dataReader["tp"] + ""); list[7].Add(dataReader["time"] + ""); list[8].Add(dataReader["account"] + ""); } dataReader.Close(); foreach (string[] dd in arr) { if (dd[0] != null) { Print("POS " + dd[0]); } } // Loop over list elements using foreach-loop. foreach (List <string> element in list) { //Print("ELEMENT " + element); string line = string.Join(",", element.ToArray()); //Print("POZYCJA ============================= " + line); //Print(element.ElementAt(0)); foreach (string pos in element) { //Print(pos); } } return(list); }