Announcement

Collapse
No announcement yet.

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 mtamaku, 10-12-2024, 09:44 AM
        1 response
        21 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by alchippe441, Today, 07:19 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by gig618, Yesterday, 10:34 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by several, 08-27-2024, 03:10 PM
        3 responses
        24 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by fingers, Today, 07:28 AM
        0 responses
        2 views
        0 likes
        Last Post fingers
        by fingers
         
        Working...
        X