NexusFi: Find Your Edge


Home Menu

 





new stratergy help


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one benrock with 9 posts (1 thanks)
    2. looks_two NJAMC with 6 posts (3 thanks)
    3. looks_3 Big Mike with 2 posts (0 thanks)
    4. looks_4 NinjaTrader with 1 posts (0 thanks)
    1. trending_up 6,629 views
    2. thumb_up 5 thanks given
    3. group 2 followers
    1. forum 19 posts
    2. attach_file 1 attachments




 
Search this Thread

new stratergy help

  #11 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394


benrock View Post
im brand new to ninja , and i dont understand the inputs , can u recommend something ? i have the rest sorted out i think , just the inputs i need help with

thanks by the way

Okay,

I assume you are asking how to get the parameters from the dialog box to/from your strategy. The best thing to do is start downloading indicators and looking at how they work. I have to admit, NT doesn't document them well. You may also want to try the Strategy Wizard to have it setup the input parameters, then cut/paste those parts into your code. Also check out a few of the helper threads & webinars:


Here is an example of the UI code embedded within the code (Taken from RiskReward V2 Indie):

 
Code
        #region Properties
        [Category("Parameters")]
        [Description("Size of trading account in dollars")]
        [Gui.Design.DisplayNameAttribute("1. UserAcctSize")]
        public double UserAcctSize {
            get { return userAcctSize; }
            set { userAcctSize = Math.Max(0,value); }
        }

        [Category("Parameters")]
        [Description("Percent of Account to Risk per trade Ex: 2 is 2%")]
        [Gui.Design.DisplayNameAttribute("2. UserAcctRisk (%)")]
        public double UserAcctRisk {
            get { return userAcctRisk; }
            set { userAcctRisk = Math.Max(0,value); }
        }

        [Category("Parameters")]
        [Description("Dollar Account to Risk per trade Ex: 100 is $100")]
        [Gui.Design.DisplayNameAttribute("3. DollarRisk")]
        public double UserDollarRisk {
            get { return userDollarRisk; }
            set { userDollarRisk = Math.Max(0,value); }
        }

        [Category("Parameters")]
        [Description("Fixed Share/Contract Size")]
        [Gui.Design.DisplayNameAttribute("4. FixedPositionSize")]
        public int FixedShares {
            get { return fixedShares; }
            set { fixedShares = Math.Max(0,value); }
        }

        [Category("Parameters")] // Use of Category will hide it from parameter list
        [Description("Lots Type (For Forex only).")]
        [Gui.Design.DisplayNameAttribute("5. Lots Type")]
        public FXLotsType LotsType
        {
            get { return fxLotsType; }
            set { fxLotsType = value; }
        }

.... global variables removed.....
        #endregion
The parameter section holds the UI for NT. Take the "FixedShares" public variable above. Based upon the lines above, it is stored in the "Parameters" section of the UI, with the description in the next line, but has a specific display name in the UI box (without this last line you would see just the variable name). It is defined as an "int", it uses the private variable "fixedShares" (note the lowercase "f" rather than capital "F"). Upon opening the dialog box, "fixedShares" is loaded into the dialog box. Upon closing the "value" of the parameter is set back into the variable but will have a minimum value of 0 due to the Math.Max() statement.

Hope that give you a taste, hopefully that is what you are asking.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
Build trailing stop for micro index(s)
Psychology and Money Management
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
  #12 (permalink)
 benrock 
hampton bays
 
Experience: Master
Platform: ninjatrader , TOS
Broker: CQG
Trading: FUTURES
Posts: 85 since Mar 2012

heres the code i wrte but im not getting any results , can anyone help ?


#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>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class Trend3bar : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#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()
{
SetProfitTarget("", CalculationMode.Ticks, 2);
SetStopLoss("", CalculationMode.Ticks, 3, false);

CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < 3) return;
//rest of the codes

// Condition set 1
if (Close[0] > Close[1]
&& Close[1] == Close[2]
&& Close[2] == Close[3])
{
}
}

#region Properties
#endregion
}
}

Follow me on Twitter Started this thread Reply With Quote
  #13 (permalink)
 
kojava's Avatar
 kojava 
Orlando, FL
 
Experience: Advanced
Platform: NinjaTrader, ToS, Sierra Chart, MCDT
Broker: Interactive Brokers
Trading: ES, NQ, 6E, 6A, TF, CL
Posts: 43 since Jan 2011
Thanks Given: 53
Thanks Received: 29


I believe something like this is what you want.

 
Code
        protected override void OnBarUpdate()
        {
            if(CurrentBar < 4)
                return;

            // Sell condition
            if(Close[0] < Close[1] &&
               Close[1] < Close[2] &&
               Close[2] < Close[3])
            {
                DrawArrowDown("Down"+CurrentBar, true, 2, High[2]+TickSize, Color.Red);
            }
            
            // Buy condition
            if(Close[0] > Close[1] &&
               Close[1] > Close[2] &&
               Close[2] > Close[3])
            {
                DrawArrowUp("Up"+CurrentBar, true, 2, Low[2]-TickSize, Color.Green);
            }        
        }

