Support Board
Date/Time: Thu, 16 Jan 2025 04:50:10 +0000
Post From: Ascil Bars since entry.
[2017-09-27 22:00:52] |
vectorTrader - Posts: 86 |
I am writing my first c++ code and wondering how to count bars since entry. I thought that this would work but apparently not. First I created a persistant integer. I thought that this would work for exit but apparently its not counting at all. what am i doing wring to count the number of bars since the confirmed entry? int& BarsSince=sc.GetPersistentInt(3);
if (sc.Index == 0) { cbHLC = 0; BarsSince=0; } //Count the number of bars since entry //int BarsSinceEntry=0 s_SCPositionData PositionData; sc.GetTradePosition(PositionData); if(PositionData.PositionQuantity != 0) { if(BarsSince<50) { BarsSince++; } return; } sc.Subgraph[7][sc.Index]=BarsSince; // Create an s_SCNewOrder object. s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 1; NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; //Specify a Target and a Stop with 8 tick offsets. We are specifying one Target and one Stop, additional targets and stops can be specified as well. //NewOrder.Target1Offset = 50*sc.TickSize; NewOrder.Stop1Offset = 50*sc.TickSize; NewOrder.OCOGroup1Quantity = 1; // If this is left at the default of 0, then it will be automatically set. //Optional: Check if within allowed time range. In this example we will use 10:00 through 14:00. This is according to the time zone of the chart. //int BarTime = sc.BaseDateTimeIn[sc.Index].GetTime(); //bool TradingAllowed = BarTime >= HMS_TIME(10, 0, 0) && BarTime < HMS_TIME(14, 0, 0); //bool TradingAllowed = true; // Buy when the last price crosses the moving average from below. if (sc.Subgraph[4][sc.Index]> sc.Subgraph[4][sc.Index-5] && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED) { int Result = sc.BuyEntry(NewOrder); if (Result > 0) //If there has been a successful order entry, then draw an arrow at the low of the bar. { BuyEntrySubgraph[sc.Index] = sc.Low[sc.Index]; //Remember the order IDs for subsequent modification and cancellation //Target1OrderID = NewOrder.Target1InternalOrderID; Stop1OrderID = NewOrder.Stop1InternalOrderID; BarsSince=0; } } else if (PositionData.PositionQuantity > 0 && BarsSince>=50) { int Result = sc.BuyExit(NewOrder); //If there has been a successful order entry, then draw an arrow at the high of the bar. if (Result > 0) { BuyExitSubgraph[sc.Index] = sc.High[sc.Index]; } } |