/// <summary> /// Generate a stop order for a position, at a specified per-share/contract price /// </summary> /// <param name="p">your position</param> /// <param name="offset">how far away stop is</param> /// <param name="percent">what percent of position to close</param> /// <param name="normalizesize">whether to normalize size to even-lots</param> /// <param name="MINSIZE">size of an even lot</param> /// <returns></returns> public static Order PositionStop(Position p, decimal offset, decimal percent, bool normalizesize, int MINSIZE) { Order o = new Order(); if (!p.isValid || p.isFlat) { return(o); } decimal price = Calc.OffsetPrice(p, offset * -1); int size = percent == 0 ? 0 : (!normalizesize ? (int)(p.FlatSize * percent) : Calc.Norm2Min(p.FlatSize * percent, MINSIZE)); o = new StopOrder(p.FullSymbol, p.isLong ? -size : size, price); return(o); }