Today, on January 30, 2025, a new update for WealthLab was released, and after the update, my code is no longer running. The error seems to occur specifically with sell orders, particularly when setting limit and stop prices. Buy orders are working fine, even though they use the same logic.
Error:
"Execute Exception (USDJPY_H1,1162) Line 207 - Wrong Exit Signal type for Short Position
at WealthLab.Backtest.Backtester.ClosePosition(Position pos, OrderType orderType, Double price, String exitSignalName)
at WealthLab.Backtest.StrategyBase.ClosePosition(Position pos, OrderType orderType, Double price, String exitSignalName)
at WealthScript8.MyStrategy.Execute(BarHistory bars, Int32 idx) in :line 207
at WealthLab.Backtest.UserStrategyExecutor.AddParam(List`1 lst, DateTime dt)
"
Buy position WORKING:

Sell position NOT WORKING

Just to emphasize, this same code was working fine before the update.
Thank you for your attention!
Error:
"Execute Exception (USDJPY_H1,1162) Line 207 - Wrong Exit Signal type for Short Position
at WealthLab.Backtest.Backtester.ClosePosition(Position pos, OrderType orderType, Double price, String exitSignalName)
at WealthLab.Backtest.StrategyBase.ClosePosition(Position pos, OrderType orderType, Double price, String exitSignalName)
at WealthScript8.MyStrategy.Execute(BarHistory bars, Int32 idx) in :line 207
at WealthLab.Backtest.UserStrategyExecutor.AddParam(List`1 lst, DateTime dt)
"
Buy position WORKING:
Sell position NOT WORKING
Just to emphasize, this same code was working fine before the update.
Thank you for your attention!
Rename
You'll have to either paste the entire strategy code here or email it to us at support@wealth-lab.com, because I'm not seeing any problems with ClosePosition and short positions in some ad hoc testing.
QUOTE:
"Execute Exception (USDJPY_H1,1162) Line 207 - Wrong Exit Signal type for Short Position
So you are trying to exit a short position with a Sell TransactionType when you should be using a Cover TransactionType instead; I got that. But you haven't included enough code to tell us if long positions might be mistaken for short positions at the ClosePosition statement. We need more code.
Email sent,
Thank you.
Thank you.
The case of "Wrong Exit Type" was made to detect cases for Live Positions that didn't correspond to the "intended" OrderType programmed in the strategy.
ClosePosition() is agnostic - it works for both Long and Short positions. The issue we wanted to solve was prompted by a customer who was trading with "Live Positions". Even though the script only created Long positions, the Live Position was a short. The result was that ClosePosition() would actually "Cover", resulting in actually buying another position.
The only way we can detect the "intention" of ClosePosition() is looking at the exitSignalName. In your case, it starts with "Sell at", which matches a Long position. (This is the way the Blocks generate signal names. Blocks always match the correct position type.)
Solution:
Change your exitSignalNames in ClosePosition() to "Exit at... "
ClosePosition() is agnostic - it works for both Long and Short positions. The issue we wanted to solve was prompted by a customer who was trading with "Live Positions". Even though the script only created Long positions, the Live Position was a short. The result was that ClosePosition() would actually "Cover", resulting in actually buying another position.
The only way we can detect the "intention" of ClosePosition() is looking at the exitSignalName. In your case, it starts with "Sell at", which matches a Long position. (This is the way the Blocks generate signal names. Blocks always match the correct position type.)
Solution:
Change your exitSignalNames in ClosePosition() to "Exit at... "
Thank you very much for your help, I have modified the code.
Before:
After:
Working perfectly.
Before:
CODE:
if (foundPositionVenda != null) { ClosePosition(foundPositionVenda, OrderType.Stop, vS, "Sell at stop loss: 2x signal bar range"); ClosePosition(foundPositionVenda, OrderType.Limit, vA, "Sell at profit target: 6x signal bar range"); } if (foundPositionVenda != null && Minima[index] <= (entrada - (diffVenda * Parameters[9].AsDouble))) { vS = entrada - (diffVenda * Parameters[11].AsDouble); ClosePosition(foundPositionVenda, OrderType.Stop, vS, "Break even Stop");
After:
CODE:
if (foundPositionVenda != null) { PlaceTrade(bars, TransactionType.Cover, OrderType.Stop, vS, "Stop Loss"); PlaceTrade(bars, TransactionType.Cover, OrderType.Limit, vA, "Take Profit"); } if (foundPositionVenda != null && Minima[index] <= (entrada - (diffVenda * Parameters[9].AsDouble))) { vS = entrada - (diffVenda * Parameters[11].AsDouble); PlaceTrade(bars, TransactionType.Cover, OrderType.Stop, vS, "Break even Stop"); }
Working perfectly.
Your Response
Post
Edit Post
Login is required