hammerschloggen
New member
I am working on a strategy that is functioning properly up to a certain point, but I want to be able to adjust my Stop Loss if the High ever breaks a Target Threshold.
The primary avenue I have explored is to use the GetValue() and GetMaxValueOffset() to check if the High has ever been greater than the Target since the trade was made. Unfortunately, I have to use a counter to do so and since the count number is dynamic it does not work with the GetMaxValueOffset() function.
Any suggestions would be great. Assume ExitCondition has some pre-defined criteria.
The primary avenue I have explored is to use the GetValue() and GetMaxValueOffset() to check if the High has ever been greater than the Target since the trade was made. Unfortunately, I have to use a counter to do so and since the count number is dynamic it does not work with the GetMaxValueOffset() function.
Any suggestions would be great. Assume ExitCondition has some pre-defined criteria.
Code:
def Target = EntryPrice() + EntryPrice() * 0.05;
def StopLoss = EntryPrice() - EntryPrice() * 0.05;
def Count = if !isNaN(EntryPrice()) then Count[1] + 1 else 0;
def OverTarget = GetValue(high, GetMaxValueOffset(high, Count), Count) >= Target;
def ExitPrice = if OverTarget then EntryPrice() else StopLoss;
AddOrder(OrderType.SELL_TO_CLOSE, ExitCondition, ExitPrice, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Exit" + BarNumber());