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

Access Values of Indicator

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

    Access Values of Indicator

    Hi,

    i'm trying to build my first strategy. I want to use the values of the BuySellVolume indicator, but it seems like the DataSeries from the indicator are empty.
    No trade entry happens with this strategy....

    The code looks like this:


    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class DeltaRatioKursDivergenz : Strategy
    {

    private BuySellVolume bsv;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Wenn Delta positiv, long gehen";
    Name = "DeltaRatioKursDivergenz";

    // 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)
    {
    bsv = BuySellVolume();
    AddChartIndicator(bsv);
    }
    }

    protected override void OnBarUpdate()
    {
    if (bsv.Sells[0] > 0){
    EnterLong();
    }
    }
    }
    }

    Could you please help me with this? Thank you.

    Kind regars,
    Malte

    #2
    Welcome to the forums Tasse555!

    BuySellVolume relies on OnMarketData and will not generate historical plots unless Tick Replay is used. The indicator also sets plot values after the bar has been processed, so it may not be best for designing a strategy.

    I have attached a different version of this indicator that uses a Multi Time Frame approach which would not use Tick Replay. There can be slight differences when ticks are received with the same timestamp, but in general, this sort of script would be better suited for use in a strategy. To use it in the Strategy Builder, you will need to add a single tick data series to the Additional Data Page of the Strategy Builder.

    We look forward to assisting.

    (Update 2023.01.10 - resetting volume to 0 on new bar)

    BuySellVolumeOneTickExample_NT8.zip
    Last edited by NinjaTrader_ChelseaB; 01-10-2023, 12:27 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,

      thank you for the example. But this also does not work. I'm using TickReplay and the Indicator shows the correct values (both indicator do), but the strategy does not trigger any Long-trade. (That is my simple strategy approach, to see, if the strategy works with the indicator)


      This is how i use your example indicator:
      <code>
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class MyCustomStrategy1 : Strategy
      {

      private BuySellVolumeOneTick bsv;

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

      BuySellVolumeOneTick().Calculate = Calculate.OnEachTick;
      }
      else if (State == State.Configure)
      {
      }
      }

      protected override void OnBarUpdate()
      {
      if (State == State.Historical || BuySellVolumeOneTick().SellVolume[0] > 30){
      EnterLong();
      }
      }
      }
      }
      </code>

      Kind regards

      Comment


        #4
        Hello Tasse555,

        Thanks for your post.

        Below is a video demonstrating that the indicator is properly getting read, and logic can be built with this indicator. When I use the indicator to control a condition which controls my EnterLong method, I can see my logic is becoming true and allowing the order method to be reached.

        Demo - https://drive.google.com/file/d/1C9A...w?usp=drivesdk

        I have also included additional videos debugging tips with the Strategy Builder. These steps would be taken to confirm that your order submission logic is allowing your order submission methods to be reached.

        Debugging in the Strategy Builder - https://drive.google.com/file/d/1mTq...w?usp=drivesdk

        Debugging Demo - https://drive.google.com/file/d/1rOz...w?usp=drivesdk

        We look forward to assisting.
        Last edited by NinjaTrader_Jim; 05-18-2020, 08:42 AM.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by geddyisodin, 04-25-2024, 05:20 AM
        8 responses
        60 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by jxs_xrj, 01-12-2020, 09:49 AM
        4 responses
        3,285 views
        1 like
        Last Post jgualdronc  
        Started by Option Whisperer, Today, 09:55 AM
        0 responses
        5 views
        0 likes
        Last Post Option Whisperer  
        Started by halgo_boulder, 04-20-2024, 08:44 AM
        2 responses
        22 views
        0 likes
        Last Post halgo_boulder  
        Started by mishhh, 05-25-2010, 08:54 AM
        19 responses
        6,189 views
        0 likes
        Last Post rene69851  
        Working...
        X