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

Can't seem to get this to work

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

    Can't seem to get this to work

    Any help is greatly appreciated.

    I can't get this to make entrees:

    Code:
    // Store Value1 
    			if (Position.MarketPosition == MarketPosition.Flat
    				&& CrossAbove(Close, Bollinger(1.5,50).Lower, 1)
    				)
    				
                {
                    storedValue1 = Close[0];
                }
    			
    			
    	   // Start Long 
    			if (Position.MarketPosition == MarketPosition.Flat
    				&& OneTradeEntered == false
    				&& CrossAbove(Close, Bollinger(1.5,50).Lower, 1)
    				&& Close[0] > storedValue1 
    				)
    				
                {
                    entryCount = 0;
    				entryCount++;
    				EnterLong(1,PositionSize, "(Forex5) Long1"+ entryCount.ToString() + maxDD);
    				OneTradeEntered = true;
    				storedValue1 = 0;
                }

    #2
    Hello,

    Thank you for the question.

    It is hard to say from just the paste of part of the script, have you at this point used any debugging tools such as Prints to see if the conditions are becoming true? Also to check the values being passed to the conditions?

    If you have not yet, adding Print statements is a good first step, I would suggest putting a print in each of the conditions to ensure both are happening:

    Code:
    // Store Value1 
    			if (Position.MarketPosition == MarketPosition.Flat
    				&& CrossAbove(Close, Bollinger(1.5,50).Lower, 1)
    				)
    				
                {
                   [COLOR="Red"] Print("Condition 1: " + storedValue1);[/COLOR]
                    storedValue1 = Close[0];
                }
    			
    			
    	   // Start Long 
    			if (Position.MarketPosition == MarketPosition.Flat
    				&& OneTradeEntered == false
    				&& CrossAbove(Close, Bollinger(1.5,50).Lower, 1)
    				&& Close[0] > storedValue1 
    				)
    				
                {
                  [COLOR="Red"]  Print("Condition 2");[/COLOR]
                    entryCount = 0;
    				entryCount++;
    				EnterLong(1,PositionSize, "(Forex5) Long1"+ entryCount.ToString() + maxDD);
    				OneTradeEntered = true;
    				storedValue1 = 0;
                }
    Now open the Tools -> Output window and reload the script, if you see no prints, the first condition is not happening, if you only see 1 print the second condition did not happen. In the case you see both prints but no entry, it could be that the entry was ignored. In that situation you may need to use TraceOrders to find the cause: http://ninjatrader.com/support/helpG...ub=traceorders

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank Jesse, I implemented the Print statement and I can see that the first condition is being executed but the second is not. I have been staring at the code for an hour and can't figure out why.

      Comment


        #4
        Originally posted by relogical View Post
        Thank Jesse, I implemented the Print statement and I can see that the first condition is being executed but the second is not. I have been staring at the code for an hour and can't figure out why.
        Where did you make OneTradeEntered false?

        Comment


          #5
          Originally posted by koganam View Post
          Where did you make OneTradeEntered false?
          I eliminated that condition in my latest test but still no luck.

          Comment


            #6
            Hello,

            In this case, both share the first part of the condition:

            if (Position.MarketPosition == MarketPosition.Flat

            That is likely not the problem, the values being checked are likely the issue. I would suggest moving the print now to this location and print the following items to see what is happening:


            Code:
            // Store Value1 
            			if (Position.MarketPosition == MarketPosition.Flat
            				&& CrossAbove(Close, Bollinger(1.5,50).Lower, 1)
            				)
            				
                        {
                           [COLOR="Red"] Print("Condition 1: " + storedValue1);[/COLOR]
                            storedValue1 = Close[0];
                        }
            			
            	      [COLOR="Red"]  Print("OneTradeEntered: " + OneTradeEntered + " CrossAbove: " + CrossAbove(Close, Bollinger(1.5,50).Lower, 1) + " Close > storedValue1: " + Close[0] + " > " + storedValue1);[/COLOR]
            	   // Start Long 
            			if (Position.MarketPosition == MarketPosition.Flat
            				&& OneTradeEntered == false
            				&& CrossAbove(Close, Bollinger(1.5,50).Lower, 1)
            				&& Close[0] > storedValue1 
            				)
            				
                        {
            
                            entryCount = 0;
            				entryCount++;
            				EnterLong(1,PositionSize, "(Forex5) Long1"+ entryCount.ToString() + maxDD);
            				OneTradeEntered = true;
            				storedValue1 = 0;
                        }
            This is outside of the non working condition but prints the values that condition will use, this should provide more details on what value is not becoming true.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Here's what the output looks like:

              Condition 1: 1.2348
              OneTradeEntered: False CrossAbove: True Close > storedValue1: 1.2354 > 1.2354
              OneTradeEntered: False CrossAbove: False Close > storedValue1: 1.2356 > 1.2354
              OneTradeEntered: False CrossAbove: False Close > storedValue1: 1.2358 > 1.2354
              OneTradeEntered: False CrossAbove: False Close > storedValue1: 1.236 > 1.2354
              OneTradeEntered: False CrossAbove: False Close > storedValue1: 1.2356 > 1.2354
              OneTradeEntered: False CrossAbove: False Close > storedValue1: 1.236 > 1.2354
              OneTradeEntered: False CrossAbove: False Close > storedValue1: 1.2362 > 1.2354

              Comment


                #8
                Originally posted by relogical View Post
                Here's what the output looks like:

                Condition 1: 1.2348
                OneTradeEntered: False CrossAbove: True Close > storedValue1: 1.2354 > 1.2354
                OneTradeEntered: False CrossAbove: False Close > storedValue1: 1.2356 > 1.2354
                These 2 mean that your conditions are too tight. Your CrossAbove is only true on one bar, and that bar necessarily has the Close the same as the storedValue1, because that is what you coded it to be.

                How you will resolve the issue depends on what you are trying to do. Do you care to describe in words what you want to do?

                Comment


                  #9
                  I am trying to enter a position if a current cross above lower bollinger is higher than the last cross above.

                  Comment


                    #10
                    Originally posted by relogical View Post
                    I am trying to enter a position if a current cross above lower bollinger is higher than the last cross above.
                    In that case, your failure comes from the fact that your first block is itself modifying the storedValue1 before it is tested. There are a few ways to get around that, but it will depend on how your overall code is designed. At the very least, you should move the previous value into a different variable, before you store the new value, then test said previous value.

                    Here is one scheme. (I do not think that that is all that you need to do, but it should get you over the first hump).
                    Code:
                    // Store Value1 
                    			if (Position.MarketPosition == MarketPosition.Flat
                    				&& CrossAbove(Close, Bollinger(1.5,50).Lower, 1)
                    				)
                    				
                                {
                                    Print("Condition 1: " + storedValue1);
                                    previousStoredValue1 =  storedValue1;
                                    storedValue1 = Close[0];
                                }
                    			
                    	        Print("OneTradeEntered: " + OneTradeEntered + " CrossAbove: " + CrossAbove(Close, Bollinger(1.5,50).Lower, 1) + " Close > storedValue1: " + Close[0] + " > " + storedValue1);
                    	   // Start Long 
                    			if (Position.MarketPosition == MarketPosition.Flat
                    				&& OneTradeEntered == false
                    				&& CrossAbove(Close, Bollinger(1.5,50).Lower, 1)
                    				&& Close[0] > previousStoredValue1 
                    				)
                    				
                                {
                    
                                    entryCount = 0;
                    				entryCount++;
                    				EnterLong(1,PositionSize, "(Forex5) Long1"+ entryCount.ToString() + maxDD);
                    				OneTradeEntered = true;
                    				storedValue1 = 0;
                                }
                    Remember to declare previousStoredValue1 as a class variable. You may also have to reset it at some point.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by CortexZenUSA, Today, 12:53 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post CortexZenUSA  
                    Started by CortexZenUSA, Today, 12:46 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post CortexZenUSA  
                    Started by usazencortex, Today, 12:43 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post usazencortex  
                    Started by sidlercom80, 10-28-2023, 08:49 AM
                    168 responses
                    2,265 views
                    0 likes
                    Last Post sidlercom80  
                    Started by Barry Milan, Yesterday, 10:35 PM
                    3 responses
                    11 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Working...
                    X