Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
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)
Updated August 26, 2013
Top Posters
looks_one
sagetrade
with 13 posts (0 thanks)
looks_two
dynoweb
with 7 posts (4 thanks)
looks_3
sam028
with 4 posts (1 thanks)
looks_4
Big Mike
with 3 posts (0 thanks)
Best Posters
looks_one
bd92154
with 1 thanks per post
looks_two
Nicolas11
with 1 thanks per post
looks_3
dynoweb
with 0.6 thanks per post
looks_4
sam028
with 0.3 thanks per post
trending_up
9,532 views
thumb_up
7 thanks given
group
6 followers
forum
32 posts
attach_file
3 attachments
August 10th, 2013, 10:06 AM
Frankfurt / Germany
Posts: 47 since Jul 2013
Thanks Given: 28
Thanks Received: 11
ok guys, thx for the support. Now fixed the error but having two new ones ;(
It tells me that vTradeSize has first to be specified and that operator "-" can not be used for
"if ((Close[0] - anaSuperTrendM11(1, 10, 5, false).StopDot[0]) != 0) "
Would be great if someone could take a look at my code below:
Quoting
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using
NinjaTrader .Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Hi This is My Description
/// </summary>
[Description("Hi This is My Description")]
public class SageTestStrat : Strategy
{
#region Variables
// Wizard generated variables
private int trueFalse = 1; // Default setting for TrueFalse
// User defined variables (add any user defined variables below)
private double RiskSize = 1000; // Risk Value
private double vTradeSize = 1; // TradeSize Value
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (anaSuperTrendM11(1, 10, 5, false).StopDot[1] > Close[1]
&& anaSuperTrendM11(1, 10, 5, false).StopDot[0] < Close[0])
{
TradeSize();
EnterLong((int)TradeSize, "Buy Long");
}
// Condition set 2
if (Position.Quantity > 0
&& anaSuperTrendM11(1, 10, 5, false).StopDot[1] < Close[1]
&& anaSuperTrendM11(1, 10, 5, false).StopDot[0] > Close[0])
{
ExitLong("Exit Long", "");
}
}
void TradeSize()
{
if ((Close[0] - anaSuperTrendM11(1, 10, 5, false).StopDot[0]) != 0)
{
vTradeSize = RiskSize / Math.Abs(Close[0] - anaSuperTrendM11(1, 10, 5, false).StopDot[0]);
}
else
{
vTradeSize = 0;
}
vTradeSize = Math.Floor(vTradeSize);
TradeSize = vTradeSize;
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int TrueFalse
{
get { return trueFalse; }
set { trueFalse = Math.Max(0, value); }
}
#endregion
}
}
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
August 10th, 2013, 10:35 AM
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629
Hmm, how did you get anaSuperTrendM11 , as downloads are only available for Elite members ?
Success requires no deodorant! (Sun Tzu)
August 10th, 2013, 10:57 AM
Frankfurt / Germany
Posts: 47 since Jul 2013
Thanks Given: 28
Thanks Received: 11
sam028
Hmm, how did you get anaSuperTrendM11 , as downloads are only available for Elite members ?
From the author himself.
Have you got an idea left on how to solve my code issue?
August 10th, 2013, 12:04 PM
McKinney, TX
Experience: Intermediate
Platform: ThinkOrSwim, NinjaTrader
Broker: TD Ameritrade (soon to be Schwab) & NinjaTrader
Trading: The indexes, ES, YM, NQ & RTY
Posts: 171 since Aug 2012
Thanks Given: 216
Thanks Received: 157
There are several problems with your code.
First your TradeSize method is not returning anything. So I changed it as shown below
int TradeSize()
{
double vTradeSize = 0;
if ((Close[0] - anaSuperTrendM11(1, 10, 5, false).StopDot[0]) != 0)
{
vTradeSize = RiskSize / Math.Abs(Close[0] - anaSuperTrendM11(1, 10, 5, false).StopDot[0]);
}
return (int) Math.Floor(vTradeSize);
}
You were using TradeSize "TradeSize = vTradeSize;" like a variable but it's the name of your function. My change returns the results of the calculation.
I changed your long code to use this function
if (anaSuperTrendM11(1, 10, 5, false).StopDot[1] > Close[1]
&& anaSuperTrendM11(1, 10, 5, false).StopDot[0] < Close[0])
{
EnterLong(TradeSize() , "Buy Long");
}
and I remove the double vTradeSize from your variable list.
August 11th, 2013, 08:52 AM
Frankfurt / Germany
Posts: 47 since Jul 2013
Thanks Given: 28
Thanks Received: 11
dynoweb
There are several problems with your code.
First your TradeSize method is not returning anything. So I changed it as shown below
int TradeSize()
{
double vTradeSize = 0;
if ((Close[0] - anaSuperTrendM11(1, 10, 5, false).StopDot[0]) != 0)
{
vTradeSize = RiskSize / Math.Abs(Close[0] - anaSuperTrendM11(1, 10, 5, false).StopDot[0]);
}
return (int) Math.Floor(vTradeSize);
}
You were using TradeSize "TradeSize = vTradeSize;" like a variable but it's the name of your function. My change returns the results of the calculation.
I changed your long code to use this function
if (anaSuperTrendM11(1, 10, 5, false).StopDot[1] > Close[1]
&& anaSuperTrendM11(1, 10, 5, false).StopDot[0] < Close[0])
{
EnterLong(TradeSize() , "Buy Long");
}
and I remove the double vTradeSize from your variable list.
thx dynoweb. I followed your steps, but it still won't compile :/
August 11th, 2013, 01:59 PM
near Paris, France
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769
Hi,
I suggest that you move the "return" line between current lines 74 and 75.
Nicolas
Sent from my mobile phone with Tapatalk
August 11th, 2013, 03:25 PM
Frankfurt / Germany
Posts: 47 since Jul 2013
Thanks Given: 28
Thanks Received: 11
Nicolas11
Hi,
I suggest that you move the "return" line between current lines 74 and 75.
Nicolas
Sent from my mobile phone with Tapatalk
thx so much guys - code compiled now.
I have however the problem that TradeSize is mysteriously high!
I have an example trade on the chart.
The calculation should be as follow:
Quoting
vTradeSize = RiskSize / Math.Abs(Close[0] - anaSuperTrendM11(1, 3, 10, false).StopDot[0]);
RiskSize / Floor(Close - Supertrend) = TradeSize
So the calculation for a RiskSize of 100 should be:
100 / (1345 - 1270) = 1
and for a RiskSize of 200 it should be:
200 / (1345 - 1270) = 2
However as can be seen on the chart, Contracts traded are 28 for a RiskSize of 100.
August 11th, 2013, 08:11 PM
Posts: 692 since Jun 2009
Thanks Given: 436
Thanks Received: 465
sagetrade
From the author himself.
Have you got an idea left on how to solve my code issue?
Since the author anaSuperTrendM11 is a good programmer and he is in your time zone, have you contacted him yet ?
Math. A gateway drug to reality.
August 12th, 2013, 07:08 AM
Frankfurt / Germany
Posts: 47 since Jul 2013
Thanks Given: 28
Thanks Received: 11
traderwerks
Since the author anaSuperTrendM11 is a good programmer and he is in your time zone, have you contacted him yet ?
first check if anyone else from the forum has help on this, before bothering admins!
August 14th, 2013, 12:32 PM
McKinney, TX
Experience: Intermediate
Platform: ThinkOrSwim, NinjaTrader
Broker: TD Ameritrade (soon to be Schwab) & NinjaTrader
Trading: The indexes, ES, YM, NQ & RTY
Posts: 171 since Aug 2012
Thanks Given: 216
Thanks Received: 157
Nicolas11
Hi,
I suggest that you move the "return" line between current lines 74 and 75.
Nicolas
Sent from my mobile phone with Tapatalk
Really you should have deleted lines 71-74 since they are after the return statement.
vTradeSize is a variable with a scope inside the TradeSize method. It's initialized to 0 so if that if condition doesn't run this method will return 0. If the if condition is true, the it will return the vtradeSize value of non-zero.
You can also print the values to be sure your calculations are as you expect, look in the console window for the output.
Print("Returning " + (int) Math.Floor(vTradeSize);
Return (int) Math.Floor(vTradeSize);
Rick
Last Updated on August 25, 2013