NexusFi: Find Your Edge


Home Menu

 





Very simple code


Discussion in NinjaTrader

Updated
    1. trending_up 1,589 views
    2. thumb_up 4 thanks given
    3. group 3 followers
    1. forum 6 posts
    2. attach_file 4 attachments




 
Search this Thread

Very simple code

  #1 (permalink)
 Impeesa 
Salamanca/Spain
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ, CL
Posts: 5 since Jun 2014
Thanks Given: 7
Thanks Received: 1

Hello

I am just a beginner programming codes and I need some help.

As you can see in jpeg attached, I have created a very simple strategy.

DeltaHigh of a bar > 75, then EntryShortLimit + 4 ticks in next bar
DeltaLow of a bar < -75, then EntryLongLimit - 4 ticks in next bar

But orders are launched one bar later instead just the bar after the conditions are met.
Can somebody please have a look at the strategy file zip and tell me what line of code is wrong and what is the right way?

Thanks a lot

Attached Thumbnails
Click image for larger version

Name:	17_09_2020_1918.jpg
Views:	138
Size:	152.0 KB
ID:	305097  
Attached Files
Elite Membership required to download: DeltaSample.zip
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
TopStepX from TST
Platforms and Indicators
What broker to use for trading palladium futures
Commodities
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Strategy stop orders partially filled
EasyLanguage Programming
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Funded Trader platforms
57 thanks
Trading with Intuition
16 thanks
Self sabotage reframed
15 thanks
Joes Trading Garage
13 thanks
Just another trading journal: PA, Wyckoff & Trends
13 thanks
  #2 (permalink)
 
AllSeeker's Avatar
 AllSeeker 
Mumbai, India
Legendary Pratik_4Clover
 
Experience: Beginner
Platform: TradingView & ZerodhaKite
Trading: NIFTY, BANKNIFTY
Frequency: Daily
Duration: Minutes
Posts: 1,430 since Jan 2019
Thanks Given: 5,255
Thanks Received: 5,024

From what I understood from that is to meet the condition bar needs to close, then only the system registers it as a "bar" and tallies the condition.

Basically your conditions won't be complete till bar is closed and naturally your response (order) for condition meeting will be on the next bar from the one where your condition has met.

/Just explaining the general programing logic, I don't code on NT, so maybe they have some way to lookahead this little technicality.

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #3 (permalink)
userque
Chicago IL
 
Posts: 180 since Apr 2016
Thanks Given: 573
Thanks Received: 130


Hi, check out this link to the NinjaTrader forum:

https://forum.ninjatrader.com/forum/ninjatrader-8/strategy-development/96317-enterlong-is-delayed-by-1-bar

You can use these Google search terms to find more, if you need them:

ninjatrader one bar late

Short answer: It won't wait 'till the next bar during live trading, and;

There are also ways to make it not wait while backtesting.

Reply With Quote
Thanked by:
  #4 (permalink)
 Impeesa 
Salamanca/Spain
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ, CL
Posts: 5 since Jun 2014
Thanks Given: 7
Thanks Received: 1

This issue happens with CumulativeDelta Ninjatrader indicator, but not with others like Volume, as you can see in screenshots attached.

CumulativeDelta indicator in strategy is delayed one bar from "Real" CumulativeDelta Indicator...

It does not happen when strategy is calculated OnEachTick, but in that situation, orders are launched during the trigger bar and not at close...

Any idea?

Attached Thumbnails
Click image for larger version

Name:	18_09_2020_0957.jpg
Views:	100
Size:	80.9 KB
ID:	305110   Click image for larger version

Name:	18_09_2020_0952.jpg
Views:	92
Size:	78.3 KB
ID:	305111  
Started this thread Reply With Quote
  #5 (permalink)
userque
Chicago IL
 
Posts: 180 since Apr 2016
Thanks Given: 573
Thanks Received: 130


Impeesa View Post
...Any idea?

Ninjatrader Customer support explains it nicely here:

https://forum.ninjatrader.com/forum/ninjatrader-8/platform-technical-support-aa/100663-calculate-both-on-bar-close-and-each-tick

The short:

Keep using calculate on each tick; but also use IsFirstTickOfBar.

Reply With Quote
Thanked by:
  #6 (permalink)
 Impeesa 
Salamanca/Spain
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, NQ, CL
Posts: 5 since Jun 2014
Thanks Given: 7
Thanks Received: 1

Thanks. I had read that but it when I used IsFirstTickOfBar it didn't work as expected, neither OnBarClose (entries one bar later) nor OnEachTick (entries during trigger bar)

Started this thread Reply With Quote
  #7 (permalink)
userque
Chicago IL
 
Posts: 180 since Apr 2016
Thanks Given: 573
Thanks Received: 130


Impeesa View Post
Thanks. I had read that but it when I used IsFirstTickOfBar it didn't work as expected, neither OnBarClose (entries one bar later) nor OnEachTick (entries during trigger bar)

It can be very tricky to wrap your brain around the different numbering schemes, and closed bars vs. open; and off-by-one bugs. I've spent many hours debugging those sorts of things in just one complicated strategy.

I deal more with strategies than indicators; but maybe try asking in the NT forum. You may even need to send them your logs and/or code.

Sounds like it can be done with the items already mentioned, but for some pesky bug in your code.

Keep us posted if you get it squared away.

Reply With Quote
Thanked by:




Last Updated on September 18, 2020


© 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