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()
            {
                [B]Print("Bars In Progress: " + BarsInProgress + " CurrentBar: " + CurrentBar );[/B]
                if (BarsInProgress != 0) 
                    return;
    
                if (CurrentBars[1] < 1
                || CurrentBars[2] < 1)
                return;
                
                myDoubleSeries[0] = SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit;
                [B]Print("myDoubleSeries[0]: " + myDoubleSeries[0] + " SMA(myDoubleSeries, 21)[0] " + SMA(myDoubleSeries, 21)[0]);[/B]
                if (SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit <= SMA(myDoubleSeries, 21))
                    
                
                {
                     [B]Print("SystemPerformance condition met");[/B]
                    // 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.



    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, 10: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[B][0][/B]: " + myDoubleSeries2[B][0][/B]);
        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by andrewtrades, Today, 04:57 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X