- ago
Hello,

I have a problem with a short stragey. It seems to work well with a simple exit:

Cover after 1 bar

However, I would like to add also a "Cover at Limit" exit - which in my opinion should lead to a covering probably the same day the shares are short-sold, if the limit course is reached.

But no matter what limit I enter - e.g. 0.5% below open - there is never any difference to the result without this additional rule. Only when I remove the "Cover after 1 bar" I get different results depending on the percentage value I use. (I always use "Open" as a reference - is that correct?) But I want both rules to apply: To cover on the first day, if the limit is reached OR to sell beginning of next day, if it is not reached.

How could I set up this appropriately? Thanks for your help!

Best regards
Werner
0
597
Solved
6 Replies

Reply

Bookmark

Sort
- ago
#1
Probably the Limit Order becomes only valid at the second bar? Could that be, so that it is impossible to have a limit order the day the share is short-sold?
0
- ago
#2
Hi Werner,

QUOTE:
But no matter what limit I enter - e.g. 0.5% below open - there is never any difference to the result without this additional rule.

I assume you're using WL7 B53. Given a simple test case, how can we reproduce this to help you?
QUOTE:
Probably the Limit Order becomes only valid at the second bar?

Not sure what "second" bar you're talking about but orders are placed for the bar next to the signal bar (i.e. idx+1).
0
Cone8
 ( 7.89% )
- ago
#3
Same-bar exits must be coded in a C# Strategy. It's not hard, and once you have your block strategy "complete", just click the Open as a C# Coded Strategy button. This opens a new Strategy Window, and now you can edit and save it as a new Strategy.

For the same-bar exit, copy and paste this method at the same level as the Execute method.... e.g., right above the line public override void Execute(BarHistory bars, int idx)
CODE:
      public override void AssignAutoStopTargetPrices(Transaction t, double basisPrice, double executionPrice)       {          double pct = 0.5;    // change this value as required                    if (t.TransactionType == TransactionType.Short)          {             t.AutoProfitTargetPrice = executionPrice * (1 - pct / 100.0);    // 0.5% below the entry price          }          else          {             t.AutoProfitTargetPrice = executionPrice * (1 + pct / 100.0);    // 0.5% above the entry price          }                }

Note!
For valid results for same-bar exits in a backtest, the strategy should enter the position with a market order.
0
Best Answer
- ago
#4
Thank you very much for your help, Cone!

I was able to create this "same-bar-limit-covering". It did not lead to additional profit. But then I found the "AutoStopLossPrice" setting, and this led to a minor improvement.

My idea would be to experiment with Stop Loss setting dependent on the stock's liquidity. Do you know maybe, if I could use the ATRP indicator (or another liquidity indicator) in this code and how to write it?

Best regards
Werner
0
- ago
#5
You could use the Tag property to store information in a Transaction while in Execute and then restore it in Assign...
0
- ago
#6
OK, thank you, Eugene. I did it - hopefully properly:

a) In "Initialize()" I set the ATRP:

indicator5 = new ATRP(bars,16);

b) After "PlaceTrade()" - which does the shorting:

double d;
d = indicator5[ index ];
_transaction.Tag = d;

c) And then in "AssignAutoStopTargetPrices()":

pct += atrp_reduc + Convert.ToDouble( t.Tag ) * atrp_fac;

So far, I got only a very minor improvement with that. But maybe I need to optimize it.

Best regards
Werner
1

Reply

Bookmark

Sort