NexusFi: Find Your Edge


Home Menu

 





Script question: filling in a region between two DataSeries objects


Discussion in NinjaTrader

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




 
Search this Thread
  #1 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Legendary Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,580 since Oct 2009
Thanks Given: 4,266
Thanks Received: 6,199

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 NexusFi?
Hungary Called for Magyar at 97pct, Ending 16-Year Orban …
Prediction Markets & Event Contracts
Iran War Prediction Markets: Ceasefire 16%, Ground Invas …
Prediction Markets & Event Contracts
CPI Eve: Fed Hike Odds Hold at 52% for the First Time, I …
Prediction Markets & Event Contracts
SEC and CFTC Unlock Customer Cross-Margining for Treasur …
Treasury Notes and Bonds
NinjaTrader Parent Payward Acquires Bitnomial for $550M …
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
2026 Fire Horse
5 thanks
  #2 (permalink)
Philippe56140
Rennes, France
 
Posts: 13 since Dec 2021
Thanks Given: 0
Thanks Received: 2

following


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



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
  #4 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Legendary Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,580 since Oct 2009
Thanks Given: 4,266
Thanks Received: 6,199

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
  #5 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Futures & Stocks
Posts: 9,887 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,114


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
Thanked by:




Last Updated on March 13, 2023


© 2026 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 - Downloads - Top
no new posts