Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Volumetric Bars method with Strategy

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

    Volumetric Bars method with Strategy

    Hello,

    i want to build a strategy based on the volumetric bars. I get the message that "The Name "bars.Type" is not available." Code CS0103

    // Short Set
    if (barsType.Volumes[CurrentBar].BarDelta < DeltaShortS)

    Somebody knows how to fix ist?

    #2
    Hello Lopat,

    Thank you for your post.

    Are the volumetric bars the primary bars in the series or an added data series? The sample script on the help guide page for Order Flow Volumetric bars demonstrates how to define the barsType as the volumetric bars:


    Keeping that sample in mind, you should be able to compile the following successfully (you may need to use the commented lines in the case that the volumetric bars are an added series and not the primary series):

    Code:
    protected override void OnBarUpdate()
    {
            if (Bars == null)
              return;
    
    
           // This sample assumes the Volumetric series is the primary DataSeries on the chart, if you would want to add a Volumetric series to a  
    
           // script, you could call AddVolumetric() in State.Configure and then for example use
           // NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = BarsArray[1].BarsType as
    
           // NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
    
    
    
            NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = Bars.BarsSeries.BarsType as    
            NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
    
            if (barsType == null)
              return;
    
    
            try
            {
              double price;
              Print("=========================================================================");
              Print("Bar: " + CurrentBar);
              Print("Delta for bar: " + barsType.Volumes[CurrentBar].BarDelta);
              if (barsType.Volumes[CurrentBar].BarDelta < DeltaShortS[INDENT=2]// do something[/INDENT]
             }
            catch{}
    }
    ​
    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hello Emily,

      thanks that helped. But i need some more help to debug. All of a sudden my strategy isnt working anymore. i get following error:

      Error on calling 'OnStateChange' mehtod: Index was outside the bounds of the array.

      But i didnt changed the method...

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Geben Sie hier die Beschreibung für die neue benutzerdefinierte Strategie.";
      Name = "VolumetricBarsV3";
      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;

      //Parameters
      DeltaLongS = -100;
      DeltaShortS = 100;
      TakeProfit = 100;
      StopLoss = 50;

      }​

      Comment


        #4
        Hello Lopat,

        Thank you for your reply.

        The snippet you have shared does not seem to indicate the cause of the error. In order to narrow down which part of your script is throwing the error, you could add Print() statements throughout your script. For example, if you add a print every few lines that prints the line number, you can see which print was the last to come up in the NinjaScript Output window before the error is thrown. This will help you to identify which lines of code are the cause and then you can work toward a solution to prevent the error. Here are some helpful links related to prints and debugging your script:Please let me know if I may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by lightsun47, Today, 03:51 PM
        0 responses
        4 views
        0 likes
        Last Post lightsun47  
        Started by 00nevest, Today, 02:27 PM
        1 response
        8 views
        0 likes
        Last Post 00nevest  
        Started by futtrader, 04-21-2024, 01:50 AM
        4 responses
        44 views
        0 likes
        Last Post futtrader  
        Started by Option Whisperer, Today, 09:55 AM
        1 response
        13 views
        0 likes
        Last Post bltdavid  
        Started by port119, Today, 02:43 PM
        0 responses
        8 views
        0 likes
        Last Post port119
        by port119
         
        Working...
        X