Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop execution if less than supertrend line

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

    #46
    Looks like im not quite out of the woods yet. Its exiting based on the secondary object as i was trying to accomplish but it looks like its possibly also entering based on secondary bar object. Would like it to enter as normal based on primary. Do i have the BIP in the right place? How do i make sure entry part of the code is using primary?

    Code:
     
    protectedoverridevoid Initialize() 
    {Add(PeriodType.Minute, 1);
     
     CalculateOnBarClose = true; }
     
    protectedoverridevoid OnBarUpdate()
     
    {
     // Condition set 1 Long Entry
    [B]if (BarsInProgress == 0)[/B]
    if (MACD(longmacdfast, 26, 5)[0] >= 0
    && Close[0] > BigMO(bigmoemalong).EMAline[0]
    && SuperTrend(14, 2.618, true).UpTrend[0] < Close[0]
    && MACD(longmacdfast, 26, 9)[0] > MACD(longmacdfast, 26, 9)[1]
    && Close[0] < (BigMO(bigmoemalong).EMAline[0] + (ATR(14)[0] * 10))
    && ToTime(Time[0]) > ToTime(timestart, 0, 0)
    && ToTime(Time[0]) < ToTime(16, 0, 0)
    ) 
    { EnterLong(DefaultQuantity, ""); }
     
     
     
    // Condition set 2 Long Exit. If price Closes below supertrend for previous bar, exit long.
    if ( SuperTrend(BarsArray[0], 14, 2.618, true).UpTrend[1] >= Closes[1][0]
    && ToTime(Time[0]) > ToTime(timestart, 0, 0)
    && ToTime(Time[0]) < ToTime(timeend, 0, 0))
     
    { ExitLong("", ""); }}

    Comment


      #47
      Currently it only executes the first line after the BarsInProgress == 0 check. If you want more than one line executed after an if statement, all lines must be enclosed in curly brackets { }. Some examples for branching are available here:

      Last edited by NinjaTrader_RyanM1; 02-10-2012, 01:40 PM.
      Ryan M.NinjaTrader Customer Service

      Comment


        #48
        I don't think so, I have..

        {
        // Condition set 1 Long Entry

        and then at the end have the extra curly bracket to close it out...

        { ExitLong("", ""); }}

        Comment


          #49
          Right, those brackets enclose the whole OnBarUpdate() handler, but you do not have any enclosing the logic you want to execute for if (BarsInProgress == 0). Add some { } for all code you want to run within BIP 0.
          Ryan M.NinjaTrader Customer Service

          Comment


            #50
            Those are all if statements, If BIP... if MACD... if Close[0]...etc. etc. then the one command to Enter long has curly brackets around it
            {EnterLong("", "");}

            Comment


              #51
              Please let me know if you gave you tried my suggestion and if there is something I can clarify about it? I understand you disagree that it is the solution here, but let's agree that you are willing to try the proposed changes and report back your progress.

              Code:
              if (BarsInProgress == 0)
              {
              if (MACD(longmacdfast, 26, 5)[0] >= 0
              && Close[0] > BigMO(bigmoemalong).EMAline[0]
              && SuperTrend(14, 2.618, true).UpTrend[0] < Close[0]
              && MACD(longmacdfast, 26, 9)[0] > MACD(longmacdfast, 26, 9)[1]
              && Close[0] < (BigMO(bigmoemalong).EMAline[0] + (ATR(14)[0] * 10))
              && ToTime(Time[0]) > ToTime(timestart, 0, 0)
              && ToTime(Time[0]) < ToTime(16, 0, 0)
              ) 
              { EnterLong(DefaultQuantity, ""); }
              }
              Ryan M.NinjaTrader Customer Service

              Comment


                #52
                Yes I tried that, and I just tried it again to double check, it does not change anything. And I don't logically see how it would, those are all if statements that must be true before it can execute the long
                if (BarsInProgress == 0)
                if MACD(longmacdfast, 26, 5)[0] >= 0
                if Close[0] > BigMO(bigmoemalong).EMAline[0]
                etc.

                if all of these are true then execute the long. But i went and put your exact code below in and nothing changed. Its still executing the buy on the secondary it appears.

                Code:
                 
                if (BarsInProgress == 0)
                { if (MACD(longmacdfast, 26, 5)[0] >= 0 
                && Close[0] > BigMO(bigmoemalong).EMAline[0] 
                && SuperTrend(14, 2.618, true).UpTrend[0] < Close[0] 
                && MACD(longmacdfast, 26, 9)[0] > MACD(longmacdfast, 26, 9)[1] 
                && Close[0] < (BigMO(bigmoemalong).EMAline[0] + (ATR(14)[0] * 10)) 
                && ToTime(Time[0]) > ToTime(timestart, 0, 0)
                && ToTime(Time[0]) < ToTime(16, 0, 0) )
                { EnterLong(DefaultQuantity, ""); } }

                Comment


                  #53
                  All logic would be contained with BIP == 0, so it should only check conditions during updates to primary series. Since both primary and secondary are the same instrument, can you please clarify your understanding of "Its still executing the buy on the secondary it appears."?
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #54
                    Please see attached photo. Ive circled the region in question. There is a long execution and than another one immediately after it. Its only supposed to execute the first long. When I remove the secondary portion of the code it doesn't execute this second long.

                    It should only exit if the bar closes below the green dots(supertrend dots), which it doesnt.
                    Attached Files

                    Comment


                      #55
                      If you remove/add the secondary series, this could have other implications - different sequences or series of trades.

                      Best is just check if the conditions are true or not for that bar, which requires identifying it, and then printing all values used in your condition. You'll likely find that they're true and the strategy is working as designed.

                      Unfortunately we just do not have the resources to do this strategy debugging for you. We like to help where we can, but there are too many potential factors and setups to offer this for everyone.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #56
                        Got it. This line of the Exit portion of the code if ( SuperTrend(BarsArray[0], 14, 2.618, true).UpTrend[1] >= Closes[1][0]

                        The .UpTrend[1] needed to be changed to .UpTrend[0]. The uptrending Supertrend line doesn't always flip to the underneath side of the price right away, stays on the top side. So right after entering the trade it was prematurely catching and exiting. So I just took the [1] or previous bar out of the mix so it wouldn't catch too early. What a pain.

                        Comment


                          #57
                          SuperTrend and Serializing along with Juirk Dll error

                          Hi...I installed SuperTrend...I am getting a error about the SuperTrend could not be serialized and also the Juirk DLL can not be found...in plain english...how do I fix?

                          Just wondering about this again please?



                          Greg
                          Last edited by birdog; 03-05-2013, 02:28 PM.

                          Comment


                            #58
                            Originally posted by zachj View Post
                            attached the .cs file. Do you have to have the file open for it to print to the output window or how does it know which file to pull from. I guess it must just pull from whichever file has a print statement in it.
                            Hello i m not able to import spitfire target script

                            error screenshot is attached kindly give me solution asap.
                            Attached Files

                            Comment


                              #59
                              Hello mailmayank87,

                              Thank you for your post and welcome to the NinjaTrader support forum!

                              Please follow the instructions below to see where the errors are coming from after compiling the indicator. This will allow you to debug the indicator/strategy or remove it from your PC. If you are wondering why you receive an error when compiling only one indicator, it is because NinjaTrader always compiles all indicators and strategies - not just one. This is done to give you the highest runtime performance possible.
                              • Open NinjaTrader
                              • From the Control Center select the Tools menu--> select the Edit NinjaScript menu item--> select Indicator
                              • Select any indicator and double click on it (we need only to open and compile one script to see all compile errors for all files).
                              • A new window will appear and you will need to right click in the window and select Compile to compile the indicators.
                              • At the bottom of the window a new section will appear where you can find the error locations.
                              • From there you have the option to comment out offending code sections, remove the complete indicator or debug it to be able to compile again.

                              If you are unsure as to what the error is indicating, please send me a screenshot of the error with the name and description fields clearly readable.

                              To send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CRTL + V to paste the image. Lastly, save as a jpeg file and attach the file to your response.

                              We have also collected more comprehensive steps for resolving NinjaScript programming errors in this tip on our forums - http://www.ninjatrader.com/support/f...ead.php?t=4678

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              651 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              370 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              577 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X