NexusFi: Find Your Edge


Home Menu

 





Learning Ninjascript - Start Here


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one StoxFox with 2 posts (1 thanks)
    2. looks_two mntrader with 2 posts (1 thanks)
    3. looks_3 Zondor with 1 posts (6 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
      Best Posters
    1. looks_one Zondor with 6 thanks per post
    2. looks_two trendisyourfriend with 2 thanks per post
    3. looks_3 StoxFox with 0.5 thanks per post
    4. looks_4 mntrader with 0.5 thanks per post
    1. trending_up 2,253 views
    2. thumb_up 10 thanks given
    3. group 6 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

Learning Ninjascript - Start Here

  #1 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: Ninjatrader®
Broker: CQG, Kinetick
Trading: Gameplay Klownbine® Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,731

Ninjascript is a customized version of the Microsoft® C# object oriented programming language.

With a good foundation in the C# language, learning Ninjascript is relatively easy.
This looks like a particularly good introductory course.
Understandable, but not watered down.

ZetCode C# tutorial

"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote

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
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #3 (permalink)
 
mntrader's Avatar
 mntrader 
Vienna, Austria
 
Experience: Beginner
Platform: NinjaTrader
Trading: NQ, ES
Posts: 13 since Jul 2023
Thanks Given: 9
Thanks Received: 3


Thank you for posting this C# course! I already started doing code academy C# course and would like to deepen my knowledge.

I'd be curious if you know any YouTubers that do a lot of coding examples/stuff on NinjaScript. I've found a couple of ones, but you might have some names in your mind.

Thank you!

Reply With Quote
  #4 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,171
Thanks Received: 6,018


mntrader View Post
Thank you for posting this C# course! I already started doing code academy C# course and would like to deepen my knowledge.

I'd be curious if you know any YouTubers that do a lot of coding examples/stuff on NinjaScript. I've found a couple of ones, but you might have some names in your mind.

Thank you!

The Ninjatrader support forum is the best place to ask questions:
https://forum.ninjatrader.com/

Next, Google. If you have a question about a command just type:
ninjatrader 'your question'
ex.: ninjatrader exitlong

Next, ChatGPT:
ex.:
in C#, how would you remove the first char of a string but keep the remaining ?

In C#, you can remove the first character of a string and keep the remaining characters by using the Substring method. Here's an example:
 
Code
string input = "Hello";
string output = input.Substring(1);

Console.WriteLine(output); // "ello"
Another example:
Me:
Create a strategy in C Sharp for Ninjatrader to go long only when price crosses a moving average. Just write the relevant code that goes into the method OnBarUpdate()

ChatGPT
Sure, here's an example strategy in C# for NinjaTrader that goes long (buys) when the price crosses above a simple moving average (SMA). This code should be placed within the OnBarUpdate() method of your strategy class:

 
Code
protected override void OnBarUpdate()
{
    // Define the parameters for the strategy
    int period = 20; // Period of the moving average
    double threshold = 0.001; // Price threshold for crossing

    // Calculate the moving average
    double smaValue = SMA(period)[0];

    // Check for a cross above condition
    if (CrossAbove(Close, smaValue, 1) && Close[0] > smaValue + threshold)
    {
        // Place a long (buy) order
        EnterLong("LongEntry");
    }
}
In this example, the strategy calculates a simple moving average (SMA) with a specified period (20 bars in this case). It then checks if the current bar's close price crosses above the SMA and is also above the SMA plus a small threshold value. If both conditions are met, it places a long (buy) order using the EnterLong method.

Please note that this is a basic example, and you might want to enhance it further with additional risk management, position sizing, and other trading logic to create a more comprehensive trading strategy. Also, make sure to thoroughly backtest any strategy before deploying it in a live trading environment.
You can refine your request if you see something wrong:
Ex.
About the threshold variable, my chart symbol is the NQ futures contract, the minimum movement is 1 tick so modify this variable to use tick offset instead.

 
Code
protected override void OnBarUpdate()
{
    // Define the parameters for the strategy
    int period = 20; // Period of the moving average
    int tickOffset = 2; // Number of ticks above the moving average for entry

    // Calculate the moving average
    double smaValue = SMA(period)[0];

    // Calculate the tick size for the instrument
    double tickSize = TickSize;
    
    // Calculate the threshold in price terms
    double threshold = smaValue + tickOffset * tickSize;

    // Check for a cross above condition
    if (CrossAbove(Close, smaValue, 1) && Close[0] > threshold)
    {
        // Place a long (buy) order
        EnterLong("LongEntry");
    }
}
In this modified version, the tickOffset variable determines how many ticks above the moving average the current price needs to be in order to trigger a long entry. The TickSize property gives you the tick size of the instrument you're trading. The threshold is calculated as the moving average plus the tick offset multiplied by the tick size.

Make sure to adjust the tickOffset value according to your trading preferences and strategies.

---
Use the Strategy Builder and unlock the code and study it.

Reply With Quote
Thanked by:
  #5 (permalink)
 
mntrader's Avatar
 mntrader 
Vienna, Austria
 
Experience: Beginner
Platform: NinjaTrader
Trading: NQ, ES
Posts: 13 since Jul 2023
Thanks Given: 9
Thanks Received: 3

trendisyourfriend, this is super helpful! Thank you for sharing these suggestions, and code examples.

Reply With Quote
Thanked by:
  #6 (permalink)
 
StoxFox's Avatar
 StoxFox 
N. California
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ, CL
Posts: 36 since Oct 2019
Thanks Given: 8
Thanks Received: 36

I hope I'm not breaking any rules by posting a link that contains something for sale. I'm not affiliated with the author of this book:

NinjaScript Launch Pad

This is a claim right on their front page:


Quoting 
NinjaScript Programmer's Launch Pad was selected by the NinjaScript Technical Support team at NinjaTrader® to train existing Tech Support members on how to troubleshoot NinjaScript related inquiries.


Reply With Quote
Thanked by:
  #7 (permalink)
 
bobwest's Avatar
 bobwest 
Western Florida
Site Moderator
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,162 since Jan 2013
Thanks Given: 57,341
Thanks Received: 26,267


StoxFox View Post
I hope I'm not breaking any rules by posting a link that contains something for sale. I'm not affiliated with the author of this book:

NinjaScript Launch Pad

No problem.

You are not breaking any rule unless you are selling your own stuff. If you are recommending someone else's material that you've found to be good, then you are just doing the right thing by letting others know about it.

Bob.

When one door closes, another opens.
-- Cervantes, Don Quixote
Reply With Quote
  #8 (permalink)
 
StoxFox's Avatar
 StoxFox 
N. California
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ, CL
Posts: 36 since Oct 2019
Thanks Given: 8
Thanks Received: 36

Thank you for the clarification. I'm going to keep this in mind going forward, because I sometimes come across stuff that really helps with trading.

Reply With Quote




Last Updated on August 9, 2023


© 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