Hello,
Is it possible to implement this using building blocks? When one indicator crosses another. Buy after a 3% increase within 4 days
Thanks
Is it possible to implement this using building blocks? When one indicator crosses another. Buy after a 3% increase within 4 days
Thanks
Rename
We have a BarsSince indicator, but there isn't a way to apply it properly to a condition and compare it to a number of bars. That would be a handy condition and I'll put it on the "To Do" list.
Anyway, as an example, here's how you'd use BarSince to find how many bars since the Close crossed above a moving average.
Anyway, as an example, here's how you'd use BarSince to find how many bars since the Close crossed above a moving average.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript12 { public class MyStrategy : UserStrategyBase { IndicatorBase ind2; IndicatorBase barsSince; public override void Initialize(BarHistory bars) { ind2 = SMA.Series(bars.Close,50); PlotIndicator(ind2, WLColor.Blue); // bars since SMA crossed over ind2 barsSince = BarsSince.Series(bars.Close > ind2); PlotIndicator(barsSince); } public override void Execute(BarHistory bars, int idx) { } } }
There's always more than one way to skin a cat. If you drop the 4-day requirement and simply take the slope of the price (converted to percentages with ROC) over 4 bars, you will get something "sort of" similar. Some might even argue this linear regression approach, which takes an average over 4-bars, may give you a more stable solution in some situations.
The pctChgOver4days[idx] > 3.0 is looking for a 3% increase over a 4-bar period, which is different than what you're asking for. Do appreciate that. (I'm not sure the 3.0 number is correct, but the units for slope should be in percentage/bar where the ROC indicator puts price into percentages.)
And this solution is not looking at the SMA of the price, although you could add that.
I don't do Blocks, but someone should be able to convert the approach below into Blocks for you.
The pctChgOver4days[idx] > 3.0 is looking for a 3% increase over a 4-bar period, which is different than what you're asking for. Do appreciate that. (I'm not sure the 3.0 number is correct, but the units for slope should be in percentage/bar where the ROC indicator puts price into percentages.)
And this solution is not looking at the SMA of the price, although you could add that.
I don't do Blocks, but someone should be able to convert the approach below into Blocks for you.
CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { IndicatorBase pctChgOver4days; public override void Initialize(BarHistory bars) { pctChgOver4days = LRSlope.Series(ROC.Series(bars.Close, 1), 4); } public override void Execute(BarHistory bars, int idx) { if (HasOpenPosition(bars, PositionType.Long)) { //sell conditions below } else { //buy conditions below if (pctChgOver4days[idx] > 3.0) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } } } }
We could easily whip up that custom building block for you in a few hours work. If you’re interested email concierge@wealth-lab.com
Just to expand on the alternative linear regression approach, you can add a goodness-of-fit condition to your Buy operation with the WL RSquared indicator. The rSquared value is depicting how well the price gain over 4 bars follows the regression line; if it's perfect, 3% per day over 4 days, it will have a value of 1.0. I would let the WL parameter optimizer set the rSquared threshold to maximize your profit. Below, I have set it to 0.7 minimum in this example.
CODE:If you don't know statistics (and the rSquared behavior), get someone locally to help you that does. The more you know the more profit you can make. And it's more fun working with a local partner.
{ //buy conditions below if (pctChgOver4days[idx] > 3.0 && rSquared[idx] > 0.7) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); }
Hello,
thanks for the support and the solutions. Unfurtunatelly i can´t coding. So i have to do this with blocks.
@ superticker. I havn´t someone to interact with strategies. I learn a lot by thomas vittners billions college. But the most things i do it by myself.
So i hope, glitch will create a new building block.
And who knows, one day i will learn coding.
Regads
MaSto
thanks for the support and the solutions. Unfurtunatelly i can´t coding. So i have to do this with blocks.
@ superticker. I havn´t someone to interact with strategies. I learn a lot by thomas vittners billions college. But the most things i do it by myself.
So i hope, glitch will create a new building block.
And who knows, one day i will learn coding.
Regads
MaSto
QUOTE:
Unfortunately I can´t coding. So I have to do this with blocks.
The coded solutions I've given in Post #2 and Post #4 can be done with existing Blocks. There's nothing special about them. Ask someone to convert them to Blocks for you. (Or, since you're a Blocks programmer, you may be able to do it yourself.)
But I wouldn't apply methodology you don't understand. For example, the RSquared (regression correlation coefficient) is about how well the price model follows the linear regression line (LRSlope indicator). If you're not familiar with how that works, either look it up in a statistics book or don't use it. Never treat any methodology as a black box because every black box comes with certain assumptions that may not apply in some cases. Happy computing to you.
We should have a block for BarsSince. We'll get it done eventually, but as Glitch mentioned, the Concierge method is faster.
How do you envision a block for BarsSince would work? i think it would be easy to craft a customized block for this special case but I can’t see how a generalized BarsSince block would fit within the Blocks framework.
It's actually a simple block:
BarsSince (Indicator1 [comparer1] Indicator2) [comparer2] N bars
Example for above:
BarsSince (Close > MathIndOp (Close * 1.03)) <= 4 bars
Well, that's not exactly it, but if a delay were added here and there, we can get it.
BarsSince (Indicator1 [comparer1] Indicator2) [comparer2] N bars
Example for above:
BarsSince (Close > MathIndOp (Close * 1.03)) <= 4 bars
Well, that's not exactly it, but if a delay were added here and there, we can get it.
QUOTE:
BarsSince Close > MathIndOp (Close * 1.03) <= 4 bars
Doing this with C# code would be more intuitive and easier. :-)
I think there should be a Block to inject C# code in the Block framework whenever necessary. That would handle all the awkward cases.
Hello,
a friend of mine created a code. How can i import this code as a block.
Thanks
Markus
a friend of mine created a code. How can i import this code as a block.
Thanks
Markus
They can create a Buidling Block extension library, here is the API documentation:
https://www.wealth-lab.com/Support/ExtensionApi/BuildingBlock
https://www.wealth-lab.com/Support/ExtensionApi/BuildingBlock
Ok, thanks. We will try it.
Your Response
Post
Edit Post
Login is required