• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Please help with very simple strategy (bollinger) to beginner

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

    Please help with very simple strategy (bollinger) to beginner

    Hi, need help with very simple strategy on bolinger bands

    Ned to:
    When bar open is higher than the Bollinger upper line, and the close of the bar is lower than Bollinger upper line - go Short.
    And
    When bar open is lower than the Bollinger Lower line, and the close of the bar is upper than Bollinger Lower line - go Long.

    Please help to understand the code for complete beginner.
    Very thanks for the help!

    My wrong code:

    Code:
    	IsInstantiatedOnEachOptimizationIteration	= true;
    			}
    			else if (State == State.Configure)
    			{
    			}
    			else if (State == State.DataLoaded)
    			{				
    				Bollinger1				= Bollinger(Close, 2, 14);
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			if (CurrentBars[0] < 1)
    			return;
    
    			 // Set 1
    			if ((CrossAbove(Bollinger1.Upper, Open, 1))
    				 && (CrossBelow(Bollinger1.Upper, Close, 1)))
    			{
    				EnterShortLimit(Convert.ToInt32(DefaultQuantity), 1, @"GoShort");
    			}
    			
    			 // Set 2
    			if ((CrossAbove(Bollinger1.Lower, Open, 1))
    				 && (CrossBelow(Bollinger1.Lower, Close, 1)))
    			{
    				EnterLongLimit(Convert.ToInt32(DefaultQuantity), 1, @"GoLong");
    			}
    			
    		}
    	}
    }

    #2
    Hello memonolog,

    It looks like in set 1 you are looking for both a crossabove and a crossbelow to occur on the same bar.

    CrossAbove looks for series 1 to be less than series 2 on the previous bar and then for series 1 to be greater than series 2 on the current bar.

    CrossBelow looks for exact opposite. Series 1 must be greater than series 2 on the previous bar and then series 1 must be less than series 2 on the current bar.

    So with this code you would require that the open of the bar be less than the bollinger upper line on the previous bar and the close must be above the bollinger upper line on the previous bar, then on the current bar this needs to reverse, the open must be below the upper line and the close of the bar above it.

    Then a sell short limit order is placed at a price of 1.00 (likely all the way at the bottom of the scale depending on the instrument). I would expect this order to be rejected for being on the wrong side of the market or would fill immediately as a sell limit below market would fill at the market price.


    With the second condition the open of the bar must be less than the bollinger lower line on the previous bar and the close above it and then must reverse on the current bar with the close below the bollinger lower and the open above it.

    However, this would place a buy limit order at a price of 1.00 (again, likely at the bottom of the scale depending on the instrument and would likely never fill unless the price of the instrument came down to 1.00).


    To understand exactly why orders are being placed (meaning the conditions are not evaluating as true), it becomes necessary to add prints to the script of all variable values and view the output.

    Below is a link to a forum post that has links to videos that demonstrate this.
    https://ninjatrader.com/support/foru...979#post510979

    Then to find if orders are being placed and then cancelled because they are not filled, add TraceOrders = true; to the script either manually or by checking the Default Properties -> More Properties -> Trace orders checkbox. This wil also appear in the output window.

    Please include the output from the prints so that we may further assist.


    Last, below I am providing a link to a forum post with helpful information, links to videos, and tutorials about getting started with NinjaScript.
    https://ninjatrader.com/support/foru...609#post503609
    Last edited by NinjaTrader_ChelseaB; 10-02-2017, 06:59 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for replay!
      can you provide complete example of the code?

      Comment


        #4
        Hello memonolog,

        Are you asking for a complete example of a print?

        A full example of a print for a crossabove is shown in the video that is linked in the forum post about debugging.

        Are you asking for an example of the behavior I have described?

        I have described the rules you have coded in post #1.


        Are you intending to use CrossAbove / CrossBelow?

        From your description, you may not be intending to use these.

        You are may not be looking for a cross of the items, but instead are just looking for one item to be higher than another (without also comparing the previous bar).

        For example:
        Code:
        if (Open[0] > Bollinger1.Upper[0] && Close[0] < Bollinger1.Lower[0])
        {
        EnterShort();
        }
        Last edited by NinjaTrader_ChelseaB; 10-02-2017, 07:05 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you very, very much!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Maxwell123, Today, 12:34 AM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Started by memonic, Today, 02:21 AM
          0 responses
          5 views
          0 likes
          Last Post memonic
          by memonic
           
          Started by Guru73, Yesterday, 02:47 AM
          5 responses
          33 views
          0 likes
          Last Post Guru73
          by Guru73
           
          Started by Guru73, Today, 01:35 AM
          0 responses
          2 views
          0 likes
          Last Post Guru73
          by Guru73
           
          Started by i2w8am9ii2, Yesterday, 04:41 PM
          1 response
          12 views
          0 likes
          Last Post Lancer
          by Lancer
           
          Working...
          X