Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Intrabar Logic

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

    Intrabar Logic

    Hi guys, was hoping with some basic help on intrabar logic:

    What I'm trying to do is use some commands basic on the current bar using some sort of THEN statement:

    For example I am doing the following based on 10 tick Renko Bars:

    1. If Ask crosses 10 ticks below the close of previous bar

    AND THEN

    2. If Ask crosses above the Close of the previous bar and ask volume is > than a specified number

    3. THEN if ask increases another 5 ticks and ask volume is than a specified number.

    Trigger Order

    I am struggling with the logic of THEN so multiple conditions are satisfied one after the other before an order is actioned. In the above example should only work if 1 is triggered first then action 2 and if two is triggered then action 3. I'm ok with:

    if and else commands but not

    if and Then

    Can you please help me on this one:

    Thanks
    DJ

    #2
    Hello djkiwi,

    You will have to code a sequence. A common approach is using bool flags and user variables. A sample for sequences with user variables is available here.


    An example with bool flags looks something like this:

    Code:
    #region Variables
    private bool goSecondCond = false;
    private bool goThirdCond = false;
    #endregion
    
    if (yourFirstCondition)
    goSecondCond = true;
    			
    if (goSecondCond && yourSecondConditions)  
    goThirdCond = true;
    
    if (goThirdCond && yourThirdConditions)
    //place orders
    You then need something later on that resets these back to their initial values as false.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Orders Going nuts

      Thanks Ryan, that is exactly what I'm looking for although when it triggered the order it started going nuts and kept triggering orders! I only want it to process one order per bar you see. So what happens here is once gosecondcond 2 is triggered then it processes the ATM Strategy. I found this firsttickofbar as per the manual but that doesn't seem to work. Also I found this in another post, that doesn't help either:

      && GetAtmStrategyMarketPosition("TF2") == MarketPosition.Flat

      Any ideas on this one? Thanks. DJ

      Here is some of my code:

      // LONG ENTRIES

      }
      if (orderIdL.Length == 0
      && atmStrategyIdL.Length == 0
      && GetAtmStrategyMarketPosition("TF2") == MarketPosition.Flat
      && FirstTickOfBar


      && Open[0] > Open[1]
      && Close[1] > Open[1]
      &&_ADXVMA_Alertsv01_5_1_Hurley2(5, true).Signal[0] ==1
      )

      goSecondCond=true;

      //Second Condition

      if(goSecondCond
      &&Close[0] < Close[1] - PrevBarsPlusTicks * TickSize

      )

      {

      atmStrategyIdL = GetAtmStrategyUniqueId();
      orderIdL = GetAtmStrategyUniqueId();
      orderBarL = CurrentBar;
      AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Close[1] - prevBarsPlusTicks * TickSize,0, TimeInForce.Day, orderIdL, "TF2", atmStrategyIdL);


      }

      Comment


        #4
        Hello,

        Do you have any logic that cancels that ATM Strategy entry? As this is the only reason with the code provided here that you would get multiple entried at in a row E.I. go nuts.

        As when the ATM Strategy is run its gets generated an atmStrategyIDL that will have an ID in it. The only time thist length would be 0 is if you have reset it. What code are you using to reset it?
        BrettNinjaTrader Product Management

        Comment


          #5
          Reset a strategy

          Hi Brett, I'm not sure how to reset it. I though that the firsttickof bar would do the trick. Can you please tell me how to reset it . Thanks. DJ

          Comment


            #6
            DJ - I would work first from the dedicated sample we have on this. It's built into the platform. Click Tools > Edit NinjaScript > Strategy > SampleAtmStrategy.

            Work as close to the sample as you can without changing the structure. There is a lot of internal logic there that is needed for it to work properly. The final step in this sequence, before placing orders, should be checking the orderIdLength and AtmStrategyId.Length. Currently, your condition for placing the orders does not include this.
            Last edited by NinjaTrader_RyanM1; 01-03-2011, 10:34 AM.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Latest Code - PROBLEM SOLVED

              NOTE: PROBLEM SOLVED LATEST CODE PRESENTED FOR OTHERS HAVING SAME PROBLEM WITH MULTIPLE CONDITIONS AND CANCELING ORDERS

              Hi Ryan, actually I have been through that sample code many times trying to get to the bottom of it. My code was derived from some of the excellent work of MrTicks. I have also looked at the thread below as well and tried to incorporate those things mentioned.



              In post 8 MrTicks talks about inserting the following Code into the program. You mention set COBC to true although my strategy needs to be set to false. Mind you when set to true it still went nuts I had orders of over 200 sometimes.

              private bool tradeLong = false;
              private bool tradeShort = false;

              I've also looked at this part and added it but it made things even worse:



              To try and get this to work I have simplified the strategy to very basic for now to get to the bottom of it. So this strategy simply places Long orders based on a 5 tick pullback then the price exceeds the previous close (as per Second and third conditions) and shorts the opposite. The problem is even after all this work it is still going nuts as am I.

              Please find the code below and would greatly appreciate your comments on how to solve this mystery:

              Thanks
              DJ
              Attached Files
              Last edited by djkiwi; 01-02-2011, 01:36 AM.

              Comment


                #8
                Glad to hear you found the culprit and thanks for sharing the code here.

                Comment


                  #9
                  Market Position Flat Issue

                  Thanks Bertrand, unfortunately the joy didn't last for now at least. I have managed to stop the 200 pending orders but now the problem is it is triggering new orders once I'm in the trade. If you look at the code below I do have the right code to stop this happening:

                  && GetAtmStrategyMarketPosition("TF2") == MarketPosition.Flat in line 104

                  and

                  && GetAtmStrategyMarketPosition("TF2") == MarketPosition.Flat - in line 150

                  Any ideas on this one? Thanks. DJ

                  Comment


                    #10
                    I looked through the code you submitted.

                    You have order placement methods that do not use this market position check you posted.

                    You will have to debug this. Print all values for the conditions you have before placing orders.

                    You have order placement in these conditions:
                    if(goLongThirdCond && Close[0] > Close[1])


                    if(goShortThirdCond && Close[0] < Close[1])
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Intrabar Issues

                      Hi Ryan, can you please elaborate on this. It is getting me in the order ok. When looking at the output screen I am seeing:

                      1. GetAtmStrategyMarketPosition() method error: AtmStrategyId 'TF2' does not exist (Note: Josh said to put the getatm in instead of this: (Position.MarketPosition == MarketPosition.Flat) because I'm in an ATM strategy.

                      Why do you think it is doing this when I am in the ATM strategy?

                      2. Print statements

                      Also when I insert the print statements do I put them as per the code below? The reason I ask is I am getting this on the output screen:

                      ***** out of memory exception: too much data to print, all output is deleted *****979
                      0
                      False
                      796.5
                      797.5
                      True
                      True
                      **NT** GetAtmStrategyMarketPosition() method error: AtmStrategyId 'TF2' does not exist
                      False
                      796.5
                      797.7
                      False
                      False
                      **NT** GetAtmStrategyMarketPosition() method error: AtmStrategyId 'TF2' does not exist
                      0

                      3. Code with print statements giving above output?

                      // SHORT ENTRIES

                      if (FirstTickOfBar) {
                      tradedShort = false;}



                      //Print(Position.MarketPosition);
                      Print(tradedShort);
                      Print(Open[0]);
                      Print(Open[1]);
                      Print(goShortSecondCond);
                      Print(goShortThirdCond);


                      if (orderIdS.Length == 0
                      && atmStrategyIdS.Length == 0
                      && GetAtmStrategyMarketPosition("TF2") == MarketPosition.Flat
                      && Position.MarketPosition == MarketPosition.Flat

                      && tradedShort == false

                      && Close[1] < Open[1]
                      && Open[0] < Open[1]

                      )

                      Thanks. DJ

                      Comment


                        #12
                        The issue you reported was with orders placed undesirably. To debug this then, you must look at the values for the conditions used in order placement.

                        You mentioned that you're using a market position check, but this condition is not used for order placement. It's only the state of your goLongThird and a bullish bar that determines whether you're placing an order. You have to track these variables any place you need to identify what may be happening.

                        If it's too complicated to sort out what is happening with the code, then simplify it. Do a two step sequence and only move to a third when you've verified everything works as you expect.

                        If you're getting too much output, try running with COBC = true or reducing the number of print statements.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Order Issues

                          Thanks Ryan, well this is the part I'm struggling with:

                          "You mentioned that you're using a market position check, but this condition is not used for order placement. It's only the state of your goLongThird and a bullish bar that determines whether you're placing an order"

                          My understanding was once the third condition was satisfied it then uses the ATM strategy in line 150 for order placement:

                          AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Close[1] - prevBarsPlusTicks * TickSize,0, TimeInForce.Day, orderIdL, "TF2", atmStrategyIdL);

                          Once in the trade I'm still not clear why this won't work and trades are triggered once I'm in the trade...

                          GetAtmStrategyMarketPosition(atmStrategyIdL) == Cbi.MarketPosition.Flat). Maybe I need to put this market condition check after I'm in the trade somewhere?

                          I tried to following this advice you gave to mr ticks in post 17:

                          http://www.ninjatrader.com/support/f...hlight=mrticks.

                          You suggested mr ticks to put the following in. If you could look at my line 304 I am missing the second line here: the atmstragetystoptarket part. Is this the issue? Thanks for your patience. DJ

                          // You can change the stop price
                          if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
                          AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
                          Last edited by djkiwi; 01-03-2011, 01:56 PM.

                          Comment


                            #14
                            There's unfortunately no shortcut here to simplifying and debugging. I'm not aware of a one-line change you can make to have the strategy perform the way you want.

                            I would start over, working from the sample and do a two step sequence, making sure to manage the states of all your bool variables to create the sequence you like. If you change the structure a lot from the sample then this can break all the internal logic that's necessary for it to work.
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              Redo

                              Hi Ryan, let me try and start again and see when it happens. One other thing I noticed when doing these print statements is the output window lags. I removed my strategies and it was still rattling off stuff hours later. Is there a way to reset it?

                              I did see this...

                              ClearOutputWindow()

                              So does it mean you have to run a program to reset it each time? Thanks. DJ

                              Comment

                              Latest Posts

                              Collapse

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