How to access the previous value of an indicator? (MC.NET) - MultiCharts | futures io social day trading
futures io futures trading


How to access the previous value of an indicator? (MC.NET)
Updated: Views / Replies:913 / 8
Created: by Jeffrey Attachments:0

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

How to access the previous value of an indicator? (MC.NET)

  #1 (permalink)
Elite Member
Hong Kong
 
Futures Experience: Beginner
Platform: MultiCharts, NinjaTrader
Favorite Futures: HSIF, ES
 
Posts: 10 since Jul 2010
Thanks: 2 given, 1 received

How to access the previous value of an indicator? (MC.NET)

 
Code
public class New_ATR : IndicatorObject {
      
      [Input]
      public int period { get; set; }
      
      private double trueRange;
      private double averageTrueRange;
      
      private IPlotObject plot1;
      
      public New_ATR(object _ctx):
      base(_ctx){
      
         // default 14 days
         period = 14;         
      }
      
      protected override void Create() {
         // create variable objects, function objects, plot objects etc.
         plot1 = AddPlot(new PlotAttributes("ATR", EPlotShapes.Line, Color.Cyan, Color.Empty, 0, 0, true));
      }
      
      protected override void StartCalc() {
         // assign inputs
      }
      protected override void CalcBar(){
         
         // calculate the value of first bar
         if (Bars.CurrentBar == 0) {            
             trueRange = Bars.High[0] - Bars.Low[0];
            plot1.Set(0, trueRange);
         }
         else {
            // logic from NT7
            //double trueRange = High[0] - Low[0];
            //trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1])));
            //Value.Set(((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period));
            
            trueRange = Bars.High[0] - Bars.Low[0];            
            trueRange = Math.Max(Bars.Low[0] - Bars.Close[1], Math.Max(trueRange, Math.Abs(Bars.High[0] - Bars.Close[1])));
            
            averageTrueRange = ((Math.Min(Bars.CurrentBar + 1, period) - 1 ) * ?????? + trueRange) / Math.Min(Bars.CurrentBar + 1, period);
            
            plot1.Set(0, averageTrueRange);
         }
      }
   }
Say i am on the 2nd bar of the daily series, I want to access the variable of trueRange of first bar so that I can calculate the average of two days. How can I do this?

Is it possible to store the indicator value of current bar into a array so that I have a series of values that I can read anytime? Cheers.

Reply With Quote
 
  #2 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,533 since Apr 2013
Thanks: 231 given, 855 received
Forum Reputation: Legendary

Hi Jeffrey,

either compute the truerange for the particular bar again or store the result into a VariableSeries variable. Then you can reference previous values.

4.5 Functions and Special Variables - MultiCharts

Regards,
ABCTG

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #3 (permalink)
Elite Member
Hong Kong
 
Futures Experience: Beginner
Platform: MultiCharts, NinjaTrader
Favorite Futures: HSIF, ES
 
Posts: 10 since Jul 2010
Thanks: 2 given, 1 received



ABCTG View Post
Hi Jeffrey,

either compute the truerange for the particular bar again or store the result into a VariableSeries variable. Then you can reference previous values.

4.5 Functions and Special Variables - MultiCharts

Regards,
ABCTG

Thanks for the swirl response. Let's say I follow this to set the value into the array

 
Code
using System;
 
namespace PowerLanguage.Indicator
{
    public class ITest : IndicatorObject
    {
        private VariableSeries<Double> m_plotVal;
        private IPlotObject Plot1;
 
        public ITest(object ctx) : base(ctx)
        {
            length = 10;
        }
 
        [Input]
        public int length { get; set; }
 
        protected override void Create()
        {
            Plot1 = AddPlot(new PlotAttributes("Test"));
            m_plotVal = new VariableSeries<Double>(this);
        }
 
        protected override void CalcBar() {
            m_plotVal.Value = Bars.Close[length] - Bars.CloseValue;
            Plot1.Set(0, m_plotVal.Value);
        }
    }
}
How can I read the value of previous bar from the from the VariableSeries? I can't find a good example to show me this...Appreciated if you can shed some light!

Reply With Quote
 
  #4 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,533 since Apr 2013
Thanks: 231 given, 855 received
Forum Reputation: Legendary

Jeffrey,

the same as you do it for the Close. In the code you posted m_plotVal[X], where X is the bar you want to go back (0 = Currentbar).

Regards,
ABCTG

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #5 (permalink)
Elite Member
Jacksonville, Florida United States
 
Futures Experience: Intermediate
Platform: NT8, Fully custom
Broker/Data: NT Brokerage, Interactive Brokers
Favorite Futures: ES
 
Jasonnator's Avatar
 
Posts: 69 since Dec 2014
Thanks: 19 given, 44 received

I have noticed that if I try to go pretty far back in the data series, I need to use Bars.FullSymbolData.Close[x]. I'm less than 1 week on MC so I'm not exactly sure why this is. I think it may have something to do with maximum number of bars (ExecInfo.MaxBarsBack) an indicator can see by default.

Reply With Quote
 
  #6 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,533 since Apr 2013
Thanks: 231 given, 855 received
Forum Reputation: Legendary

Jasonnator,

you are correct. By default the first bar on the chart for a study is the first bar after the maximum number of bars you set for your study to reference. This is done in order to ensure all values are probably computed.

Regards,
ABCTG


Jasonnator View Post
I have noticed that if I try to go pretty far back in the data series, I need to use Bars.FullSymbolData.Close[x]. I'm less than 1 week on MC so I'm not exactly sure why this is. I think it may have something to do with maximum number of bars (ExecInfo.MaxBarsBack) an indicator can see by default.


Reply With Quote
 
  #7 (permalink)
Elite Member
Jacksonville, Florida United States
 
Futures Experience: Intermediate
Platform: NT8, Fully custom
Broker/Data: NT Brokerage, Interactive Brokers
Favorite Futures: ES
 
Jasonnator's Avatar
 
Posts: 69 since Dec 2014
Thanks: 19 given, 44 received

@ABCTG
Just to clarify, if MaxBarsBack = 300, then Bars.Close[0] is still the current bar but it's the same as Bars.FullSymbolData.Close[299] in terms of all bars on the chart? That would mean the the far right bar is always MaxBarsBack...

Reply With Quote
 
  #8 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,533 since Apr 2013
Thanks: 231 given, 855 received
Forum Reputation: Legendary

Jasonnator,

bar 0 will always be the current bar. Bars.Close[1] and Bars.FullSymbolData.Close[1] both return the bar to the left of the current bar. The only difference is that Bars.Close[x] is limited by the Max bars back setting and Bars.FullSymbolData is not.

Regards,
ABCTG

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #9 (permalink)
Elite Member
Jacksonville, Florida United States
 
Futures Experience: Intermediate
Platform: NT8, Fully custom
Broker/Data: NT Brokerage, Interactive Brokers
Favorite Futures: ES
 
Jasonnator's Avatar
 
Posts: 69 since Dec 2014
Thanks: 19 given, 44 received

Gotcha, thanks

Reply With Quote

Reply



futures io > > > > How to access the previous value of an indicator? (MC.NET)

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
MC.Net Email Alert DonB4x MultiCharts 1 December 3rd, 2014 06:11 PM
Multicharts or MC.NET indicator to save bar data into a MySQL/MS SQL Server database? andby MultiCharts 3 October 13th, 2014 03:37 PM
stochastic rsi MC.net seacat MultiCharts 0 August 20th, 2014 08:44 AM
[MC.Net] Using ExecControl.Recalculate() Outside of Indicator Class dkhenkin MultiCharts 0 June 14th, 2013 12:26 AM
MC NET gparkis MultiCharts 3 September 20th, 2012 02:34 PM


All times are GMT -4. The time now is 02:42 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, 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
Page generated 2017-12-18 in 0.12 seconds with 19 queries on phoenix via your IP 54.92.194.75