Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with example of adding atm to a Strat. Looking for example.

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

    #16
    forrestang, what the point the stop does not execute like you would expect, what info does the TraceOrders output give you then? To me your price adjustment does not seem right for both sides you add 2 tick to the AvgPrice of the position.

    Comment


      #17
      Originally posted by NinjaTrader_Bertrand View Post
      forrestang, what the point the stop does not execute like you would expect, what info does the TraceOrders output give you then? To me your price adjustment does not seem right for both sides you add 2 tick to the AvgPrice of the position.
      The trace order, I'm not sure what that is telling me? It's more or less different for every trade, even though they have the same outcome.

      As far as the price adjustment, wouldn't you want to set the stoploss adjustment to some value +- your average price?

      Comment


        #18
        Ok, with the TraceOrders what I meant is: at that point there's no 'ignored' order noted, right?

        Right, you would set the value with an offset to your AvgPrice, but I just noted you were adding 2 ticks it whether you're long or short and I'm not sure if that was your intention.

        Comment


          #19
          Originally posted by NinjaTrader_Bertrand View Post
          Ok, with the TraceOrders what I meant is: at that point there's no 'ignored' order noted, right?

          Right, you would set the value with an offset to your AvgPrice, but I just noted you were adding 2 ticks it whether you're long or short and I'm not sure if that was your intention.
          I see what you mean. That was one of the iterations, I guess i was just trying anything. Setting them opposite, and different still yields a problem.

          What I don't get is how I can have the same exact code, only with the different operands and variables, and get different results?

          Comment


            #20
            You would need to debug your strategy and add some visual checks to what exactly is being calculated where as things do not work out as you expect, sometimes it's all you need as you deem a section to be fine that is leading to an issue later, step by step is then the only way to understand how it gets to it's final result, then you can make attempt to correct it at it's origin. For your stop, it seems to work yet it shouldn't be executed before the ExitOnClose? If you take the entry and add 2 tick like in your code, is that ever triggered by PA?

            Comment


              #21
              Originally posted by NinjaTrader_Bertrand View Post
              You would need to debug your strategy and add some visual checks to what exactly is being calculated where as things do not work out as you expect, sometimes it's all you need as you deem a section to be fine that is leading to an issue later, step by step is then the only way to understand how it gets to it's final result, then you can make attempt to correct it at it's origin. For your stop, it seems to work yet it shouldn't be executed before the ExitOnClose? If you take the entry and add 2 tick like in your code, is that ever triggered by PA?
              The examples show where price does come back to that BE+2, but it just doesn't trigger. I've put a Print() in that loop, so it is getting there. It just doesn't execute.

              I guess I will just have to try again at more debugging. I figured setting stops was a pretty straightforward exercise, yet it is proving to be the most PITA thing I've worked with so far.

              Comment


                #22
                Please give that slightly changed version a try, you were getting some 0 stoploss prices as you attempted to access the Position object to early, basically before your return out on that call to ManageOrders if flat. This was easily spotted as the stop loss prices were all visualized with the a drawing object for example, it can really help debugging scripts.
                Attached Files

                Comment


                  #23
                  This script still doesn't execute the BE stop. I think moving the stoploss in the initialize as above has set a hard OCO, it ignores the other adjustments completely.

                  Did you remove the drawing objects? Seems like I need to get some of those in there. Did you just plot dots or something? Can you draw objects on a chart from within a strategy?

                  Comment


                    #24
                    Originally posted by forrestang View Post
                    Can you draw objects on a chart from within a strategy?
                    I see you can. I swear I tried this before and it didn't work. Hehe.

                    Comment


                      #25
                      Originally posted by NinjaTrader_Bertrand View Post
                      Please give that slightly changed version a try, you were getting some 0 stoploss prices as you attempted to access the Position object to early, basically before your return out on that call to ManageOrders if flat. This was easily spotted as the stop loss prices were all visualized with the a drawing object for example, it can really help debugging scripts.
                      Bertrand,

                      There has to be something with the way NT handles these orders, or something I am not doing?

                      I have the script doing EXACTLY what I want... on the Long Side. It is the exact same code for the short side. But for some reason, it refuses to handle my adjusted stop properly on the short side. It can't be some overlap problem, because when I comment out all the code having to do with the long side, it still doesn't handle those short orders.

                      Comment


                        #26
                        I've isolated my problem a bit further. And is the way I am setting that stopLoss somehow.

                        Still messing with it. I have both the ProfitTarget and InitialStop both up in the initialize section. I have the stop the exit condition for closing beyond the MovingAverage in this block. All 3 of the conditions I listed above work fine.

                        Here is the block of code where I am attempting to set the stop adjustment. You can see the section I have commented out. With that commented out, the strat WILL exit on any of the conditions I have above just fine.

                        When I remove the comments, I get the following error. So the adjustment must not be going where I think it should.

                        Code:
                        private void ManageOrdersShort()
                        		{		
                        			if (Position.MarketPosition == MarketPosition.Short)
                        			{
                        				numBars = BarsSinceEntry("Short1");
                        				double maxMove = MAX(Low, numBars)[0];
                        				
                        [COLOR="SeaGreen"]//				if (maxMove <= Position.AvgPrice - (beMove*TickSize))
                        //					SetStopLoss("Short1", CalculationMode.Price, Position.AvgPrice - (2*TickSize), false);[/COLOR]
                        				
                        				if (Close[0]> spanB[0])
                        					ExitShort("ExitShort1", "Short1");
                        				
                        				Print("hello");
                        			}
                        		}
                        Attached Files

                        Comment


                          #27
                          I'm onto something here.

                          That adjustment is being submitted too soon. Need to go over that logic.

                          Will report back.
                          Attached Files

                          Comment


                            #28
                            The problem is definetely that 'if()' statement.

                            For some reason, it is evaluated as TRUE as soon as the entry is placed, instead of evaluating as true after it moves a certain distance?

                            THAT is the problem. At least I figured out that much.

                            Comment


                              #29
                              Ok, really this time I got it working. I'm not going to pretend to remember exactly what I changed.

                              THIS reference was a help.
                              Last edited by forrestang; 08-04-2011, 11:12 PM.

                              Comment


                                #30
                                forrestang, sorry for our late reply here, glad to hear you were able to isolate it down and resolve.

                                Comment

                                Latest Posts

                                Collapse

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