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

Why isnt this working? Stoploss..

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

    Why isnt this working? Stoploss..

    Code:
            private void GoLong()
            {
                SetStopLoss("stop1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);        
                EnterLong(DefaultQuantity,"");
            }
            
            private void ManageOrders()
            {
                if (Position.MarketPosition == MarketPosition.Long)
                {
                    if (High[0] > Position.AvgPrice + (Target1*TickSize))
                        SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
                }        
    
    
            }
    tracelog:

    Code:
    5/31/2013 9:37:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='stop1' Mode=Price Value=1645.25 Currency=0 Simulated=False
    5/31/2013 9:37:00 AM Entered internal PlaceOrder() method at 5/31/2013 9:37:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
    as you can see from tracelog that the original stoploss is being set. but when manageorder() is kicked in, the stoploss is not being calculated correctly, for some reason the stoploss is being set to ZERO!

    manageorder() is placed in OnBarUpdate() and I get the same results if i set COBC true/false

    #2
    Hello calhawk01,

    Thank you for your post.

    The TraceLog you provided shows the stop placed at 1645.25 and an order to buy at market after that.

    Does your TraceLog show the Stop Loss set to 0? If so please provide this line in your response.

    Comment


      #3
      The tracelog that I provided above has two lines. Look at the second line and you will see the stoploss being set to zero.

      Golong() sets my initial stoploss. This stoploss is behaving as expected.

      Manageorder() sets my second stoploss when market conditions change. This stoploss is not behaving as expected. As you can see the stoploss is being set at zero in the second line for the tracelog I provided.

      What I'm trying to do is (for the past three weeks):
      Enter the market with my initial stoploss (golong()) then when high[0] is larger than target1 I want to change my stoploss to entry price (manageorder())

      Comment


        #4
        Hello calhawk01,

        Thank you for your response.

        The first line in your TraceLog is the submission of your StopLoss:
        Originally posted by calhawk01 View Post
        5/31/2013 9:37:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='stop1' Mode=Price Value=1645.25 Currency=0 Simulated=False
        The second line from your TraceLog is the submission of your EnterLong:
        Originally posted by calhawk01 View Post
        5/31/2013 9:37:00 AM Entered internal PlaceOrder() method at 5/31/2013 9:37:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
        The lines above are from the lines of code below (not the ManageOrders() method):
        Code:
        private void GoLong()
                {
                    SetStopLoss("stop1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);        
                    EnterLong(DefaultQuantity,"");
                }
        You can use a Print() statement after the if condition to adjust your StopLoss to see if the condition is truly being returned true:
        Code:
               private void ManageOrders()
                {
                    if (Position.MarketPosition == MarketPosition.Long)
                    {
                        if (High[0] > Position.AvgPrice + (Target1*TickSize))
                            {
                            [B][U]Print("High is greater than target - adjust Stop Loss.");[/U][/B]
                            SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
                    }
        Please let me know if you have any questions.

        Comment


          #5
          I just tried what you said. Manageorder() seems to never kick in even though it should. my target 1 is 5 ticks and the market went up 15 points and came down to my entry price but manageorder stoploss never kicked in..and i never exited the position until end of the day.

          can you see anything wrong with the above manageorder() statement??

          Comment


            #6
            Hello calhawk01,

            Thank you for your response.

            I see no items with the method itself, can you send me your strategy code or a toy version with the methods for entry and order management to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 855678' in the subject line?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by pibrew, Today, 06:37 AM
            0 responses
            0 views
            0 likes
            Last Post pibrew
            by pibrew
             
            Started by rbeckmann05, Yesterday, 06:48 PM
            1 response
            12 views
            0 likes
            Last Post bltdavid  
            Started by llanqui, Today, 03:53 AM
            0 responses
            6 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by burtoninlondon, Today, 12:38 AM
            0 responses
            10 views
            0 likes
            Last Post burtoninlondon  
            Started by AaronKoRn, Yesterday, 09:49 PM
            0 responses
            15 views
            0 likes
            Last Post AaronKoRn  
            Working...
            X