Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set own stop/loss order

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

    Set own stop/loss order

    Hi guys,

    I am trying to solve a simple task in developing a strategy and can't figure out the correct way:

    As long as an order is online I want to update the stop loss order every day to the low of the previous day. This is not possible if I call the SetStopLoss in the initialize method but it doesn't work as expected if I call it in OnBarUpdate.

    What is the common approach on this? Shouldn't be to hard?

    BTW: Is there any graphic explaining when is which method called in strategies and indicators? Like the ASP.net page life cylce here: http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx. That would be very very helpful for new developers!

    For my experience: I'm new to NinjaTrader and automated trading, a bit experienced in the FX trading and well experienced in software development. Just that you know what I know

    Thanks!

    #2
    Ok, sorry, wrong forum, could please move this to "Strategy Development"?

    Comment


      #3
      It doesn't sound hard.


      Can you post the code in question?

      It will be easier to debug and point out errors, without guessing 1,000 different guesses as to what you might have coded.




      Originally posted by FxPredator View Post
      Hi guys,

      I am trying to solve a simple task in developing a strategy and can't figure out the correct way:

      As long as an order is online I want to update the stop loss order every day to the low of the previous day. This is not possible if I call the SetStopLoss in the initialize method but it doesn't work as expected if I call it in OnBarUpdate.

      What is the common approach on this? Shouldn't be to hard?

      BTW: Is there any graphic explaining when is which method called in strategies and indicators? Like the ASP.net page life cylce here: http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx. That would be very very helpful for new developers!

      For my experience: I'm new to NinjaTrader and automated trading, a bit experienced in the FX trading and well experienced in software development. Just that you know what I know

      Thanks!

      Comment


        #4
        Sure but as I don't know where exactly to set the SetStopLoss or to send an order by myself this is pretty basic, thats why I didn't post it it the first place. But anyway, here we go:

        The indicator gives my a signal to buy and I buy - that works well. But how to manage a stop loss by my own rule (like I said, as example always on the low of the previous day but just if the previous low is higher than the currently active stop loss).

        Code:
        private IOrder entry = null;
        
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
        }
        
        protected override void OnBarUpdate()
        {	
            var indicator = FxPMacdCross();
            if (indicator.FxPSignal[0] == 1)
            {
                EnterLongStop(High[0]);
            }
        }

        Comment


          #5
          It looks like there is a lot of work to be done.

          What time frame is your chart?

          I'm guessing it probably isn't a daily chart?....

          Have you read up on multi time frame stuff?

          and using Add?



          Originally posted by FxPredator View Post
          Sure but as I don't know where exactly to set the SetStopLoss or to send an order by myself this is pretty basic, thats why I didn't post it it the first place. But anyway, here we go:

          The indicator gives my a signal to buy and I buy - that works well. But how to manage a stop loss by my own rule (like I said, as example always on the low of the previous day but just if the previous low is higher than the currently active stop loss).

          Code:
          private IOrder entry = null;
          
          protected override void Initialize()
          {
              CalculateOnBarClose = true;
          }
          
          protected override void OnBarUpdate()
          {	
              var indicator = FxPMacdCross();
              if (indicator.FxPSignal[0] == 1)
              {
                  EnterLongStop(High[0]);
              }
          }

          Comment


            #6
            Originally posted by sledge View Post
            It looks like there is a lot of work to be done.
            Why? And I'm happy to do it I just don't really know where to set what.

            Originally posted by sledge View Post
            What time frame is your chart?

            I'm guessing it probably isn't a daily chart?....
            Yes it is a daily chart but does that matter?

            Originally posted by sledge View Post
            Have you read up on multi time frame stuff?

            and using Add?
            Yes and yes and I don't see the connection here, why is that important? I don't want to use multi time (at the beginning) and Add is for adding plots?

            Oh and I just started yesterday, could be that I missed something somewhere.

            But all I want to achieve is that after entering a position a stop loss order is set below the latest bar and every day a check runs like this:
            1. No position open? - Don't do anything
            2. Is stop loss higher than the previous bar low (if we are long)? - Don't do anything
            3. Previous bar low is higher than current active stop loss? - Update the stop loss to previous bar low (because price increased)

            Comment


              #7
              So, manual entry with strategy automation exit?


              I don't think that's possible...

              *NT support needs to confirm this..

              Originally posted by FxPredator View Post
              Why? And I'm happy to do it I just don't really know where to set what.



              Yes it is a daily chart but does that matter?



              Yes and yes and I don't see the connection here, why is that important? I don't want to use multi time (at the beginning) and Add is for adding plots?

              Oh and I just started yesterday, could be that I missed something somewhere.

              But all I want to achieve is that after entering a position a stop loss order is set below the latest bar and every day a check runs like this:
              1. No position open? - Don't do anything
              2. Is stop loss higher than the previous bar low (if we are long)? - Don't do anything
              3. Previous bar low is higher than current active stop loss? - Update the stop loss to previous bar low (because price increased)

              Comment


                #8
                Actually everything should be fully automated, sorry if I didn't explain it well. I'm not going to enter trades manually, everything should be done by the strategy I'm creating.

                Comment


                  #9
                  FxPredator, for working the stops into the script and managing them dynamically as new bars form I would suggest checking into this example - http://www.ninjatrader.com/support/f...ead.php?t=3222

                  There are more advanced ways to trigger stop / target submissions giving you ever more control, but starting out the Set()'s would be more convenient to work with code wise.
                  BertrandNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by merzo, 06-25-2023, 02:19 AM
                  10 responses
                  823 views
                  1 like
                  Last Post NinjaTrader_ChristopherJ  
                  Started by frankthearm, Today, 09:08 AM
                  5 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  43 views
                  0 likes
                  Last Post jeronymite  
                  Started by yertle, Today, 08:38 AM
                  5 responses
                  16 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by adeelshahzad, Today, 03:54 AM
                  3 responses
                  19 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X