void SetOffset(string sym, OffsetInfo off) { // check for index int idx = addindex(sym, off); if (_verbdebug) { debug(sym + " set offset: " + off.ToString(DebugDecimals)); } }
void SetOffset(string sym, OffsetInfo off) { // check for index if (_trackedOffsetInfos.ContainsKey(sym)) { _trackedOffsetInfos[sym] = off; } else { _trackedOffsetInfos.Add(sym, off); } if (_verbdebug) { debug(sym + " set offset: " + off.ToString(DebugDecimals)); } }
void SetOffset(string sym, OffsetInfo off) { // check for index int idx = addindex(sym, off); if (_verbdebug) debug(sym + " set offset: " + off.ToString(DebugDecimals)); }
void SetOffset(string sym, OffsetInfo off) { // check for index if (_trackedOffsetInfos.ContainsKey(sym)) _trackedOffsetInfos[sym] = off; else _trackedOffsetInfos.Add(sym, off); if (_verbdebug) debug(sym + " set offset: " + off.ToString(DebugDecimals)); }
/// <summary> /// pass arbitrary price to use for trail reference price /// </summary> /// <param name="symbol"></param> /// <param name="p"></param> public void newPoint(string symbol, decimal p) { // get index for symbol int idx = symidx(symbol); // setup parameters OffsetInfo trail = null; decimal refp = 0; // see if we trail this symbol if ((idx == NOSYM) && _trailbydefault) { // get parameters idx = _trail.Count; refp = p; trail = new OffsetInfo(_defaulttrail); // save them _symidx.Add(symbol, idx); _ref.Add(refp); _pendingfill.Add(false); firecount.Add(symbol, 0); esize.Add(symbol, pt[symbol].UnsignedSize); // just in case user is modifying on seperate thread lock (_trail) { _trail.Add(trail); } D(symbol + " trail tracking modified: " + trail.ToString()); } else if ((idx == NOSYM) && !_trailbydefault) { return; } else { // get parameters refp = _ref[idx]; // in case tracker started after trail stop should have been broken. if (refp == 0 && _pt[symbol].isValid) { refp = _pt[symbol].AvgPrice; } // just in case user tries to modify on seperate thread lock (_trail) { trail = _trail[idx]; } } // see if we need to update ref price if ((refp == 0) || (_pt[symbol].isLong && (refp < p)) || (_pt[symbol].isShort && (refp > p))) { // update refp = p; // save it _ref[idx] = refp; // notify v(symbol + " new reference price: " + p); } // see if we broke our trail var testdist = Math.Abs(refp - p); var trailtest = testdist > trail.StopDist; if (!_pendingfill[idx] && (trail.StopDist != 0) && trailtest && (MaxFireCount > firecount[symbol])) { // notify D(symbol + " hit trailing stop at: " + p.ToString("F2")); // mark pending order _pendingfill[idx] = true; // get order Order flat = new MarketOrderFlat(_pt[symbol], trail.StopPercent, trail.NormalizeSize, trail.MinimumLotSize); // get order id flat.id = _id.AssignId; // adjust expectation esize[symbol] -= flat.UnsignedSize; // count fire firecount[symbol]++; // send flat order SendOrder(flat); // notify D(symbol + " enforcing trail with: " + flat.ToString() + " esize: " + esize[symbol] + " count: " + firecount[symbol]); if (HitOffset != null) HitOffset(symbol, flat.id, p); } else if (!_noverb) { if (_pendingfill[idx]) v(symbol + " waiting for trail fill."); else if (trail.StopDist == 0) v(symbol + " trail has been disabled."); else if (!trailtest) { v(symbol + " trail not hit, current dist: " + testdist + " trailamt: " + trail.StopDist); } else if (MaxFireCount > firecount[symbol]) { v(symbol + " trail max fire reached at: " + firecount[symbol] + " max: " + MaxFireCount); } } }