Support Board
Date/Time: Fri, 03 May 2024 13:39:19 +0000
Post From: I buy at the end of a candle but it is filled in the next candle
[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 |
candle.png / V - Attached On 2021-06-04 22:13:53 UTC - Size: 59.93 KB - 209 views |