NexusFi: Find Your Edge


Home Menu

 





Please help with simple line


Discussion in NinjaTrader

Updated
    1. trending_up 1,304 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Please help with simple line

  #1 (permalink)
 ReximusMaximus 
SAINT LOUIS
 
Experience: Advanced
Posts: 40 since Aug 2019
Thanks Given: 7
Thanks Received: 23

Hello traders,

After trying to pay three different freelance coders and purchasing a course on ninjascript, I still am at a loss. (The coders failed to provide code, and the course was for intermediate coders and did not explain even the basics)

I'm a full time discretionary trader, and have been in the markets for over a decade.

There was a period of time several years ago where I wrote and tested hundreds of EAs in MT4 using MQL4 so I felt that would be a reasonable prereq for coding ninjascript, but the resources for ninjascript are not beginner friendly like they are for MQL4.

Originally my project was to have an automated exit strategy for manually placed orders (placed in chart trader using hot keys). ES only, one trade at a time, intraday only.

I've received the advice on this forum to make an indicator that plots a line, then use the ATM strategy "thing/tool" (not sure what the terminology is as I'm new to ninja).

Does anyone have just a simple line or two of code they can share with me to plot a line? I tried using the wizard to create an indicator, and tried to use:

Draw.HorizontalLine(this, "tag1", 1000, Brushes.Black);

From the documentation.

But when I got the calculation for "Y" I started running into errors, which resulted in an error: "ninjascript must be in a compilable state to create or edit strategies"

I've been at this for nearly 8 hours and could really use a helping hand.

My goal is so simple, I just want a horizontal line to be plotted when these conditions are met:

- drop down menu to select variable: long/short
- variable the user can change: bodysize_minimum (ticks)
- variable the user change: stop_buffer (ticks)

for longs:

if close[1]>open[1] && close[1]-open[1] >= bodysize_minimum
then move the line (to be used as a trailing stop) to this location: low[1]-stop_buffer

The idea is to exit when a "strong" bar that closes in the direction of the current trade is broken.

The opposite would be true for shorts.

Does anyone have the time or inclination to share with me a very basic few lines of code?

I've never gotten any code in ninja to work, so if you could find it in your heart to explain how to use the code I'd be so grateful.

I feel like such an idiot to have to post this. Not only have I written and tested hundreds of EAs for MT4, but I've done so using they very easy easylanguage in tradestation, which was wonderful.

I'm considering just writing code and trading in tradestation, but I use the orderflow tools in ninja to make a living, and would love to start making progress in this platform, but it there is so much less learning material for NT.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
What is Markets Chat (markets.chat) real-time trading ro …
76 thanks
Spoo-nalysis ES e-mini futures S&P 500
55 thanks
Just another trading journal: PA, Wyckoff & Trends
37 thanks
Bigger Wins or Fewer Losses?
24 thanks
The Program
17 thanks
  #2 (permalink)
 hedgeplay 
Austin Texas / US
 
Experience: Intermediate
Frequency: Several times daily
Duration: Seconds
Posts: 176 since Dec 2019
Thanks Given: 145
Thanks Received: 211


ReximusMaximus View Post
Hello traders,

I'm a full time discretionary trader, and have been in the markets for over a decade.

Does anyone have just a simple line or two of code they can share with me to plot a line?

My goal is so simple, I just want a horizontal line to be plotted when these conditions are met:

- drop down menu to select variable: long/short
- variable the user can change: bodysize_minimum (ticks)
- variable the user change: stop_buffer (ticks)

for longs:
if close[1]>open[1] && close[1]-open[1] >= bodysize_minimum

I've never gotten any code in ninja to work, so if you could find it in your heart to explain how to use the code I'd be so grateful.

I written and tested hundreds of EAs for MT4, but I've done so using they very easy easylanguage in tradestation,

Hi,

I do not have much time but you have received thanks for posts you have made here so here are a few quick answers .

First a straightforward answer to a straightforward question.



Quoting 
Does anyone have just a simple line or two of code they can share with me to plot a line?

In NT8's Control Center click New and open a NinjScript Editor. Open the Indicators folder and open the CCI Indicator ...

More lines of code to create "lines" than you may really want.

AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameCCI);
AddLine(Brushes.DarkGray, 200, NinjaTrader.Custom.Resource.CCILevel2);
AddLine(Brushes.DarkGray, 100, NinjaTrader.Custom.Resource.CCILevel1);
AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine);
AddLine(Brushes.DarkGray, -100, NinjaTrader.Custom.Resource.CCILevelMinus1);
AddLine(Brushes.DarkGray, -200, NinjaTrader.Custom.Resource.CCILevelMinus2);



Learning Note... whenever you see something like "NinjaTrader.Custom.Resource.CCILevel2" in a OCS().SetDefaults that also means "replace this 'resource' with any text name you want in quotes..


E.g. swap "... , NinjaTrader.Custom.Resource.CCILevel2);"

for

" ... , "Finally my own darn line.");

Possible a more helpful answer is to check out this syntax.

"AddLine(new Stroke(Brushes.Yellow, DashStyleHelper.Solid, 2), PlotStyle.Line, "Yes!, Test & DataBox Title of a My own Powerful Line Construct");




------------------------
Another line ....


ReximusMaximus View Post
if close[1]>open[1] && close[1]-open[1] >= bodysize_minimum

Keyword here is TickSize. Tip: Use X times TickSize to handle any candle body size your after.

Assuming 'bodysize Min is 3X the Tick Size of the instrument ...

this compiles for me: if(Close[1] > Open[1] && ( Close[1] - Open[1] ) >= (TickSize * 3));

and.. if(Close[1] > Open[1] && ( Close[1] - Open[1] ) >= (TickSize * BodySize)); // "BodySize" being the public Property you configured for user input when attaching the indicator to the chart.


https://ninjatrader.com/support/helpGuides/nt8/?code_breaking_changes.htm


ReximusMaximus View Post

- drop down menu to select variable: long/short

Super easy. Open any / all Indicator and Strategy "Samples" provided in the default NT8 install and look at the #region near the bottom titled "Properties"





Bonus Answer:

The NT Support staff is unusually good / strong at helping people who are trying..

This approach typically gest a pretty good response..

1) A post here with I am trying to build this in the Builder.
2) Here is the *.cs code of what I have accomplished so far. ing and struggling
3) This is the specific next step I need help with.



Bonus Answer #2:

As 'chewy' as the builder can be using it to prototype will produce time saving code that shows exactly how NT8 expects you to code things.

... although if you have developed hundreds of EAs than maybe skip the Builder and look at provided "Samples' code references I provide in the links below.



Bonus Answer #3

Studying these examples is a great way to learn how to code so that Ninja likes your code and is a good source of ideas.

https://ninjatrader.com/support/helpGuides/nt8/?indicator2.htm
https://ninjatrader.com/support/helpGuides/nt8/?strategy2.htm




I gotta go.. Have fun!


HedgePlay

Reply With Quote
Thanked by:
  #3 (permalink)
 ReximusMaximus 
SAINT LOUIS
 
Experience: Advanced
Posts: 40 since Aug 2019
Thanks Given: 7
Thanks Received: 23



hedgeplay View Post
Hi,

I do not have much time but you have received thanks for posts you have made here so here are a few quick answers .

First a straightforward answer to a straightforward question.




In NT8's Control Center click New and open a NinjScript Editor. Open the Indicators folder and open the CCI Indicator ...

More lines of code to create "lines" than you may really want.

AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameCCI);
AddLine(Brushes.DarkGray, 200, NinjaTrader.Custom.Resource.CCILevel2);
AddLine(Brushes.DarkGray, 100, NinjaTrader.Custom.Resource.CCILevel1);
AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine);
AddLine(Brushes.DarkGray, -100, NinjaTrader.Custom.Resource.CCILevelMinus1);
AddLine(Brushes.DarkGray, -200, NinjaTrader.Custom.Resource.CCILevelMinus2);



Learning Note... whenever you see something like "NinjaTrader.Custom.Resource.CCILevel2" in a OCS().SetDefaults that also means "replace this 'resource' with any text name you want in quotes..


E.g. swap "... , NinjaTrader.Custom.Resource.CCILevel2);"

for

" ... , "Finally my own darn line.");

Possible a more helpful answer is to check out this syntax.

"AddLine(new Stroke(Brushes.Yellow, DashStyleHelper.Solid, 2), PlotStyle.Line, "Yes!, Test & DataBox Title of a My own Powerful Line Construct");




