I'm developing a strategy with Long/ShortStop Orders and I'm trying to move (trailing) the orders following the prize.
I have a problem to get the distance (in ticks) between the price (Ask/Bid) and the pending orders. The formula (difference) do not work fine!
================================================== ========
This is the code about the place and modifying orders, in "OnBarUpdate()" and CalculateOnBarClose = true;
Show you img for alternative view;
#region PENDING ORDER Type 3 // PENDING ORDERS (type 3) if (entrytype == 3) { if (Position.MarketPosition == MarketPosition.Flat) { if (entryOrderBuy == null && TradeEntry == 1) { entryOrderBuy = EnterLongStop(0, true, 1, GetCurrentAsk() + OffSetOrder * TickSize, "buy order"); } if (entryOrderSell == null && TradeEntry == -1) { entryOrderSell = EnterShortStop(0, true, 1, GetCurrentBid() - OffSetOrder * TickSize, "sell order"); } } // MODIFIED ORDER if (entryOrderBuy != null && (entryOrderBuy.StopPrice - GetCurrentAsk()) > OffSetOrder * TickSize) { entryOrderBuy = EnterLongStop(0, true, 1, GetCurrentAsk() + OffSetOrder * TickSize, "buy order"); //Print (entryOrderBuy.StopPrice - GetCurrentAsk() ); //Print (GetCurrentAsk()); } if (entryOrderSell != null && (GetCurrentBid() - entryOrderSell.StopPrice) > OffSetOrder * TickSize) { entryOrderSell = EnterShortStop(0, true, 1, GetCurrentBid() - OffSetOrder * TickSize, "sell order"); //Print (entryOrderBuy.StopPrice - GetCurrentAsk() ); //Print (GetCurrentAsk()); } } #endregion
This is the code to Print:
protected override void OnOrderUpdate(IOrder order) { if (entryOrderBuy != null && entryOrderBuy == order) { if (order.OrderState != OrderState.Filled) Print ("Moving pending buy order: STOP PRICE = " + entryOrderBuy.StopPrice + " | ASK PRICE = " + GetCurrentAsk()+ " | DIFF. PRICE = " +(entryOrderBuy.StopPrice - GetCurrentAsk()) ); } if (entryOrderSell != null && entryOrderSell == order) { if (order.OrderState != OrderState.Filled) Print ("Moving pending sell order: STOP PRICE = " + entryOrderSell.StopPrice + " | BID PRICE = " + GetCurrentBid()+ " | DIFF. PRICE = " +(GetCurrentBid() - entryOrderSell.StopPrice) ); }
Moving pending sell order: STOP PRICE = 0,7284 | BID PRICE = 0,7285 | DIFF. PRICE = 9,9999999999989E-05 Moving pending sell order: STOP PRICE = 0,7284 | BID PRICE = 0,7285 | DIFF. PRICE = 9,9999999999989E-05 Moving pending sell order: STOP PRICE = 0,7285 | BID PRICE = 0,7286 | DIFF. PRICE = 9,9999999999989E-05 Moving pending sell order: STOP PRICE = 0,7285 | BID PRICE = 0,7286 | DIFF. PRICE = 9,9999999999989E-05 Moving pending sell order: STOP PRICE = 0,7285 | BID PRICE = 0,7286 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0 | ASK PRICE = 0,7284 | DIFF. PRICE = -0,7284 Moving pending buy order: STOP PRICE = 0 | ASK PRICE = 0,7284 | DIFF. PRICE = -0,7284 Moving pending buy order: STOP PRICE = 0 | ASK PRICE = 0,7284 | DIFF. PRICE = -0,7284 Moving pending buy order: STOP PRICE = 0,7282 | ASK PRICE = 0,7281 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7282 | ASK PRICE = 0,7281 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7282 | ASK PRICE = 0,7281 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7281 | ASK PRICE = 0,728 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7281 | ASK PRICE = 0,728 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7281 | ASK PRICE = 0,728 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7277 | ASK PRICE = 0,7276 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7277 | ASK PRICE = 0,7276 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7277 | ASK PRICE = 0,7276 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7276 | ASK PRICE = 0,7275 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7276 | ASK PRICE = 0,7275 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7276 | ASK PRICE = 0,7275 | DIFF. PRICE = 9,9999999999989E-05 Moving pending sell order: STOP PRICE = 0,7283 | BID PRICE = 0,7284 | DIFF. PRICE = 9,9999999999989E-05 Moving pending sell order: STOP PRICE = 0,7283 | BID PRICE = 0,7284 | DIFF. PRICE = 9,9999999999989E-05 Moving pending sell order: STOP PRICE = 0,7283 | BID PRICE = 0,7284 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0 | ASK PRICE = 0,7282 | DIFF. PRICE = -0,7282 Moving pending buy order: STOP PRICE = 0 | ASK PRICE = 0,7282 | DIFF. PRICE = -0,7282 Moving pending buy order: STOP PRICE = 0 | ASK PRICE = 0,7282 | DIFF. PRICE = -0,7282 Moving pending buy order: STOP PRICE = 0,7281 | ASK PRICE = 0,728 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7281 | ASK PRICE = 0,728 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,7281 | ASK PRICE = 0,728 | DIFF. PRICE = 9,9999999999989E-05 Moving pending buy order: STOP PRICE = 0,728 | ASK PRICE = 0,7279 | DIFF. PRICE = 9,9999999999989E-05
Questions:
1. Why with differencial of 1 point I get difference ans so bad values?
Ex1: Moving pending sell order: STOP PRICE = 0,7283 | BID PRICE = 0,7284 | DIFF. PRICE = 9,9999999999989E-05
Ex2: Moving pending sell order: STOP PRICE = 0,7283 | BID PRICE = 0,7284 | DIFF. PRICE = 0,0001000000000001
... and sometimes why the StopPrice=0 ?..I have set more condition to Print only with StopOrder Active!
2. How can I get perfect values (on candle close: false or true):
Difference between order and price: 1,2,3,4,5 ...point
3. How can you see I have used "order.OrderState != OrderState.Filled" to work with pending order "active" (no filled). I have try OrderState.PartFilled but is never active, do not work. Could you tell me something about? When there is a stop/limit order active, the OrderState.PartFilled is True??
Many thanks for your support
Comment