• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SMA of equity curve

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

    SMA of equity curve

    hi,
    im tryng to build a strategy that it stops when the equity curve is below its SMA (21 period).The problem is that the strategy dont start to do trades. the code that i write for obtain this is. Can i get some help to run it? thanks in advance
    Code:
    protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0) 
                    return;
    
                if (CurrentBars[1] < 1
                || CurrentBars[2] < 1)
                return;
                
                myDoubleSeries[0] = SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit;
                
                if (SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit <= SMA(myDoubleSeries, 21))
                    
                
                {
                    
                    // Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
                    return;
                }

    #2
    Hello maxwellreturn,

    Welcome to the NinjaTrader Forum.

    In this situation, I would suggest using some Prints to find out whats going on. The platform comes with a debug window called the Output Window (New -> NinjaScript Output), this can be used to test parts of your code to find out problems or values being used.

    Because you said it places no trades, I would guess the logic to place the trades is not being called. I would also presume you have omitted that logic from your sample.

    From what you have provided, I would suggest adding some prints like the following:

    Code:
    protected override void OnBarUpdate()
            {
                Print("Bars In Progress: " + BarsInProgress + " CurrentBar: " + CurrentBar );
                if (BarsInProgress != 0) 
                    return;
    
                if (CurrentBars[1] < 1
                || CurrentBars[2] < 1)
                return;
                
                myDoubleSeries[0] = SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit;
                Print("myDoubleSeries[0]: " + myDoubleSeries[0] + " SMA(myDoubleSeries, 21)[0] " + SMA(myDoubleSeries, 21)[0]);
                if (SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit <= SMA(myDoubleSeries, 21))
                    
                
                {
                     Print("SystemPerformance condition met");
                    // Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
                    return;
                }
    This would print for each bar processed, and then the value of myDoubleSeries and also if the condition became true. If none of the prints happen, that may be a data problem. If some prints happen, this is likely a logical problem or problem in values being used.

    https://ninjatrader.com/support/foru...49&postcount=2

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      thank you jesse,

      i try to explain what i want to obtain; im trying to store the cum profit of a strategy in the series t for use it, for example, to obtain a SMA of the cum profit for money mangament purpose( trading the equity curve)

      the entire code that im using is this(im using print like you suggest to understand where is my error):
      Code:
      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.Indicators;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion
      
      //This namespace holds Strategies in this folder and is required. Do not change it. 
      namespace NinjaTrader.NinjaScript.Strategies
      {
          public class provareequity : Strategy
          {
              private SMA SMA1;
              private SMA SMA2;
              private double myDoubleSeries = 0;
              private Series<double> myDoubleSeries2;
              
      
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Strategy here.";
                      Name                                        = "provareequity";
                      Calculate                                    = Calculate.OnBarClose;
                      EntriesPerDirection                            = 1;
                      EntryHandling                                = EntryHandling.AllEntries;
                      IsExitOnSessionCloseStrategy                = true;
                      ExitOnSessionCloseSeconds                    = 30;
                      IsFillLimitOnTouch                            = false;
                      MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                      OrderFillResolution                            = OrderFillResolution.Standard;
                      Slippage                                    = 0;
                      StartBehavior                                = StartBehavior.WaitUntilFlat;
                      TimeInForce                                    = TimeInForce.Gtc;
                      TraceOrders                                    = false;
                      RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                      StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                      BarsRequiredToTrade                            = 20;
                      // Disable this property for performance gains in Strategy Analyzer optimizations
                      // See the Help Guide for additional information
                      IsInstantiatedOnEachOptimizationIteration    = true;
                  }
                  else if (State == State.Configure)
                  {
                      
                  }
                  else if (State == State.DataLoaded)
                  {                
                      SMA1                = SMA(Close, 14);
                      SMA2                = SMA(Close, 150);
                      myDoubleSeries2 = new Series<double>(this, MaximumBarsLookBack.Infinite);
                      
                  }
              }
      
              protected override void OnBarUpdate()
              {   Print("Bars In Progress: " + BarsInProgress + " CurrentBar: " + CurrentBar );
                  if (BarsInProgress != 0) 
                      return;
      
                  if (CurrentBars[0] < 1)
                  return;
                  
                  myDoubleSeries2[0] = SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit;
                  Print("mydoubleseries2:" + myDoubleSeries2);
                  
                  
                  
                  
                  // Set 1
                  if (CrossAbove(SMA1, SMA2, 1))
                  {
                      EnterLong(Convert.ToInt32(DefaultQuantity), "");
                  }
                  
                   // Set 2
                  if (CrossBelow(SMA1, SMA2, 1))
                  {
                      ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
                  }
                  
              }
          }
      }
      normally in the output i should see the value of cumprofit in the variable "myDoubleSeries2" but instead i see this:



      what should i do?
      Last edited by maxwellreturn; 12-27-2017, 09:41 AM.

      Comment


        #4
        Hello,

        Thank you for the reply.

        It looks like you are printing just the series and not the value, you need to specify a BarsAgo for a series:

        Code:
        Print("myDoubleSeries2[0]: " + myDoubleSeries2[0]);
        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ntbone, Today, 09:54 PM
        0 responses
        1 view
        0 likes
        Last Post ntbone
        by ntbone
         
        Started by rwilliam, Today, 03:14 PM
        0 responses
        5 views
        0 likes
        Last Post rwilliam  
        Started by rwilliam, Today, 03:10 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by rontronimous, Today, 03:04 PM
        2 responses
        8 views
        0 likes
        Last Post rontronimous  
        Started by zacharydw00, Today, 03:14 PM
        0 responses
        5 views
        0 likes
        Last Post zacharydw00  
        Working...
        X