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

Check Barcolour & Indicatorvalue

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

    Check Barcolour & Indicatorvalue

    Hello again,

    as not a programmer its not easy to realize a "simple" Strategy. So i have 2 Questions

    1. I create an Indicator who plots my CandleOutlineBrushes[0] = Brushes.XY; (different Colours). Can i check the last 10 Bars, if they are White or Yellow? Like this
    Code:
    if (ShortSignal && ShortCounter < 2)
    {
       if (Check last 10 Bars if one or more white or yellow)
          Counter + 1;
      else
          EnterShort();
          Counter +1;
    }
    In the picture below you can see that i have 6 Shortentry`s. But only SE 1 & 2 are Valid. SE3 & 4 have a white/yellow bar in the last 10 Bars and SE5 & 6 are not Valid because the EntryCounter > 2.

    2. I have a second Indicator Name: namespace NinjaTrader.NinjaScript.Indicators._Dira / public class _DiraVolume3 : Indicator. In this Indicator i set public double _DiraVollasthighVol;
    ​And now i want the Value of _DiraVollasthighVol in my Strategy.

    Code:
    i try this
    
    double try1 = _DiraVolume3._DiraVollasthighVol;
    But it will not work. How ican realize it?

    Last edited by Dirales; 05-14-2023, 04:33 AM.

    #2
    What you probably want to do, to make this simpler, is to add a Series output to the indicator you made that does the candle outline color, so that that indicator has a very simple way to tell the strategy if the candle is white or yellow. You could make two Series<bool> outputs like IsBarWhite[] and IsBarYellow[] or you could add a single int-type output that is something like BarClassification[] where 0 = everything else, 1 = white, 2 = yellow. You mention you are not a programmer, but you've come this far - you can probably do this - just keep reading the help and searching the forums and you'll find lots of good examples for how to do these sorts of things. Adding the output to the indicator will make it simpler to use this information with Strategy Builder or with a simple strategy because you can then refer to MyIndicator.IsBarWhite[0] to see if the current bar is white, etc.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      I found "SampleBoolSeries", Import the Indicator and try to understand the concept behind them. Without success i try any way i know
      I make a new Strategy and want the BearIndication

      Can u say, whats wrong with my approach?

      Code:
      namespace NinjaTrader.NinjaScript.Strategies
      {
          public class Try1 : Strategy
          {
              private SampleBoolSeries try1;
      
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Strategy here.";
                      Name                                        = "Try1";
                      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)
                  {
                      try1 = SampleBoolSeries.BearIndication[0];
                  }
              }
      
              protected override void OnBarUpdate()
              {
                  //Add your custom strategy logic here.
                  try1 = SampleBoolSeries.BearIndication[0];
              }
          }
      }​
      Allways the same error: SampleBoolSerie() is Method and cant be use...
      Last edited by Dirales; 05-14-2023, 07:37 AM.

      Comment


        #4
        Hello Dirales,

        Thanks for your post.

        The try1 variable in your script would need to be instantiated first before calling BearIndication or BullIndication.

        Create the class-level try1 SampleBoolSeries variable in your script as you have done.
        Code:
        private SampleBoolSeries try1;
        In State.DataLoaded, you would instantiate the variable by calling try1 = SampleBoolSeries();
        Code:
        else if (State == State.DataLoaded)
        {
            try1 = SampleBoolSeries();
        }​
        Then, in OnBarUpdate() you could use the try1 variable for conditions in your script.
        Code:
        protected override void OnBarUpdate()
        {
            //Add your custom strategy logic here.
            if (try1.BearIndication[0] == true)
            {
                Print("BearIndication true");
            }
        }​
        You could consider creating some simple conditions using indicator plots in the Strategy Builder and clicking the 'View code' button to get an idea of how to instantiate indicators in State.DataLoaded() and then use those variables within a strategy.

        Strategy Builder-Creating indicator to value comparisons: https://ninjatrader.com/support/help...lueComparisons

        Please let me know if I may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hello QuantKey_Bruce & BrandonH,

          many thanks for your help. Now iam understand the Concept.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by StockTrader88, 03-06-2021, 08:58 AM
          45 responses
          3,992 views
          3 likes
          Last Post johntraderuser2  
          Started by TAJTrades, Today, 09:46 AM
          0 responses
          7 views
          0 likes
          Last Post TAJTrades  
          Started by rhyminkevin, Yesterday, 04:58 PM
          5 responses
          62 views
          0 likes
          Last Post dp8282
          by dp8282
           
          Started by realblubb, Today, 09:28 AM
          0 responses
          8 views
          0 likes
          Last Post realblubb  
          Started by AaronKoRn, Yesterday, 09:49 PM
          1 response
          19 views
          0 likes
          Last Post Rikazkhan007  
          Working...
          X