NexusFi: Find Your Edge


Home Menu

 





Compiling Error (Statement Expected)


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one sagetrade with 13 posts (0 thanks)
    2. looks_two dynoweb with 7 posts (4 thanks)
    3. looks_3 sam028 with 4 posts (1 thanks)
    4. looks_4 Big Mike with 3 posts (0 thanks)
      Best Posters
    1. looks_one Nicolas11 with 1 thanks per post
    2. looks_two bd92154 with 1 thanks per post
    3. looks_3 dynoweb with 0.6 thanks per post
    4. looks_4 sam028 with 0.3 thanks per post
    1. trending_up 8,527 views
    2. thumb_up 7 thanks given
    3. group 6 followers
    1. forum 32 posts
    2. attach_file 3 attachments




 
Search this Thread

Compiling Error (Statement Expected)

  #11 (permalink)
sagetrade
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
}
}


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Are there any eval firms that allow you to sink to your …
Traders Hideout
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #12 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
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)
Follow me on Twitter Reply With Quote
  #13 (permalink)
sagetrade
Frankfurt / Germany
 
Posts: 47 since Jul 2013
Thanks Given: 28
Thanks Received: 11



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

Reply With Quote
  #14 (permalink)
 dynoweb 
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.

Follow me on Twitter Reply With Quote
Thanked by:
  #15 (permalink)
sagetrade
Frankfurt / Germany
 
Posts: 47 since Jul 2013
Thanks Given: 28
Thanks Received: 11


dynoweb View Post
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 :/


Reply With Quote
  #16 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
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

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #17 (permalink)
sagetrade
Frankfurt / Germany
 
Posts: 47 since Jul 2013
Thanks Given: 28
Thanks Received: 11


Nicolas11 View Post
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.


Reply With Quote
  #18 (permalink)
 traderwerks   is a Vendor
 
Posts: 692 since Jun 2009
Thanks Given: 436
Thanks Received: 465


sagetrade View Post
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.
Reply With Quote
  #19 (permalink)
sagetrade
Frankfurt / Germany
 
Posts: 47 since Jul 2013
Thanks Given: 28
Thanks Received: 11


traderwerks View Post
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!

Reply With Quote
  #20 (permalink)
 dynoweb 
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 View Post
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

Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on August 25, 2013


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts