_Merch_Man_
Active member
Morning Guys
I've got a strategy which works except when then the exit condition happens one bar after entry. The strategy buys when the high crosses above the blue line and sells when price crosses below the grey (middle) line. As you can see in the image, when the exit condition happens one bar after entry, ToS is ignoring the exit condition. The exit condition works except in this scenario. Is there a way to "fix" this? Thanks!
I've got a strategy which works except when then the exit condition happens one bar after entry. The strategy buys when the high crosses above the blue line and sells when price crosses below the grey (middle) line. As you can see in the image, when the exit condition happens one bar after entry, ToS is ignoring the exit condition. The exit condition works except in this scenario. Is there a way to "fix" this? Thanks!
Ruby:
input length = 10;
input averageType = AverageType.WILDERS;
input Days_Before = 1;
input Days_After = 2;
def WideRangingDay = TrueRange(high, close, low) / ATR(length, averageType) > 1.6;
def Signal = if IsNaN(close[Days_After]) then Signal[Days_After] else WideRangingDay[Days_After];
def ValidBarNumber = if !IsNaN(BarNumber()) then BarNumber() else ValidBarNumber[1];
def WideRangingDayStartBarID = if Signal then ValidBarNumber[Days_After + Days_Before] else WideRangingDayStartBarID[1];
def WideRangingDayEndBarID = if Signal then ValidBarNumber else WideRangingDayEndBarID[1];
def True_High = fold th = ValidBarNumber - WideRangingDayEndBarID
to ValidBarNumber - WideRangingDayStartBarID + 1
with THC = GetValue(high, ValidBarNumber - WideRangingDayEndBarID)
do if THC > GetValue(high, th) then THC else GetValue(high, th);
def True_Low = fold tl = ValidBarNumber - WideRangingDayEndBarID
to ValidBarNumber - WideRangingDayStartBarID + 1
with TLC = GetValue(low, ValidBarNumber - WideRangingDayEndBarID)
do if TLC < GetValue(low, tl) then TLC else GetValue(low, tl);
plot PTRH = True_High;
plot PTRL = True_Low;
plot MidLevel = ((PTRH-PTRL)/2)+PTRL;
input StartDate = 19501201;
def Days = DaysFromDate(StartDate);
def EntryCondition = high crosses above PTRH and Days >= 0;
def EntryPrice = PTRH;
def ExitCondition1 = low crosses below ((PTRH-PTRL)/2)+PTRL;
def ExitPrice = ((PTRH-PTRL)/2)+PTRL;
def ExitNow = ExitCondition1;
AddOrder(OrderType.BUY_TO_OPEN, EntryCondition, price = EntryPrice, tradeSize = 1, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "");
AddOrder(OrderType.SELL_TO_CLOSE, ExitNow, price = ExitPrice, tradeSize = 1, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "");