My MM / PositionSize Code - EasyLanguage Programming | futures io social day trading
futures io futures trading


My MM / PositionSize Code
Updated: Views / Replies:1,451 / 10
Created: by sagetrade Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

My MM / PositionSize Code

  #1 (permalink)
Trading Apprentice
Frankfurt / Germany
 
Futures Experience: Intermediate
Platform: NT, MC
Favorite Futures: Stocks, Futures
 
sagetrade's Avatar
 
Posts: 47 since Jul 2013
Thanks: 28 given, 10 received

My MM / PositionSize Code

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

Quoting 
Buy ("Enter Long") 3 Contracts Next Bar At Market;

I'd like to write a function with name "TradeSize", so that i can write...

Quoting 
Buy ("Enter Long") TradeSize Contracts Next Bar At Market;

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

Quoting 
mathround(TradeSize) = RiskSize / (SharePrice - IndicatorValue(Supertrend))

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


Last edited by sagetrade; July 31st, 2013 at 06:52 PM.
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,527 since Apr 2013
Thanks: 229 given, 854 received
Forum Reputation: Legendary


Hi sagetrade,

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:

 
Code
Inputs: 
	RiskSize			(NumericSimple),
	ATRLength			(NumericSimple), 
	ATRMult			(NumericSimple), 
	Strength			(NumericSimple);
	
Variables:
	vSTrend			(0),
	vTradeSize			(0),
	vSuperTrend			(0);

//call the supertrend function
vSuperTrend = SuperTrend(ATRLength, ATRMult, Strength, vSTrend);

//the Close - vSuperTrend <> 0 check avoids division by zero errors	
if Close - vSuperTrend <> 0 then	
	vTradeSize = RiskSize / AbsValue(Close - vSuperTrend)
else
	vTradeSize = 0; {you should change this value to whatever you want to use for the size in cases the last price is equal to the supertrend}
	
//round to the next lowest value
vTradeSize = Floor(vTradeSize);

//TradeSize is the name of the function, if you use a different name, you need to change TradeSize to this name
TradeSize = vTradeSize;
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.

Regards,
ABCTG

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #4 (permalink)
Trading Apprentice
Frankfurt / Germany
 
Futures Experience: Intermediate
Platform: NT, MC
Favorite Futures: Stocks, Futures
 
sagetrade's Avatar
 
Posts: 47 since Jul 2013
Thanks: 28 given, 10 received

Thank you so much, ABCTG!

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!


Quoting 

// Sage Test Strategy 15.07.2013

Inputs:

smalength ( 200 ),
emalength ( 50 ),
ATRLength ( 10 ),
ATRMult ( 3 ),
Strength ( 10 ),
RiskSize ( 100 );

Variables:

smav ( 0 ),
emav ( 0 ),
vSTrend ( 0 ),
vSuperTrend ( 0 ),
vTradeSize ( 0 ),
st1 ( 0 );

// Call MAs
smav = Average(Close, smalength);
emav = XAverage(Close, emalength);

// Call Supertrend
vSuperTrend = Supertrend(ATRLength, ATRMult, Strength, vSTrend);

// Call Tradesize
vTradeSize = TradeSize(RiskSize, ATRLength, ATRMult, Strength, vStrend);

// Open new positions (Long Only)

if marketposition = 0 then begin // Only open new positions if flat

if close > vSuperTrend then begin // Checks if Supertrend is below price action

end;

// EMA crosses Above SMA & Both Rising
if emav crosses above smav and smav > smav[1] and emav > emav[1] and emav > smav then begin // If SMAV and EMAV are rising and cross
Buy ("Enter Long") vTradeSize Contracts Next Bar At Market;

end;

end;

// Send Initial SL Order

if marketposition = 1 then begin // Checks if positions are opened (Long)
st1 = vSuperTrend;
Sell ("Exit Stop") all Contracts Next Bar At st1 Stop; //Close open positions

end;

// Close existing positions

if marketposition = 1 then begin //Checks if positions are opened

if close < vSuperTrend then begin //If supertrend switches from green to red
Sell ("Exit Regular") all Contracts next Bar At Close; //Closes open positions

end;
end;



Last edited by sagetrade; August 4th, 2013 at 06:20 PM.
Reply With Quote
 
  #5 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,527 since Apr 2013
Thanks: 229 given, 854 received
Forum Reputation: Legendary

You are welcome. The line
 
Code
Buy ("Enter Long") TradeSize Contracts Next Bar At Market;
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.

Regards,
ABCTG

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #6 (permalink)
Trading Apprentice
Frankfurt / Germany
 
Futures Experience: Intermediate
Platform: NT, MC
Favorite Futures: Stocks, Futures
 
sagetrade's Avatar
 
Posts: 47 since Jul 2013
Thanks: 28 given, 10 received

Thanx ABCTG,

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.


Last edited by sagetrade; August 4th, 2013 at 06:25 PM.
Reply With Quote
 
  #7 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,527 since Apr 2013
Thanks: 229 given, 854 received
Forum Reputation: Legendary

What is the error message you are getting?

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.


 
Code
//the Close - vSuperTrend <> 0 check avoids division by zero errors	
if Close - vSuperTrend <> 0 then	
	vTradeSize = RiskSize / AbsValue(Close - vSuperTrend)
else
	vTradeSize = 0; {you should change this value to whatever you want to use for the size in cases the last price is equal to the supertrend}
	
//round to the next lowest value
vTradeSize = Floor(vTradeSize);
Regards,
ABCTG

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #8 (permalink)
Trading Apprentice
Frankfurt / Germany
 
Futures Experience: Intermediate
Platform: NT, MC
Favorite Futures: Stocks, Futures
 
sagetrade's Avatar
 
Posts: 47 since Jul 2013
Thanks: 28 given, 10 received

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?

thx Sage


Last edited by sagetrade; August 9th, 2013 at 11:31 AM.
Reply With Quote
 
  #9 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,527 since Apr 2013
Thanks: 229 given, 854 received
Forum Reputation: Legendary

You are welcome.

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.

Regards,
ABCTG


sagetrade View Post
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?

thx Sage


Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #10 (permalink)
Trading Apprentice
Frankfurt / Germany
 
Futures Experience: Intermediate
Platform: NT, MC
Favorite Futures: Stocks, Futures
 
sagetrade's Avatar
 
Posts: 47 since Jul 2013
Thanks: 28 given, 10 received



ABCTG View Post
You are welcome.

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.

Regards,
ABCTG

Can I avoid the system being switched off, if I keep TradeSize as a seperate function and just change the input in there?

Can MC sync open positions if I change RiskSize, system is switched off and I switch it on again?

Reply With Quote

Reply



futures io > > > > > My MM / PositionSize Code

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can someone help me w/ this code calhawk01 NinjaTrader Programming 5 June 4th, 2013 09:42 PM
what does this code mean? ticker NinjaTrader Programming 2 April 11th, 2013 02:56 AM
need a coder to code new NT7 indi from existing MT4 indi - I have source code traderdp Hire a Consultant or Programmer 0 January 31st, 2013 09:21 PM
Better Momentum's "code #" I Lost...r all code #'s same ? xm4730 ?? Billbb Platforms and Indicators 2 January 26th, 2012 07:15 PM
Can someone code this ? skyfly NinjaTrader Programming 8 April 25th, 2011 01:40 PM


All times are GMT -4. The time now is 04:09 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-12 in 0.15 seconds with 19 queries on phoenix via your IP 54.163.210.170