- ago

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;


2. i want to use pointvalue...

thanks.
0
417
Solved
20 Replies

Reply

Bookmark

Sort
- ago
#1
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
0
- ago
#2
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?
0
- ago
#3
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?
0
- ago
#4
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.
0
Best Answer
Glitch8
 ( 11.36% )
- ago
#5
You can set the Quantity property of the Transaction instance that you get as a result of the PlaceTrade call.
0
- ago
#6
In the block, I can't see the code for positionsizer. How can I view the complete code for the strategy that includes positionsizer?
0
- ago
#7
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?
0
Cone8
 ( 5.94% )
- ago
#8
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             } } : :
0
- ago
#9
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.
0
- ago
#10
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.
0
- ago
#11
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.
0
- ago
#12
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.
0
Cone8
 ( 5.94% )
- ago
#13
What's wrong with the specific answer in Post #8?
0
- ago
#14
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.
0
Cone8
 ( 5.94% )
- ago
#15
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"?
0
- ago
#16
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.
0
Glitch8
 ( 11.36% )
- ago
#17
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.
1
- ago
#18
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.
0
Glitch8
 ( 11.36% )
- ago
#19
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.
1
- ago
#20
@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.

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.
0

Reply

Bookmark

Sort