Support Board
Date/Time: Wed, 26 Feb 2025 21:57:43 +0000
I buy at the end of a candle but it is filled in the next candle
View Count: 463
[2021-06-04 22:17:03] |
User582602 - Posts: 1 |
Hello Team, I have written a simple strategy to buy a contract at the close of a candle (I showed it on the chart) but I see it is executed in the next candle (not exactly at the close of the candle). My question is what is my problem? The code that I am using to buy is as simple as follow; // Buy when the last price crosses the moving average from below.
if (TradingAllowed && sc.CrossOver(Last, Subgraph_SimpMovAvg) == CROSS_FROM_BOTTOM && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED) { Result = (int)sc.BuyEntry(NewOrder); //Result = sc.BuyOrder(NewOrder); //If there has been a successful order entry, then draw an arrow at the low of the bar. if (Result > 0) { r_BuyEntryInternalOrderID = NewOrder.InternalOrderID; SCString InternalOrderIDNumberString; InternalOrderIDNumberString.Format("BuyEntry Internal Order ID: %d", r_BuyEntryInternalOrderID); sc.AddMessageToLog(InternalOrderIDNumberString, 0); Subgraph_BuyEntry[sc.Index] = sc.Low[sc.Index]; } } I have attached a pic that shows the one-candle difference between when I asked the system to buy and when the order was executed and filled. Thanks |
![]() |
[2021-06-05 10:44:14] |
User907968 - Posts: 833 |
Review the documentation for sc.GetBarHasClosedStatus, particularly this "The very last bar in the chart is never considered a closed bar until there is a new bar added to the chart." ACSIL Interface Members - Functions: sc.GetBarHasClosedStatus() At the point you are entering your order, a new bar has been added to the chart already, so although your arrow is drawn under the closed bar, the order is actually entered on the new chart bar. |
To post a message in this thread, you need to log in with your Sierra Chart account: