Support Board
Date/Time: Tue, 21 Jan 2025 07:31:52 +0000
Post From: Report Possible Bug: sc.SellEntry() Incorrectly Displays Order Fills
[2018-08-02 13:15:47] |
Richard Chinn - Posts: 28 |
I think I am understanding the documented action of the variable correctly. It does work properly, preventing another of the same type trade on the same bar. I think maybe this is a clue from the documentation: sc.AllowOnlyOneTradePerBar Documentation ... For example, once sc.BuyEntry is called and is successful with an order submission (whether the order fills or not), additional calls to sc.BuyEntry will be ignored on the same chart bar and will return SCT_SKIPPED_ONLY_ONE_TRADE_PER_BAR. My program code checks if the bar closed, sets variables, then determines if a trade is possible. If no trade is possible a return is made and the code to initiate a new order should never be evaluated. This is what I am seeing happen: - A successful sc.BuyEntry is made, the price 1@____ is displayed on the bar and the position is displayed (I have Checked: Trade>>Show Orders and Positions) - Almost immediately a -1@____ is displayed but the first position is NOT closed and is still actively displaying (I'm watching the P&L calculations change) - At some point my study sees an exit condition on a future bar and closes the position as expected. This is what I think MAY be happening: - A successful sc.BuyEntry() is made and the sc.AllowOnlyOneTradePerBar becomes active - On a subsequent iteration through the study on the same bar, an unsuccessful sc.BuyEntry() attempt is made. Probably because my entry conditions are valid. - The -1@____ is displayed on the chart and I get the error message "Order skipped because only one trade per bar is allowed." Could this be what is happening? On the first unsuccessful attempt, the -1@____ is being displayed in error As I stated in my first post, I have not seen this happen when sc.SellEntry opens a position first. This does not happen on every successful sc.BuyEntry. When it does happen, it only happens once and I get the error message only one time. My programming style is defensive so I should never get this message even on a first unsuccessful attempt. The ACTUAL complete code pertaining to the issue is below. I think this may be an actual bug and not my programming. I hope this helps. if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED) orderEntryDelayed = orderExitDelayed = false; sc.GetTradePosition(PositionData); if (PositionData.PositionQuantity <= -1 && !orderExitDelayed) { if (exitOdds >= ir_MinExitOdds.GetFloat() / 100) { orderExitDelayed = true; orderType = atm_ORDER_EXITBUY; } else return; } else if (PositionData.PositionQuantity == 0 && !orderEntryDelayed) { if (entryOdds >= ir_MinEntryOdds.GetFloat() / 100) { if (entryDirection >= 1) { orderEntryDelayed = true; orderType = atm_ORDER_ENTRYBUY; } else if (entryDirection <= -1) { orderEntryDelayed = true; orderType = atm_ORDER_ENTRYSELL; } else return; } else return; } else if (PositionData.PositionQuantity >= 1 && !orderExitDelayed) { if (exitOdds >= ir_MinExitOdds.GetFloat() / 100) { orderExitDelayed = true; orderType = atm_ORDER_EXITSELL; } else return; } else return; s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 1; NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.TimeInForce = SCT_TIF_DAY; if (orderType == atm_ORDER_ENTRYBUY || orderType == atm_ORDER_EXITBUY) orderResult = (int)sc.BuyEntry(NewOrder); // Submit order if (orderType == atm_ORDER_ENTRYSELL || orderType == atm_ORDER_EXITSELL) orderResult = (int)sc.SellEntry(NewOrder); // Submit order if (orderResult < 1) sc.AddMessageToLog(sc.GetTradingErrorTextMessage(orderResult), ir_OpenMessageLog.GetBoolean()); |