Hey guys! just explore this new forum! , well Im working in a strategy , based on the opening, how I calculate and all the other things is just working fine, Im in a 1 min chart , Basically, after establishing the range, I try to place two orders: one above the high of the opening range (buy) and another below the low of the opening range (sell), waiting to be triggered when the price reaches those points.
Regarding the logic to capture my data, I have no problem. However, when I apply the strategy to the chart, nothing happens— the orders never appear on the chart, they never get executed, nothing happens.
I tried changing the logic and using CrossAbove
and CrossBelow
, and that works perfectly, but in that case, the market waits until the close of the candle to enter, which is not what I want. I want to enter as close as possible to my upper and lower limits.
I’m not sure if I’m using the order methods incorrectly. I’ve used EnterLongStopMarket()
and also EnterLongStopLimit()
, same for sell, but I can’t get it to work properly. In some cases, only one of the orders gets placed, but it’s not consistent.
I’m wondering if someone could help clarify things for me. I’m leaving a portion of the code here. Thank you! `protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
// Calculate opening range
if (Times[0][0].TimeOfDay >= SessionStart.TimeOfDay && Times[0][0].TimeOfDay <= SessionFinish.TimeOfDay && !isOpeningRangeSet)
{
openingRangeHigh = Math.Max(openingRangeHigh, High[0]);
openingRangeLow = Math.Min(openingRangeLow, Low[0]);
}
else if (Times[0][0].TimeOfDay > SessionFinish.TimeOfDay && !isOpeningRangeSet)
{
isOpeningRangeSet = true;
Print("Opening Range set: High=" + openingRangeHigh + ", Low=" + openingRangeLow);
}
// Draw opening range visuals
if (Times[0][0].TimeOfDay == SessionFinish.TimeOfDay)
{
Draw.Rectangle(this, "Opening Range" + CurrentBar, false, 6, openingRangeHigh, 0, openingRangeLow, Brushes.Gold, Brushes.Gold, 20);
Draw.Text(this, "Data" + CurrentBar, "Range: " + (openingRangeHigh - openingRangeLow), 5, openingRangeHigh);
Draw.Text(this, "Check" + CurrentBar, "B/P: " + (openingRangeHigh + 4 * TickSize), 0, openingRangeHigh + 10 * TickSize);
Draw.Text(this, "Check" + CurrentBar + 1, "S/P: " + (openingRangeLow - 4 * TickSize), 0, openingRangeLow + 10 * TickSize);
}
// Place orders after opening range is set
if (isOpeningRangeSet && Times[0][0].TimeOfDay >= SessionFinish.TimeOfDay && Times[0][0].TimeOfDay <= SessionFinish.TimeOfDay.Add(new TimeSpan(0, 16, 0)) && BarsInProgress == 0 )
{
Draw.Text(this, "Check1" + CurrentBar + 2, "1" , 0, Low[0] - 2 * TickSize);
if (Position.MarketPosition == MarketPosition.Flat)
{
Draw.Text(this, "Check2" + CurrentBar + 1, "2" , 0, Low[0] - 2 * TickSize);
double buyStopPrice = openingRangeHigh + StretchTest * TickSize;
double sellStopPrice = openingRangeLow - StretchTest * TickSize;
Print("Placing orders: BuyStop=" + buyStopPrice + ", SellStop=" + sellStopPrice);
EnterLongStopLimit(buyStopPrice, openingRangeHigh, "ORB_Buy");
EnterShortStopLimit(sellStopPrice, openingRangeLow, "ORB_Sell");
SetStopLoss("ORB_Buy", CalculationMode.Price, openingRangeLow, false);
SetStopLoss("ORB_Sell", CalculationMode.Price, openingRangeHigh, false);
}
}
// Exit logic
if (BarsSinceEntryExecution(0, "ORB_Buy", 0) >= ExitBars)
ExitLong("ORB_Buy");
if (BarsSinceEntryExecution(0, "ORB_Sell", 0) >= ExitBars)
ExitShort("ORB_Sell");
// Reset at session start
if (Times[0][0].TimeOfDay == SessionStart.TimeOfDay)
{
openingRangeHigh = 0;
openingRangeLow = double.MaxValue;
isOpeningRangeSet = false;
positionOpened = false;
Print("Resetting ORB variables at session start");
}
}`