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

Using bool to link indicators

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

    Using bool to link indicators

    Hello,
    I have 2 indicators, Indicator A (has some calculations above or below certain bars), and Indicator B (has some arrow signals above or below certain bars). I have set up a BoolSeries in Indicator B so that when an arrow signal occurs on a bar, false changes to yes. This is a summary of the additional code in indicatorB (all code additions are in bold):

    Code:
    {
            #region Variables
    
    			[B]private BoolSeries arrowup1;[/B]
    		#endregion
    }
    
            protected override void Initialize()
            {
                	Overlay				= true;
    			CalculateOnBarClose = true;
    			/* "this" syncs the BoolSeries to the historical bar object of the indicator. It will generate one bool value for eveery price bar. */
    			[B]arrowup1 = new BoolSeries (this);[/B]
    		
            }
    
            protected override void OnBarUpdate()
    {
    			//Reset bools to false after each bar
    			
    			[B]arrowup1.Set(false);[/B]
    			
    if (((close1 < open1 )||((open1 == close1) &&(Math.Abs(high1 - open1) > Math.Abs(low1 - open1)))||((open1 == close1) &&(Math.Abs(high1 - open1) == Math.Abs(low1 - open1))))&& ((close0 > open0)|| ((open0 == close0) && (Math.Abs(high0 - open0) < Math.Abs(low0 - open0)))|| ((open0 == close0) && (Math.Abs(high0 - open0) == Math.Abs(low0 - open0)))))				 
    {
    if (((myBslBullInv[0]<myBslBullInv[1]) && (myBslBear[0]>myBslBear[1])) && ((myBslBullInvPeriod3[0]<myBslBullInvPeriod3[1]) &&  (myBslBearPeriod3[0]>myBslBearPeriod3[1])))
    DrawArrowUp("My Arrow" + CurrentBar, false, 0, Low[0] - TickSize, Color.Purple); /			
    [B]arrowup1.Set(true);[/B]
    }
    }
    
    #region Properties
    {
    [B][Browsable(false)]
    	[XmlIgnore()]
    	public BoolSeries Arrowup1
    	{
    		get {return arrowup1;}	
    	}[/B]
    }
    Loading indicator A & B independently both work – I get the arrow signals and calculations (although not all on arrow signal bars at this stage).
    Is the top of the OnBarUpdate method the correct place to switch off the BoolSeries (arrowup1.Set(false)?
    I have then saved Indicator B as Indicator C. I then try to link to Indicator A by bringing in the BoolSeries created in Indicator A as follows:

    Code:
    {
          #region Variables
    
    			[B]private IndicatorA indicatorC;[/B]
    	#endregion
    }
    
            protected override void Initialize()
    {
                	Overlay				= true;
    			CalculateOnBarClose = true;
    
    [B]indicatorC = IndicatorA(bearperiod20, bearperiod3, bearperiod6, bearperiod8, bslDownBslFastUp, bslUpBslFastDown, bullperiod13, 
    bullperiod3, bullperiod6, bullperiod8, plotsChangeMinDiff, rangeMaxSpread, rangePeriod);[/B]
    }
    
            protected override void OnBarUpdate()
    {
    if ((diffVol <= mediumTsov) && (Close[0] > Open[0]) && (diffVol > displayVol) && (!((Open[1] < Close[1]) && (Open[0] < Close[0]) && (Close[1] == Open[0]))))
    {
    a1 = Math.Round(4 * higherPrice, MidpointRounding.ToEven)/4; aPB = Math.Round(4 * pbFromHigherPrice, MidpointRounding.ToEven)/4; a3 = Math.Round(4 * higherPriceFromPb, MidpointRounding.ToEven)/4;
    
    [B]if(indicatorC.Arrowup1[0] == true) [/B]
    DrawText (TagdiffVol1 + CurrentBar, "A"+"\n"+diffVol+"\n"+wTSum+"\n"+a1+"\n"+aPB+"\n"+a3.ToString(), 0, High[0] + 6 * TickSize, Color.Black);
    
    }
    }
    But when I load indicatorC none of the calculations appear on the chart. Any ideas what I am missing?

    Thanks

    #2
    Hello GeorgeW,

    Thank you for your post.

    So the DrawText() in IndicatorC is not displaying? Or are you expecting the arrows from IndicatorA to appear when using IndicatorC?

    In IndicatorA you have the following:
    Code:
    if (((close1 < open1 )||((open1 == close1) &&(Math.Abs(high1 - open1) > Math.Abs(low1 - open1)))||((open1 == close1) &&(Math.Abs(high1 - open1) == Math.Abs(low1 - open1))))&& ((close0 > open0)|| ((open0 == close0) && (Math.Abs(high0 - open0) < Math.Abs(low0 - open0)))|| ((open0 == close0) && (Math.Abs(high0 - open0) == Math.Abs(low0 - open0)))))  
    {
    if (((myBslBullInv[0]<myBslBullInv[1]) && (myBslBear[0]>myBslBear[1])) && ((myBslBullInvPeriod3[0]<myBslBullInvPeriod3[1]) &&  (myBslBearPeriod3[0]>myBslBearPeriod3[1])))
    DrawArrowUp("My Arrow" + CurrentBar, false, 0, Low[0] - TickSize, Color.Purple); /
    arrowup1.Set(true);
    }
    This appears to set arrowUp1 to true when the first if condition is true regardless of the second if statement that would draw the arrow. I would suggest the following instead:
    Code:
    if (((close1 < open1 )||((open1 == close1) &&(Math.Abs(high1 - open1) > Math.Abs(low1 - open1)))||((open1 == close1) &&(Math.Abs(high1 - open1) == Math.Abs(low1 - open1))))&& ((close0 > open0)|| ((open0 == close0) && (Math.Abs(high0 - open0) < Math.Abs(low0 - open0)))|| ((open0 == close0) && (Math.Abs(high0 - open0) == Math.Abs(low0 - open0)))))  
    {
    if (((myBslBullInv[0]<myBslBullInv[1]) && (myBslBear[0]>myBslBear[1])) && ((myBslBullInvPeriod3[0]<myBslBullInvPeriod3[1]) &&  (myBslBearPeriod3[0]>myBslBearPeriod3[1])))
    {
    DrawArrowUp("My Arrow" + CurrentBar, false, 0, Low[0] - TickSize, Color.Purple); /
    arrowup1.Set(true);
    }
    }
    Setting the BoolSeries to false at the beginning of the OnBarUpdate() is correct.

    Comment


      #3
      Hello PatrickH,
      Thanks for your help.
      It is the DrawTexts in Indicator C that are not showing. I am loading indicator A separately to show the arrows. I have tried your solution, but the DrawText still does not display.

      Comment


        #4
        Hello GeorgeW,

        Thank you for your response.

        May we test out the indicators on our end to see if we can break down what is occurring?
        If so, please send a note to platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick H - 1589021' in the subject line. Attach your indicators by going to File > Utilities > Export NinjaScript > Export selected source files > select your Indicator > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.

        Comment


          #5
          Hello PatrickH,
          Unfortunately the indicators are private at the moment, so I cannot send them. I will try the bool with a simple indicator to see if I can work out what is happening.

          Thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by funk10101, Today, 09:43 PM
          0 responses
          3 views
          0 likes
          Last Post funk10101  
          Started by pkefal, 04-11-2024, 07:39 AM
          11 responses
          36 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Yesterday, 08:51 AM
          8 responses
          44 views
          0 likes
          Last Post bill2023  
          Started by yertle, Today, 08:38 AM
          6 responses
          26 views
          0 likes
          Last Post ryjoga
          by ryjoga
           
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          24 views
          0 likes
          Last Post algospoke  
          Working...
          X