NexusFi: Find Your Edge


Home Menu

 





Resetting a variable at a designated time


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Fat Tails with 2 posts (3 thanks)
    2. looks_two cory with 1 posts (1 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 RonKiker with 1 posts (0 thanks)
    1. trending_up 1,642 views
    2. thumb_up 4 thanks given
    3. group 4 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Resetting a variable at a designated time

  #1 (permalink)
 RonKiker 
Birmingham, AL
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, YM, NQ
Posts: 34 since Apr 2012
Thanks Given: 17
Thanks Received: 23

I have an On Balance Volume indicator that keeps a running tally of volume. I want to reset the total to 0 at a designated time, say 1:00am. Can someone give me some advice on how to code this?

Here is the current code:

 
Code
protected override void OnBarUpdate()
        {
            // Set the initial plot value to 0 on the first bar
	if (CurrentBar == 0)
	    Value.Set(0);
			
	else
	    Value.Set(Value[1] + (UpDownTradeVolumeNV().UpVolume[0] - 
                    UpDownTradeVolumeNV().DownVolume[0]));
         }
Thanks,
Ron

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
REcommedations for programming help
Sierra Chart
Quant vue
Trading Reviews and Vendors
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
What is Markets Chat (markets.chat) real-time trading ro …
72 thanks
Spoo-nalysis ES e-mini futures S&P 500
55 thanks
Just another trading journal: PA, Wyckoff & Trends
27 thanks
Bigger Wins or Fewer Losses?
24 thanks
The Program
16 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


You could try something like this:

 
Code
protected override void OnBarUpdate()
{
    // Set the initial plot value for the first bar of each session
    if (Bars.FirstBarOfSession)
       Value.Set( (UpDownTradeVolumeNV().UpVolume[0] - 
             UpDownTradeVolumeNV().DownVolume[0]));
			
   else
       Value.Set(Value[1] + (UpDownTradeVolumeNV().UpVolume[0] - 
             UpDownTradeVolumeNV().DownVolume[0]));
}


Not sure that it will work, as you have only shared a fraction of your code.

Reply With Quote
  #4 (permalink)
 
1LotTrader's Avatar
 1LotTrader 
Douglas, United Kingdom
 
Experience: Advanced
Platform: Custom
Trading: Bund
Posts: 181 since Jun 2009
Thanks Given: 206
Thanks Received: 445

if ((Time[0].Hour == 1) && (Time[0].Minute== 0) && (Time[0].Second == 0))
Print("Do something");


Make sure your bar series actually breaks at 1:00am or it will skip over.

Follow me on Twitter Reply With Quote
  #5 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090

use "<" or ">" against the time mark then.

Reply With Quote
Thanked by:
  #6 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


cory View Post
use "<" or ">" against the time mark then.

Or to be more accurate:

-> for charts built from ticks (tick, volume, range, renko) use ">=" or "<="
-> for minute or second charts use ">" or "<"

The reason here is that a minute bar with a time stamp 1:00:00 AM covers the minute prior to 1:00:00 AM, while a tick bar - or volume, range or renko bar - with a time stamp 1:00:00 AM covers a period after 1:00:00 AM.

Reply With Quote
Thanked by:




Last Updated on August 27, 2013


© 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