Script question: filling in a region between two DataSeries objects - futures io
futures io



Script question: filling in a region between two DataSeries objects


Discussion in NinjaTrader

Updated
    1. trending_up 228 views
    2. thumb_up 1 thanks given
    3. group 8 followers
    1. forum 4 posts
    2. attach_file 1 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 150,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Script question: filling in a region between two DataSeries objects

(login for full post details)
  #1 (permalink)
 trendisyourfriend 
Legendary Market Wizard
Quebec
 
Experience: Intermediate
Platform: NinjaTrader wt Rancho Dinero's profiling tools
Broker: AMP/CQG
Trading: ES, NQ, YM
 
trendisyourfriend's Avatar
 
Posts: 4,340 since Oct 2009
Thanks: 4,023 given, 5,724 received

Filling in a region between two DataSeries objects
---
I'd like to shade an area between 2 DataSeries objects such as 2 EMA's but would like to avoid keeping too many objects in memory to minimize the CPU usage.

My first thought was to first find the barindex on the left side of the visible portion of the chart and use a loop to re-draw the many regions from the left barindex up to the barindex to the right side or to the CurrentBar

I am looking for a short example how i could implement such a script. Any suggestion would be appreciated. Thanks.

Link to the Draw.Region

Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
Tradingview Phone Call Alert
Trading Reviews and Vendors
 
Best Threads (Most Thanked)
in the last 7 days on futures io
NinjaTrader Brokerage Services (www.ninjatraderbrokerage …
152 thanks
Big Mike in Ecuador
67 thanks
New NinjaTrader
41 thanks
Selling Options on Futures?
12 thanks
Gradient Color Bars
7 thanks
 
(login for full post details)
  #2 (permalink)
Philippe56140
Rennes, France
 
 
Posts: 5 since Dec 2021
Thanks: 0 given, 0 received

following

Reply With Quote
 
(login for full post details)
  #3 (permalink)
 trendisyourfriend 
Legendary Market Wizard
Quebec
 
Experience: Intermediate
Platform: NinjaTrader wt Rancho Dinero's profiling tools
Broker: AMP/CQG
Trading: ES, NQ, YM
 
trendisyourfriend's Avatar
 
Posts: 4,340 since Oct 2009
Thanks: 4,023 given, 5,724 received



Philippe56140 View Post
following

I Was able to script something usin the onrender method and a loop to draw the régions which correspond to the viewing area. This is much faster when the chart contains a lot of bars.

I'll post m'y script later.

Started this thread Reply With Quote
 
(login for full post details)
  #4 (permalink)
 trendisyourfriend 
Legendary Market Wizard
Quebec
 
Experience: Intermediate
Platform: NinjaTrader wt Rancho Dinero's profiling tools
Broker: AMP/CQG
Trading: ES, NQ, YM
 
trendisyourfriend's Avatar
 
Posts: 4,340 since Oct 2009
Thanks: 4,023 given, 5,724 received

This is the script i did in the onrender method:

This script will colorize the interior of a custom VWAP channel
between the 2nd lower band to the 2nd upper band.

I use a class wide variable 'leftmostBarIndex' to determine if the left most bar has changed to know if i need to redraw or not the region.

I also remove all previous regions using 'RemoveDrawObjects()' before proceeding.

If there is a better tactic then let me know.

draw_region

Started this thread Reply With Quote
 
(login for full post details)
  #5 (permalink)
 Fat Tails 
Legendary Market Wizard
Berlin, Europe
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,890 since Mar 2010
Thanks: 4,241 given, 26,982 received


trendisyourfriend View Post
Filling in a region between two DataSeries objects
---
I'd like to shade an area between 2 DataSeries objects such as 2 EMA's but would like to avoid keeping too many objects in memory to minimize the CPU usage.

My first thought was to first find the barindex on the left side of the visible portion of the chart and use a loop to re-draw the many regions from the left barindex up to the barindex to the right side or to the CurrentBar

I am looking for a short example how i could implement such a script. Any suggestion would be appreciated. Thanks.

Link to the Draw.Region


NinjaTrader creates draw objects that are loaded when an indicator is added to a chart. The process of adding an indicator can be painfully long if you have a high resolution chart with many draw objects.
However, once loaded these objects do not need to be recalculated for display, so they do not affect CPU too much when the indicator is running. It is just the pain adding them to the chart.

In order to shade the area between two moving averages you would use many slices of DrawRegion, but not use a new draw object for every bar.
When a new bar is added without triggering a MA cross, you would extend the shaded area to the right side. A new draw object is added after a MA cross.
Other than the inconvenient of the loading time, there is a visual problem. The color change will not align to the MA cross but to the last price bar prior to the cross leaving you with the color transition prior to the cross.

To avoid this problem, you will need to add a custom section for OnRender(). If you go to the download section, you will find the amaMultiMACross indicator (Multiple Moving Averages Crosses).
You may check the plot, as it colors the space between the moving averages.

In case you have further technical questions, please send me a private message.

Reply With Quote
The following user says Thank You to Fat Tails for this post:


futures io Trading Community Platforms and Indicators NinjaTrader > Script question: filling in a region between two DataSeries objects


Last Updated on March 13, 2023


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
     



Copyright © 2023 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
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.
no new posts