I have Sell at 40% profit target and Cover at 40% profit target as exit strategies.
It works on the long leg (ie Sell at 40%), but on the short one (ie Cover) it exits the following bar at very small % change (no big shift in min/max, so no touching of the 40% barrier).
Any clue?
It works on the long leg (ie Sell at 40%), but on the short one (ie Cover) it exits the following bar at very small % change (no big shift in min/max, so no touching of the 40% barrier).
Any clue?
Rename
Please show the relevant parts of your code...
here it is:
CODE:
namespace WealthScript1 { public class MyStrategy : UserStrategyBase { public MyStrategy() : base() { AddParameter("exp", ParameterType.Double, 5, 5, 10, 1); AddParameter("Profit Target 2", ParameterType.Double, 40, 5, 50, 5); AddParameter("How many Bars?", ParameterType.Int32, 100, 10, 100, 10); ..... ..... ..... public override void Execute(BarHistory bars, int idx) { int index = idx; bool condition0; condition0 = false; { if (indicator[index] < 0.00) { if (indicator2[index] >= Parameters[0].AsDouble) { if (indicator3.TurnsDown(index)) { condition0 = true; } } } } if (condition0) { _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0, "Buy At Market (1)"); } condition0 = false; { condition0 = true; } if (condition0) { foreach(Position foundPosition0 in OpenPositions) { if (foundPosition0.PositionTag == 0) { Backtester.CancelationCode = 134; value = (Parameters[1].AsDouble / 100.0) + 1.0; ClosePosition(foundPosition0, OrderType.Limit, foundPosition0.EntryPrice * value, "Sell at 40% profit target"); } } } condition0 = false; { condition0 = true; } if (condition0) { foreach(Position foundPosition0 in OpenPositions) { if (foundPosition0.PositionTag == 0) { Backtester.CancelationCode = 134; if (idx - foundPosition0.EntryBar + 1 >= Parameters[2].AsInt) { ClosePosition(foundPosition0, OrderType.Market, 0,"Sell after 100 bars"); } } } } bool condition1; condition1 = false; { if (indicator4[index] > 0.00) { if (indicator5[index] >= Parameters[0].AsDouble) { if (indicator6.TurnsDown(index)) { condition1 = true; } } } } if (condition1) { _transaction = PlaceTrade(bars, TransactionType.Short, OrderType.Market, 0, 1, "Short At Market (2)"); } condition1 = false; { condition1 = true; } if (condition1) { foreach(Position foundPosition1 in OpenPositions) { if (foundPosition1.PositionTag == 1) { Backtester.CancelationCode = 137; ClosePosition(foundPosition1, OrderType.Limit, foundPosition1.EntryPrice * 1.0 - (Parameters[1].AsDouble/ 100.0), "Cover at 40% profit target"); } } } condition1 = false; { condition1 = true; } if (condition1) { foreach(Position foundPosition1 in OpenPositions) { if (foundPosition1.PositionTag == 1) { Backtester.CancelationCode = 137; if (idx - foundPosition1.EntryBar + 1 >= Parameters[2].AsInt) { ClosePosition(foundPosition1, OrderType.Market, 0,"Cover after 100 bars"); } } } }
What is this?
Why do you use PositionTag?
Where is it set?
CODE:
if (foundPosition0.PositionTag == 0)
Why do you use PositionTag?
Where is it set?
This code is wizard generated. It may be helpful if you show the Blocks instead.
here is an example of the results with problem in short covering ...
Thanks for the heads up. There's an error in Cover at % Profit exit rule. Specifically...
We'll have that fixed in build 13.
CODE:
// this ... foundPosition1.EntryPrice * 1.0 - (Parameters[1].AsDouble/ 100.0) ... // should be: ... foundPosition1.EntryPrice * (1.0 - Parameters[1].AsDouble / 100.0) ...
We'll have that fixed in build 13.
Your Response
Post
Edit Post
Login is required