NexusFi: Find Your Edge


Home Menu

 





newbe programmer question


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one eurostoxx with 6 posts (0 thanks)
    2. looks_two Big Mike with 3 posts (1 thanks)
    3. looks_3 Saroj with 2 posts (0 thanks)
    4. looks_4 roonius with 1 posts (0 thanks)
    1. trending_up 4,157 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 13 posts
    2. attach_file 0 attachments




 
Search this Thread

newbe programmer question

  #1 (permalink)
 eurostoxx 
T. Dot
 
Experience: Advanced
Platform: TT
Trading: FESX
Posts: 16 since Oct 2009
Thanks Given: 1
Thanks Received: 0

Hi
I am trying to write a Ninja Script code for a very simple strategy but it is taking me forever to figure it out and I think I need some help Basically the strategy is time dependant
1st part
When the time is between 9:30 – 10:30
If the low of the 1min candles is always above the 10 EMA, then condition 1 = True
Else if the high of the 1min candles is always below the 10 EMA, then codition 2 = Ture

2nd part
When the time is greater than 11:30
If condition 1 was true and now the low <= the 10 ema, then buy
If condition 2 was true and now the high >= the 10 ema, then sell
If have coded it in NT, but obviously I am doing something wrong,

Here is my code, any help would be greatly appreciated… I think I am off somewhere regarding my initial condions…
if (ToTime(Time[0]) > ToTime(9,30,00) && ToTime(Time[0]) < ToTime(10,30,00))
{
if (Low[60] > EMA(14)[0])
{
condition1 = true;
}
else if (High[60] < EMA(14)[0])
{
condition3 = true;
}

}

if (tradecounter < 4)

{
if (condition1 = true
&& ToTime(Time[0]) >= ToTime(11,30,00)
&& Low[0] < EMA(14)[0])
{
DrawDot("My dot" + CurrentBar, false, 0, 0, Color.Blue);
Alert("MyAlert0", Priority.High, "", "", 0, Color.White, Color.Black);
EnterLong(DefaultQuantity, "");
tradecounter++;
}

else if (condition3 = true
&& ToTime(Time[0]) >= ToTime(11,30,00)
&& High[0] > EMA(14)[0])
{
DrawDot("My dot" + CurrentBar, false, 0, 0, Color.Blue);
Alert("MyAlert0", Priority.High, "", "", 0, Color.White, Color.Black);
EnterShort(DefaultQuantity, "");
tradecounter++;
}
}

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Exit Strategy
NinjaTrader
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
Deepmoney LLM
Elite Quantitative GenAI/LLM
 
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
  #2 (permalink)
 
sefstrat's Avatar
 sefstrat 
Austin, TX
 
Experience: Advanced
Platform: NT/Matlab
Broker: Interactive Brokers
Trading: FX majors
Posts: 285 since Jun 2009
Thanks Given: 20
Thanks Received: 768

The only thing blatant I see:

if (condition1 = true

should be

if (condition1 == true

Reply With Quote
  #3 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629



sefstrat View Post
The only thing blatant I see:

if (condition1 = true

should be

if (condition1 == true

Or
 
Code
                            
if (condition1) {... 


Follow me on Twitter Reply With Quote
  #4 (permalink)
 eurostoxx 
T. Dot
 
Experience: Advanced
Platform: TT
Trading: FESX
Posts: 16 since Oct 2009
Thanks Given: 1
Thanks Received: 0

will it mater if condition 1 is a bool variable.. i thought I could just write "true" ,,,I thought the problem was that I didnt not get the coding right for the

if the low of the last 60 mins was above the 14 period EMA (as in the lows of the 1min candles never touched the EMA line in the past hour) - in ninja trader is written as

if (ToTime(Time[0]) > ToTime(9,30,00) && ToTime(Time[0]) < ToTime(10,30,00))
{
if (Low[60] > EMA(14)[0])

Started this thread Reply With Quote
  #5 (permalink)
 eurostoxx 
T. Dot
 
Experience: Advanced
Platform: TT
Trading: FESX
Posts: 16 since Oct 2009
Thanks Given: 1
Thanks Received: 0

thanks for the reply's btw... really appreciated

Started this thread Reply With Quote
  #6 (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,396 since Jun 2009
Thanks Given: 33,172
Thanks Received: 101,536

Low[60] is not the low of the last sixty minutes. Also, unless you've included something like
 
Code
                            
if (CurrentBar 60) return; 

Then using Low[60] is going to throw an error anyway for an out of bounds index. You need to be reviewing the Log tab of the control center for errors, if this strategy has compiled successfully but is not working as expected.

If you are using a 1-minute bar, low[60] is the low of the bar 60 minutes ago.

You need to use MIN(Low, 60)[0] to find out what the low is over the last 60 bars.

Also, you need to either post the exact error message you are receiving upon compiling (bottom of the screen), or you need to post the .cs file itself. I (we) can not really help otherwise because we don't know what the error is.

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
Thanked by:
  #7 (permalink)
 eurostoxx 
T. Dot
 
Experience: Advanced
Platform: TT
Trading: FESX
Posts: 16 since Oct 2009
Thanks Given: 1
Thanks Received: 0

thanks for the reply mike,

I am not getting any errors in the log tab, but as you suggested I am getting errors in the execution of the strategy.

I am trying to write a script for:
If the low of all the 1-min candles > the moving average (the value of the MA corresponding to that time the low was made) then xxx = true

visually, it would look like a trending market. If the market was always trading above (or below) the moving average over a certain time period then xx = true

any ideas on how to code this

the MIN(Low, 60)[0] function would almost work except i wouldnt know what to compare it against,


Thanks again

Started this thread Reply With Quote
  #8 (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,396 since Jun 2009
Thanks Given: 33,172
Thanks Received: 101,536

MIN(Low, 60)[0] will return the lowest Low value in the last 60 bars.

int _lowbar = LowestBar(Low, 60); will return the bar number the low was made on.

if (MIN(Low, 60)[0] > EMA(20)[_lowbar]) will check to see if the Low (price) is higher than the EMA(20) of [xx bars ago when the low was made].

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
  #9 (permalink)
 eurostoxx 
T. Dot
 
Experience: Advanced
Platform: TT
Trading: FESX
Posts: 16 since Oct 2009
Thanks Given: 1
Thanks Received: 0

bam! thanks

PS any ideas where I can learn all the C# little stuff like the int_lowbar ... do you know if it is on the ninja site somewhere? I find stuff a little disorganized on Help function sometimes

thanks again

Started this thread Reply With Quote
  #10 (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,396 since Jun 2009
Thanks Given: 33,172
Thanks Received: 101,536


int just means integer, and _lowbar is a variable name. it could be "int _iamsleepy" etc.

I suggest any C# "for dummies" book to cover basic principles, most of which apply to NinjaTrader directly, and then from there to learn NinjaScript specific commands, either read the help site cover-to-cover or just dissect all the code you can find and go line by line to understand it.

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




Last Updated on October 21, 2009


© 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