hi Guys,
i am trying to learn C# coding which has hard learn curve for a coding beginner.
i am still trying to understand the logic, so may have some stupid questions.
here are some of them:
1. if i coding the position in my strategy, is that still under the limitation of backtest setting position size ?
for example, i give a maxPositon function to calculate position, and i do not want use the position method in backtest setting, how should i set ?
CODE:
Transaction t1 = PlaceTrade(bars, TransactionType.Short, OrderType.Market, 0, 1, "Short"); t1.Quantity = maxPositon;
thanks.
Rename
Suggestion: please do not group different questions together in one topic. For now I've extracted your offtopic question into another thread:
https://www.wealth-lab.com/Discussion/Can-I-set-futures-mode-from-code-11459
https://www.wealth-lab.com/Discussion/Can-I-set-futures-mode-from-code-11459
QUOTE:
1. if i coding the position in my strategy, is that still under the limitation of backtest setting position size ?
One cannot make the Backtester lose control of its real world constraints. Could you ask your question in a more straightforward way to help understand your intention here?
I want to use my own code to calculate the position size instead of the built-in position size calculation method in the backtest setting interface.
For example, I want to use the percentage volatility calculation concept but replace ATR with other values.
When I backtest with my own position size code, will the position size option in the backtest setting interface affect the position size calculation of my code?
f so, how should I set it to ensure the position size is calculated according to my own code?
For example, I want to use the percentage volatility calculation concept but replace ATR with other values.
When I backtest with my own position size code, will the position size option in the backtest setting interface affect the position size calculation of my code?
f so, how should I set it to ensure the position size is calculated according to my own code?
QUOTE:
When I backtest with my own position size code, will the position size option in the backtest setting interface affect the position size calculation of my code?
Some constraints in the pos.size dialog will be retained. With this in mind, your can override the position size using the documented way:
https://www.wealth-lab.com/Support/ApiReference/Transaction
P.S. Make sure you haven't overlooked Max Risk Percent sizing (see Preferences > Trading) which can streamline your task of using the custom volatility calculation.
You can set the Quantity property of the Transaction instance that you get as a result of the PlaceTrade call.
In the block, I can't see the code for positionsizer. How can I view the complete code for the strategy that includes positionsizer?
You don't see it because it does not exist in the context.
You seem to be going the hard way while Wealth-Lab is meant to offer straightforward approaches. Can you elaborate on your task?
You seem to be going the hard way while Wealth-Lab is meant to offer straightforward approaches. Can you elaborate on your task?
QUOTE:
how should I set it to ensure the position size is calculated according to my own code?
This is what Glitch said to do in Post #5...
CODE:
public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { if (bars.Close.CrossesOver(SMA.Series(bars.Close, 20)[idx], idx)) { Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market); t.Quantity = 100; // do some calculation here and assign it to t.Quantity } } : :
WealthLab has many comprehensive features.
However, relying solely on blocks and the existing position sizer makes it challenging to implement my trading system.
For example, my trading strategy requires using both the equity curve control and percent volatility methods to determine position sizing.
As a result, I have to try to write the program myself. Since I don't have a programming background, I can only imitate and learn by looking at the C# code in the blocks. it is truely a hard way.
However, I couldn't find similar code for the position sizer part. Therefore, I am also evaluating how to make use of WealthLab.
However, relying solely on blocks and the existing position sizer makes it challenging to implement my trading system.
For example, my trading strategy requires using both the equity curve control and percent volatility methods to determine position sizing.
As a result, I have to try to write the program myself. Since I don't have a programming background, I can only imitate and learn by looking at the C# code in the blocks. it is truely a hard way.
However, I couldn't find similar code for the position sizer part. Therefore, I am also evaluating how to make use of WealthLab.
QUOTE:
... my trading strategy requires using both the equity curve control and percent volatility methods to determine position sizing.
These are two unrelated metrics. I can't imagine how you could combine the two to get a single sizing metric that would be sane. Moreover, the "entire" equity curve is only available to you after the backtest completes (i.e. after all the trading is done). It might be more doable to base your size metric on recent price performance instead (i.e. use a price momentum indicator).
It is possible to write your own posSizer plugin if you're an experienced C# programmer. But for now, I would simply have your strategy compute the position size and set it on the Transaction instance as is shown in Post #8.
Re: Post #9. What you request goes beyond the basic capability. Superticker is correct, and you're welcome to leverage our paid concierge support service if you require some complex programming i.e. a custom PosSizer.
Meanwhile, you can try to code something in C# right in the Strategy like shown in this forum topic for the percent equity sizing based on the portfolio's equity, adding more logic.
Meanwhile, you can try to code something in C# right in the Strategy like shown in this forum topic for the percent equity sizing based on the portfolio's equity, adding more logic.
The world of trading is always full of the unknown, and it is this lack of fixed answers that makes trading so fascinating, isn't it? I believe you're right. Thank you for your responses.
What's wrong with the specific answer in Post #8?
Post #8 answer is no problem.
I hope to see the C# code for a position sizer like in block, so that when I write my own strategy, I have a template to refer to. This way, I can reduce asking ineffective questions and wasting everyone's time.
However, it seems that there is no place to find it.
Nevertheless, I still appreciate everyone's answers.
I hope to see the C# code for a position sizer like in block, so that when I write my own strategy, I have a template to refer to. This way, I can reduce asking ineffective questions and wasting everyone's time.
However, it seems that there is no place to find it.
Nevertheless, I still appreciate everyone's answers.
Should we change the discussion from "Coding position size in Strategy" to a feature request for custom position sizing in a Building Block?
Is that what you mean by "position sizing like in block"?
Is that what you mean by "position sizing like in block"?
yes please, feature reques will be better.
by " position sizing like in block", i mean I hope that position sizing can also have an option to open as a C# coded strategy, just like building blocks, which can display the code of the position sizing method I selected.
Alternatively, after I built the strategy in building blocks and chosen the position sizing method in strategy settings, there can be an option to display all the code (including the strategy and position sizing).
thanks.
by " position sizing like in block", i mean I hope that position sizing can also have an option to open as a C# coded strategy, just like building blocks, which can display the code of the position sizing method I selected.
Alternatively, after I built the strategy in building blocks and chosen the position sizing method in strategy settings, there can be an option to display all the code (including the strategy and position sizing).
thanks.
We will never have position sizing in a block. There’s already a place for it in Strategy Settings and there’s already a place to introduce advance position sizers there.
Let me summarize to ensure there are no further misunderstandings and to avoid wasting everyone's time.
like i said,my core request is to see the complete code of the strategy I created in the building block, including the selected position sizing method.(like the fuction "open as C# Coded Strategy" in building block, but can see the complete code including position sizer)
I believe this code exists, and my only request is to see it.
To avoid confusion, I suggest labeling the feature request as: "How to view the complete code of the strategy I created, including the position sizing method."
I hope I have made myself clear. Thank you.
like i said,my core request is to see the complete code of the strategy I created in the building block, including the selected position sizing method.(like the fuction "open as C# Coded Strategy" in building block, but can see the complete code including position sizer)
I believe this code exists, and my only request is to see it.
To avoid confusion, I suggest labeling the feature request as: "How to view the complete code of the strategy I created, including the position sizing method."
I hope I have made myself clear. Thank you.
The code exists but not in the Strategy, which is why it's not possible to show it. It exists in a separate sub-system called Advanced Position Sizing. We separate the Strategy code from the position sizing in this way in order to achieve the most flexibility.
@arthur527 Let's keep this simple.
Can you post an equation showing how you want to calculate the number of shares to buy? You don't have to worry about getting all the C# syntax right because we can correct that part and post a corrected implementation for you. That should get you going.
The C# code generated from blocks is confusing--I agree. If you can start with one of the C# sample strategies, that may be easier. What indicators does your strategy use? Perhaps we can knock out an example strategy based around your most important indicator (or two).
You could also have the Wealth-Lab developers write a custom PosSizer for you via their paid concierge service as discussed in Post #11. Then you can use blocks to write the rest of your strategy. But the downside of this approach is that you wouldn't be able to modify the custom PosSizer yourself if you want to change it--big disadvantage. I think the approach in the first paragraph (where you can modify the position sizing code yourself) is a much better option for now.
Can you post an equation showing how you want to calculate the number of shares to buy? You don't have to worry about getting all the C# syntax right because we can correct that part and post a corrected implementation for you. That should get you going.
QUOTE:
... I don't have a programming background;... I can only ... learn by looking at the C# code in the blocks. it is truly a hard way.
The C# code generated from blocks is confusing--I agree. If you can start with one of the C# sample strategies, that may be easier. What indicators does your strategy use? Perhaps we can knock out an example strategy based around your most important indicator (or two).
You could also have the Wealth-Lab developers write a custom PosSizer for you via their paid concierge service as discussed in Post #11. Then you can use blocks to write the rest of your strategy. But the downside of this approach is that you wouldn't be able to modify the custom PosSizer yourself if you want to change it--big disadvantage. I think the approach in the first paragraph (where you can modify the position sizing code yourself) is a much better option for now.
Your Response
Post
Edit Post
Login is required