Hello,
how can I Open and Close at the same bar with AtClose orders? This is for a reallocation. Example, every end of month sell all position an reopen this position at close with the actually %size of Equity.
MDA
Size:
Color:
Hi,
Clarification required as probably I misunderstand you. Assuming daily scale, you buy the same symbol with BuyAtClose and issue an immediate SellAtClose. What'd be the purpose of doing this in a Strategy, as it only leads to a loss due to trading costs?
Size:
Color:
Hi Eugene,
A simple example. I have two positions with 50/50 size from the equity. Next month, one position has risen more than the other. I now have 60/40 size. Now I want to reallocate 50/50. I thought for a simple code, I sell everything and buy new 50/50 back. In reality, I sell only one part and buy only part of the other to get to 50/50.
MDA
Size:
Color:
That keeps it simple and certainly a good way to do it. Example below.
Install
Community.Components to use the
DateOfNextTradingDay method to assist finding the last trading day of the month.
CODE:
Please log in to see this code.
Size:
Color:
Hi Cone,
thanks for feedback.
CODE:
Please log in to see this code.
this does'nt make a trade. the change of month was not the problem. If I close and open next day at market, then works my code. only atClose is the problem. with atclose I have a close end of moth and a open end of next month.
MDA
Size:
Color:
QUOTE:
this does'nt make a trade.
Matthias, how do you run the strategy? Sure I get some entries if I run Cone's code.
Size:
Color:
hmm, OK the complete code from Cone works, but with the same problem ... the open is end of next month with me
Size:
Color:
That's because there is not enough capital to execute all signals. Try it in Raw Profit mode to make sure the code works as intended.
Size:
Color:
ahhhh yes, in RAW Profit Mode works the code, hmmm but I need the Portfolio Simulation Mode ... I test with Margin Factor 10:1 for enough Money ... with "atMarket" oders for next day works the Code correct, only with "atClose" not
Size:
Color:
Size:
Color:
Sorry, I have tried workaround 1 and 2. I do not get it to work as it should.
Size:
Color:
Then your position sizing chosen within Position Options is not appropriate for the selected DataSet, if you wanted to capture all signals. Try a much smaller position size, use Raw Profit, or execute the system in single-symbol mode.
Size:
Color:
I have still one idea ... is there a code for with "SellAtMarket" and "SellAtLimit" how this Code:
CODE:
Please log in to see this code.
When I Change Buy and sell then I get error messages
Size:
Color:
I'm not sure where your snippet came from, but here's the correction for that BuyAtMarket method:
CODE:
Please log in to see this code.
Now, the reason for doing that for BuyAtMarket was to put the precise entry price to enter at limit on the open in order to not skip trades for the backtest. It makes no sense to do that for exit orders. If you SellAtMarket (or ExitAtMarket), no resizing is required... the number of shares in the position that you specify will be exited. Ok?
Size:
Color:
Hi Cone,
thanks for help. " pos = LastPosition " that was my mistake. I had previously experimented with sellatlimit and forget to delete.
With Buyatlimit (the Code above) works for me when I increase the margin factor. But then too many positions are opened. I just can not get any further.
Size:
Color:
You mean that MF 10:1 causes too many positions to be opened? How about a smaller MF, like 1.10 or 1.15, for example?
Size:
Color:
with small margin factor I have the old Problem, the trades only open end of next month. really a simple Job. Close end of month five position and open same time five position with actually ROC Ranking. Regrettable that it is so complicated.
Size:
Color:
I'm trying to communicate the point that your position size should be in line with the number of candidates your strategy is creating on this DataSet. Five positions and a 20% equity size means a lof of skipped trades that "Skipped trade solution" and "For last position, use all what's left" combined (from
Position Options) should minimize. It should rather be 15% and a MF of 1.15, IMHO.
Size:
Color:
Hi Eugene,
thank you for your help. Sorry, I just can not get it.
MDA
Size:
Color:
If you like, please post your code with a detailed description of what you want it to do. I'm sure we can make it work ;)
Size:
Color:
Hi Cone,
here is the code:
CODE:
Please log in to see this code.
The Positions Settings are in the below in the picture.
I tried everything. I have not managed to close 5 positions at the close and open at the same time.
MDA
Size:
Color:
Did you intend the trailing semicolon on the line below?
CODE:
Please log in to see this code.
Size:
Color:
Matthias,
The "Skipped trade solution" cannot help in your case. It's for AtMarket orders only.
The more symbols your DataSet contains, the more skipped trades will there be. On a 5-symbol DataSet, at 15% equity and Margin Factor = 1.5 you can virtually get rid of them.
P.S. There's a slight logic error:
CODE:
Please log in to see this code.
Size:
Color:
Yes, that ";" was wrong. But that is not the reason for my problem. I need a simple ranking system without lists programming for closing trading.
Size:
Color: