Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tick Replay and EMA

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • thegreattrader
    replied
    have you found a solution to this problem?

    Leave a comment:


  • SystemTrading
    replied
    Originally posted by NJA_MC View Post
    I see this line:
    if (CurrentBar < Math.Max(Len,activeBar)) return;


    But I don't see where "Len" is defined. Is this possible less than Length?
    Len should be Length. This is just an error in my post, in my code I am using:

    if (CurrentBar < Math.Max(Length,activeBar)) return;

    Leave a comment:


  • NJA_MC
    replied
    I see this line:
    if (CurrentBar < Math.Max(Len,activeBar)) return;


    But I don't see where "Len" is defined. Is this possible less than Length?

    Leave a comment:


  • SystemTrading
    replied


    My Trace Log also has the following:

    2015-06-09 12:18:08:955 *************** unhandled exception trapped ***************
    2015-06-09 12:18:08:955 Exception has been thrown by the target of an invocation.
    2015-06-09 12:18:08:958 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
    at NinjaTrader.NinjaScript.Indicators.MyTickIndicator .get_Zero()
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeIn ternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at System.Reflection.RuntimePropertyInfo.GetValue(Obj ect obj, Object[] index)
    at NinjaTrader.NinjaScript.IndicatorBase.get_DisplayN ame()
    at NinjaTrader.NinjaScript.IndicatorBase.OnAfterSetSt ate()
    at NinjaTrader.NinjaScript.NinjaScriptBase.SetState(S tate state)
    at NinjaTrader.Gui.NinjaScript.IndicatorRenderBase.Se tState(State state)
    at NinjaTrader.NinjaScript.NinjaScriptBase.SetState(S tate state)
    at NinjaTrader.Gui.NinjaScript.IndicatorRenderBase.Se tState(State state)
    at NinjaTrader.Gui.Chart.ChartControl.<>c__DisplayCla ss28e.<RefreshIndicators>b__27c(Object o)
    at System.Threading.ExecutionContext.RunInternal(Exec utionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.QueueUserWorkItemCallback.System. Threading.IThreadPoolWorkItem.ExecuteWorkItem()
    at System.Threading.ThreadPoolWorkQueue.Dispatch()
    Attached Files

    Leave a comment:


  • koganam
    replied
    Originally posted by SystemTrading View Post
    I tried that, but I get the same "Unhandled exception" error. I also tried calling the EMA's directly from the OnMarketData() method and got the same error.
    What is the text of the exception?

    Leave a comment:


  • SystemTrading
    replied
    I tried that, but I get the same "Unhandled exception" error. I also tried calling the EMA's directly from the OnMarketData() method and got the same error.

    Leave a comment:


  • NJA_MC
    replied
    I would try moving:
    emaUp = EMA(upticks,Length);
    emaDown = EMA(downticks,Length);

    Into a section State.DataLoaded...

    I think upticks & downticks are not valid yet (no data) which means they may be causing the EMA to crash.

    I do have to tell you I find debugging in NT8 more difficult as it may be the multitasking framework that seems to hide what is actually happening within the code.

    Leave a comment:


  • SystemTrading
    started a topic Tick Replay and EMA

    Tick Replay and EMA

    I am trying to create an indicator very similar to the BuySellPressure indicator to count UpTicks and DownTicks instead of BidVolume and AskVolume. The code works fine until I try to add an EMA of the UpTicks and DownTicks series I've created. Once I add the EMA, NinjaTrader crashes when I try to run the indicator.

    Code:
    Series<double> upticks, downticks;
            private int            activeBar        = -1;
            private double lastPrice = 0;
            private int lastDir = 0, up = 0, down = 0;
            private EMA emaUp, emaDown;
    
    protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Calculate                    = Calculate.OnEachTick;
                    IsOverlay                    = false;
                    DisplayInDataBox            = true;
                    DrawOnPricePanel            = true;
                    DrawHorizontalGridLines        = true;
                    DrawVerticalGridLines        = true;
                    PaintPriceMarkers            = true;
                    ScaleJustification            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive    = true;
                    Length                    = 4;
    
                    AddPlot(new Pen(Brushes.Red, 2), PlotStyle.Bar, "Plot1");
                    AddLine(Brushes.DarkGray, 1, "Line1");                          
                }
                else if (State == State.Configure)
                {
                    upticks = new Series<double>(this);
                    downticks = new Series<double>(this);
                    
                    emaUp = EMA(upticks,Length);
                    emaDown = EMA(downticks,Length);
                }
                else if (State == State.Historical)
                {
                    activeBar    = 0;
                }
            }
    
    protected override void OnMarketData(MarketDataEventArgs e)
            {
                try
                {
                    if (CurrentBar < Math.Max(Len,activeBar)) return;
    
                    if(e.MarketDataType == MarketDataType.Last)
                    {
                        if (lastPrice>0)
                        {
                            if (e.Price>lastPrice)
                            {
                                up++;
                                lastDir=1;
                            }
                            else if (e.Price<lastPrice)
                            {
                                down++;
                                lastDir=-1;
                            }
                            else
                            {
                                if (lastDir==1)
                                    up++;
                                else if (lastDir==-1)
                                    down++;
                            }
                        }
                        
                        upticks[0]=up;
                        downticks[0]=down;
                        
                        Plot1[0] = emaUp[0]-emaDown[0];                    
                        
                        lastPrice = e.Price;
                    }
                }
                catch(Exception ex)
                {
                    Log(ex.ToString(),LogLevel.Error);
                }
            }
    
    protected override void OnBarUpdate()
            {
                if (CurrentBar < activeBar)
                    return;
    
                if(CurrentBar != activeBar)
                {
                    up = 0;
                    down = 0;
                    activeBar    = CurrentBar;
                }
            }

Latest Posts

Collapse

Topics Statistics Last Post
Started by CarlTrading, 03-30-2026, 11:51 AM
0 responses
27 views
0 likes
Last Post CarlTrading  
Started by CarlTrading, 03-30-2026, 11:48 AM
0 responses
26 views
0 likes
Last Post CarlTrading  
Started by CaptainJack, 03-25-2026, 09:53 PM
0 responses
30 views
0 likes
Last Post CaptainJack  
Started by CaptainJack, 03-25-2026, 09:51 PM
0 responses
18 views
0 likes
Last Post CaptainJack  
Started by Mindset, 03-23-2026, 11:13 AM
0 responses
29 views
0 likes
Last Post Mindset
by Mindset
 
Working...
X