Support Board
Date/Time: Mon, 10 Mar 2025 10:30:12 +0000
Post From: Backtesting with sc.AllowOnlyOneTradePerBar = TRUE
[2022-03-19 19:24:07] |
User409050 - Posts: 22 |
Hi thank you for your response, I'm sorry i have not made it clear enough. 1) are you expecting trades to be triggered only at the close of the current bar? No I'm not expecting trades to be triggered at the close, I'm expecting to see trades triggered at each Open/High/Low/Close Price because that the behavior mentioned in the documentation when one uses "Bar Based Backtesting". but it didn't when I added the option to exclude the last bar out of calculation. Here is my example: //1 input reference and 1 subgraph reference to draw arrows on every bar that meets the criteria SCInputRef date_to_place_orders = sc.Input[0]; SCSubgraphRef up_arrow = sc.Subgraph[0]; ... //for sc.defaults settings //some parts skipped because I don't to make the post too long //for autoloop sc.AutoLoop = 1; //setup unmannered trading in SC sc.AllowMultipleEntriesInSameDirection = TRUE; //stop when total position + working order = 10 sc.MaximumPositionAllowed = 10; sc.CancelAllOrdersOnEntriesAndReversals = false; sc.AllowEntryWithWorkingOrders = true; sc.MaintainTradeStatisticsAndTradesData = true; //allow > 1 trade for each bar sc.AllowOnlyOneTradePerBar = 0; sc.AllowOppositeEntryWithOpposingPositionOrOrders = TRUE; return; //------------------------------------end settings-------------- s_SCNewOrder test_order; test_order.OrderQuantity = 1; test_order.OrderType = SCT_ORDERTYPE_MARKET; test_order.TextTag = "Simple Order"; SCDateTime curDate = sc.BaseDateTimeIn[sc.Index]; if (curDate < date_to_place_orders.GetDate()) { return; } //Criteria //if the current date > the chosen date place as many order as it can //expected to see 4 orders for each bar when backtesting using "Bar replay" but stop when it reaches to 10 if (curDate > date_to_place_orders.GetDate()) { sc.BuyEntry(test_order); up_arrow[sc.Index] = sc.High[sc.Index]; } //ended up with the number of open position > maximum allowed position (10) //the reason is on the last bar, Sierra Chart cleared all the trade data and runs once more time for the last bar but //the last bar happens to meet the criteria and due to the fact that all openning positions have been cleared so, //it successfully placed another order and led to the "Trade Quantity" in Trades tab > Allowed number of position //Fixed by adding 1 more criteria //ended up with now using bar replay, each bar only processed once instead of 4 for each OHLC price if (curDate > date_to_place_orders.GetDate() && sc.Index < sc.ArraySize - 1) I can understand why it placed another order on the last bar, but I don't know why excluding the last bar out of calculation causes the "Bar Based Backtesting" runs only once for each bar instead of 4 times as before? Thanks Date Time Of Last Edit: 2022-03-19 19:34:12
|