------------------------
Another line ....



Keyword here is TickSize. Tip: Use X times TickSize to handle any candle body size your after.

Assuming 'bodysize Min is 3X the Tick Size of the instrument ...

this compiles for me: if(Close[1] > Open[1] && ( Close[1] - Open[1] ) >= (TickSize * 3));

and.. if(Close[1] > Open[1] && ( Close[1] - Open[1] ) >= (TickSize * BodySize)); // "BodySize" being the public Property you configured for user input when attaching the indicator to the chart.


https://ninjatrader.com/support/helpGuides/nt8/?code_breaking_changes.htm



Super easy. Open any / all Indicator and Strategy "Samples" provided in the default NT8 install and look at the #region near the bottom titled "Properties"





Bonus Answer:

The NT Support staff is unusually good / strong at helping people who are trying..

This approach typically gest a pretty good response..

1) A post here with I am trying to build this in the Builder.
2) Here is the *.cs code of what I have accomplished so far. ing and struggling
3) This is the specific next step I need help with.



Bonus Answer #2:

As 'chewy' as the builder can be using it to prototype will produce time saving code that shows exactly how NT8 expects you to code things.

... although if you have developed hundreds of EAs than maybe skip the Builder and look at provided "Samples' code references I provide in the links below.



Bonus Answer #3

Studying these examples is a great way to learn how to code so that Ninja likes your code and is a good source of ideas.

https://ninjatrader.com/support/helpGuides/nt8/?indicator2.htm
https://ninjatrader.com/support/helpGuides/nt8/?strategy2.htm




I gotta go.. Have fun!


HedgePlay

Thank you, thank you, thank you!

Saving this and will be working through it piece by piece. I'll be sure to follow all of this advice.

Thanks again, and I'll be sure to pay it forward in my own way..

Started this thread Reply With Quote
  #4 (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,172 since Jan 2013
Thanks Given: 57,497
Thanks Received: 26,292


ReximusMaximus View Post
My goal is so simple, I just want a horizontal line to be plotted when these conditions are met:

- drop down menu to select variable: long/short
- variable the user can change: bodysize_minimum (ticks)
- variable the user change: stop_buffer (ticks)

for longs:

if close[1]>open[1] && close[1]-open[1] >= bodysize_minimum
then move the line (to be used as a trailing stop) to this location: low[1]-stop_buffer

The idea is to exit when a "strong" bar that closes in the direction of the current trade is broken.

The opposite would be true for shorts.

Does anyone have the time or inclination to share with me a very basic few lines of code?

I've never gotten any code in ninja to work, so if you could find it in your heart to explain how to use the code I'd be so grateful.

Hi @ReximusMaximus,

I can empathize with your difficulties. I think that to get this to work, you will need more than "a very basic few lines of code" -- not because this is going to be a hard thing for someone to do, but because you would first need to understand the structure of an NT indicator script, and basically how to write NT code in the first place. Since you have not had much success with NT scripts, I think that is where you would need to go first -- but this could get to be a big job, just to get a fairly simple script done.

I also think there is an easier way.

I suggest you make a post in the following thread, with a clear and simple explanation of what you are looking for. (The list of conditions you gave, plus an explanation of what it is supposed to do and how you will use it should do nicely.) Someone may be willing to just write the indicator for you based on your specification and your description of what you want it to do. Here's the thread:



It's been years since I did any NT coding and I'm no longer up on it, but there are many coders who watch that thread and who may be willing to help.

Since you ask about an indicator, I am suggesting the free indicator thread. If you want the code to automatically manage your entries or exits, then that would be, in NT-lingo, a "strategy," which is another breed of cat. But there would be some similarity in the code. There is also a free NT strategy thread, somewhat less used, because the tasks the code has to do are more involved. You can check this link as well:



If the indicator would satisfy what you need, you might want to try that first.

Just remember that clarity and simplicity is the way to get people to understand what you need and to get them to help. Let people know how you want to use it and see if it sparks some interest. Good trading ideas often do.

Good luck. I hope you get what you need.

Bob.

When one door closes, another opens.
-- Cervantes, Don Quixote
Reply With Quote
Thanked by:




Last Updated on July 5, 2021


© 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