Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Hey Guys, Im having a common Trendfollower in place including MA Crossovers, that I want to write a simple MM code for. Here is my idea:
Instead of having...
I'd like to write a function with name "TradeSize", so that i can write...
This function is supposed to include a variable "RiskSize (1000)"
The tradesize function should then take the current share price into account, when all conditions are met and calculate the following...
...where IndicatorValue(Supertrend) is the current value of the Supertrend indicator!
Would be great, if one of you guys could give me some input in how a function like this can work out for me!
The Supertrend code is from BigMike himself and the code as well as pla-files can be found in this thread:
Does this logic sound reasonable to you?
Does it have any flaws?
Can you help me with which commands do I need for "mathround", "Currentshareprice" and the value of "Supertrend"?
What inputs and vars do I need to achieve this?
Thanks so much!
Can you help answer these questions from other members on NexusFi?
you seem well on track already with the written logic.
If you want Tradesize to be a function, I would suggest making RiskSize an input for it. I would also suggest instead of simply rounding the outcome, to make sure you only round down to the next full value. This will make sure that you always stay within your risk limits.
Big Mike already provided the function for the Supertrend, so you simply need to call it within your Tradesize function.
It can look something like this:
The code logic as it is has one serious problem that you probably want to avoid. When the difference between the last price and the Supertrend is very small, the Tradesize will become huge. This should be avoided with setting a maximum for the size. Another thing I noticed is that the Tradesize in general is quite large at least in my testing here on the @ES it seems so. Take a look at the outcome on a chart using the function within the Custom 1 Line indicator or place it into an indicator.
A huge TradeSize should not appear if you choose your RiskSize variable carefully, furthermore it depends on which parameters you choose for the Supertrend function and which timeframe you are running it.
If RiskSize is small, your timeframe is of larger scale and if your parameters for the Supertrend are higher than standard, your tradesize should be fine. My intention was to get a volatility adjusted TradeSize. Naturally, in some settings TradeSize will get kind of large and in others it will be smaller.
I tried to include that function in my Sample Strategy, would be great if you could take a look!
should include the variable and not the function name. You need to change TradeSize to vTradeSize. You also might want to use the number of contracts you entered with to be closed with your Exit Stop (or use "all contracts" there, too).
Other than that I didn't see anything at first glance. Although you could move the calculations from vTradeSize into the main part of the strategy. You are calling the Supertrend there already and with the function you'd call it twice now.
Can you explain what you mean by "Although you could move the calculations from vTradeSize into the main part of the strategy. You are calling the Supertrend there already and with the function you'd call it twice now."
I get an Error for calling the TradeSize function.
I meant you could change the part where you call the TradeSize function with this code from the function. You don't have to do this, I just saw that you are using the SuperTrend in the signal, too. So you could save one call by moving the size calculation to the signal directly and simply use the SuperTrend variable there.
Hi ABC, needed some time to resolve this. I managed to fix the Error problem.
Yes, the Supertrend is supposed to be in the signal too, don't know the exact role of it yet, its probably not used to be the sole criterion for entry, but switch maybe used as an exit or something. Im just tryin to rack up my EL-skills a little here.
thx for all ur support up to now, will definitly recommed you if I get a chance to!
I see, instead of using TradeSize as a function you mean I could put it into the signal directly.
Did I understand you correctly here?
What I'm wondering is, I will need to change input risksize on a regular basis manually, in order to reflect my money management preferences. Also Tradesize might also be used by different signals.
Another issue here is that if this signal is active on a regular basis, im wondering if I can get into any trouble with the strategy. What is going to happen if the signal has open positions and im going to double risksize? Am I right if I say that there is nothing happening to the current positions, but future positions will be larger? Is this any different if I change this input in TradeSize function or in the signal directly? Like if I change inputs in the signal-script, signal will go offline or something?
So what are the Advantages/Disadvantages of putting the Code into the signal, or keep it as a seperate function?
Yes, you understood it correctly the code could go directly into the signal, too.
It's no problem to change the trade size manually or to have the same signal on different charts with different settings.
However one thing you should note, in case you change things in the code or the inputs a running system will be switched off.