Reply With Quote
Thanked by:
  #14 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,398 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,537


benrock View Post
heres the code i wrte but im not getting any results , can anyone help ?

You never EnterLong() or EnterShort() in that code, thus no entries.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #15 (permalink)
 
NinjaTrader's Avatar
 NinjaTrader  NinjaTrader is an official Site Sponsor
Site Sponsor

Web: NinjaTrader
AMA: Ask Me Anything
Webinars: NinjaTrader Webinars
Elite offer: Click here
 
Posts: 1,713 since May 2010
Thanks Given: 203
Thanks Received: 2,686

We posted a 30 minute learning NinjaScript video last week, it might be helpful?

NinjaTrader 7 Tips - Learn NinjaScript Tip #1 - YouTube

Follow me on Twitter Reply With Quote
  #16 (permalink)
 benrock 
hampton bays
 
Experience: Master
Platform: ninjatrader , TOS
Broker: CQG
Trading: FUTURES
Posts: 85 since Mar 2012

ok i got it to work but i want it to wait till a new up pr down trend before it trades again .

like this in tos --- see how it gives me a buy or sell signal

Attached Thumbnails
Click image for larger version

Name:	2012-04-05_1726.png
Views:	179
Size:	139.8 KB
ID:	69085  
Follow me on Twitter Started this thread Reply With Quote
  #17 (permalink)
 benrock 
hampton bays
 
Experience: Master
Platform: ninjatrader , TOS
Broker: CQG
Trading: FUTURES
Posts: 85 since Mar 2012

heres what i have so far but im not getting targets i want





#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>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class MyCustomStrategy : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#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()
{
SetProfitTarget("", CalculationMode.Ticks, 2);
SetStopLoss("", CalculationMode.Ticks, 3, false);

CalculateOnBarClose = true;
}
private bool isBuy = true;
private bool isSell = true;

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()


{if (CurrentBar < 3) return;
//rest of the codes

{
isBuy = false; //setting it to false makes sure there is no additional buys
isSell = true; //resets isSell so that buy orders can be taken
//rest of the buy order codes
}


{
isBuy = true; //resets buy so that buy orders can be taken
isSell = false; //set isSell to false so that no other sell is taken

//rest of the sell order codes
}
// Condition set 1
if (Close[0] > Close[1]
&& Close[1] > Close[2]
&& Close[2] == Close[3])
{
EnterLong(DefaultQuantity, "");
EnterShort(DefaultQuantity, "");
}
}

#region Properties
#endregion
}
}

Follow me on Twitter Started this thread Reply With Quote
  #18 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394


benrock View Post
heres what i have so far but im not getting targets i want





#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>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class MyCustomStrategy : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#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()
{
SetProfitTarget("", CalculationMode.Ticks, 2);
SetStopLoss("", CalculationMode.Ticks, 3, false);

CalculateOnBarClose = true;
}
private bool isBuy = true;
private bool isSell = true;

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()


{if (CurrentBar < 3) return;
//rest of the codes
You need a condition statement here or this block of code executes for each run
{
isBuy = false; //setting it to false makes sure there is no additional buys
isSell = true; //resets isSell so that buy orders can be taken
//rest of the buy order codes
}


You need a condition statement here or this block of code executes for each run, it ultimately resets the values from above the those you have listed below
{
isBuy = true; //resets buy so that buy orders can be taken
isSell = false; //set isSell to false so that no other sell is taken

//rest of the sell order codes
}
// Condition set 1
if (Close[0] > Close[1]
&& Close[1] > Close[2]
&& Close[2] == Close[3])
{
Do you mean if (isBuy)
EnterLong(DefaultQuantity, "");
and if (isSell)
EnterShort(DefaultQuantity, "");
}
}

#region Properties
#endregion
}
}

I put some notes in your code above to help get you closer. The last block tries to enter both a long and short at the same time. Not sure what happens in NT, net is 0 orders (buy then sell really fast), but I think one gets overwritten so you are likely to aways get a short or a long depend on the sequence.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #19 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,398 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,537


benrock View Post
heres what i have so far but im not getting targets i want

You need to learn some basics.

Watch the programming webinars on nexusfi.com (formerly BMT), there are several.

Check out the Battle of the Bots thread, there are many strategies there where you can read source code and learn the basics.

Check out some of the joint project strategies in this section of the forum:
Elite Automated Trading - Big Mike's Trading Forum

All will give you countless examples of the basics of a strategy.

Or, if this is important to you and/or time sensitive, hire someone to do it for you.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #20 (permalink)
 benrock 
hampton bays
 
Experience: Master
Platform: ninjatrader , TOS
Broker: CQG
Trading: FUTURES
Posts: 85 since Mar 2012


this is just me tring to learn and this is what support on the ninjatrader forum gave me to put in the code .

the best way to learn for me is to do it myself . practice and help , but thankyou

Follow me on Twitter Started this thread Reply With Quote




Last Updated on April 6, 2012


© 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