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

Moving Stops and Limit Orders

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

    Moving Stops and Limit Orders

    Question. When I have any strategy set to CalculateOnBarClose = false; After that strategy takes a trade; if I try to Move the Stops Manually it automatically moves it back to where it was.

    I've tried to set the Stops (FirstTickOfBar) Only. and that still didn't help. Any way to fix this?

    I know for a fact that CalcOnBarClose = true; you can manually Move the Stops.

    #2
    Hello ginx10k,

    If the order is moving back its because your is likely continuously setting the price of this order.

    Try adding a print of the current time (DateTime.Now) one line above anywhere the order is being set or changed.

    Are you seeing many prints? Is the print continuously updating to the current time?

    (To answer you question, yes you can manually move a trade made by a NinjaScript Strategy. But the Strategy will take precedence. The strategy will also be unaware of any changes or orders you manually make.)
    Last edited by NinjaTrader_ChelseaB; 09-22-2015, 08:23 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I did as you said, and it's NOT continuously updating to current time. My script looks like this
      Code:
      if( FirstTickOfBar && Position.MarketPosition != MarketPosition.Long &&  Close[1] > Open[1] && (Volume[1] > Volume[2]) 
      	//BUY Entry I: Buy Order set few ticks above Close of Up-Bad
      						EnterLongStop(scalpLotSize, Close[1] + ((entryTrigDist + roundedSpread ) * TickSize), "buyTradeA");
      					//STEP 2: Take Profit
      						SetProfitTarget("buyTradeA", CalculationMode.Price,  Close[1] + ( profitTarget * TickSize));
      					//STEP 3: STOP LOSS
      						SetStopLoss("buyTradeA", CalculationMode.Price, Low[1] - (stopLoss * TickSize), false); 
      						
      						Print(DateTime.Now.ToString() + "Stop Moved Automatically DG ");
      
      //Then where the Stop gets Trailed, looks like this
      	if(Position.MarketPosition == MarketPosition.Long && FirstTickOfBar )
      				{	
      					if(Close[1] > Open[1])
      					{
      						//STEP 1: Set Stop Loss at Previous Bar's Open
      							SetStopLoss("buyTradeA", CalculationMode.Price, Low[1] - ( (roundedSpread + stopLoss )* TickSize), false); 
      							SetStopLoss("buyTradeR", CalculationMode.Price, Low[1] - ( (roundedSpread + stopLoss )* TickSize), false); 
      						//STEP 2: PROFIT Target Updates
      							SetProfitTarget("buyTradeA", CalculationMode.Price, Position.AvgPrice + ( profitTarget * TickSize));
      							SetProfitTarget("buyTradeR", CalculationMode.Price, Position.AvgPrice + ( profitTarget * TickSize));
      						
      						Print(DateTime.Now.ToString());
      					}
      				
      				}
      Notice how I set Only to Move on FIRSTTICKOFBAR. and yet, when I move Stop manually Strategy Amends the order. Output window is showing this.

      So since I already set to FirstTickOfBar. and there is nothing in the code that will automatically Move the Stop unless FirstTickOfBar. could there be another way to fix this?

      Comment


        #4
        Hi ginx10k,

        Can I view the entire script and test to ensure that there is not other code that may be in play?

        Or I would recommend starting with a new blank file. Make a single entry and protect this with a StopLoss that is set in OnStartUp() not OnBarUpdate(). This would be a starting point to start adding code to find out what is modifying the order.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          The file is attached. please check it out. let me know. thanks for your support
          Attached Files

          Comment


            #6
            By The Way. this is For RANGE Bars. Do EUR/USD or USD/CAD 20 Tick Range. Using "TenthOfAPip" Setting.

            Comment


              #7
              Hello ginx10k,

              I found some clarification on this.
              http://ninjatrader.com/support/forum....php?t=36309#2

              NinjaTrader is modifying the stop loss after each tick back to the price the stop loss is set to.

              To get around this you can set this up to use AtmStrategyMethods and this would allow you to manually adjust the stop loss and profit targets.

              Or instead of using SetStopLoss or SetProfitTarget, use ExitLongStopLimit, ExitShortStopLimit, ExitLongLimit, and ExitShortLimit.

              Using an Exit command is not updated on each new tick the way SetStopLoss is.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Okay, but Now Spread Question

                Okay. understood. One More QUestion. For the exact Strategy that I uploaded. Notice how all my orders have
                Code:
                ( (roundedSpread + stopLoss )* TickSize)
                The RoundedSpread or Spread. How come when the actual strategy Triggers any order, they NEVER included the spread which I've already set.

                Can you check this please

                Comment


                  #9
                  Hello ginx10k,

                  Use prints and traceorders.

                  In Initialize():
                  Code:
                  TraceOrders = true;
                  Where your exit is being placed:
                  Code:
                  double stopPrice =  (roundedSpread + stopLoss ) * TickSize;
                  
                  Print(stopPrice);
                  
                  SetStopLoss(CalculationMode.Price, stopPrice);
                  or
                  ExitLongStop(stopPrice, "exitOrderSignalName", "entryOrderFromEntrySignalName");
                  Then please post the output from the output window.
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by knowmad, Today, 03:52 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post knowmad
                  by knowmad
                   
                  Started by tradingnasdaqprueba, Today, 03:42 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Started by Haiasi, 04-25-2024, 06:53 PM
                  4 responses
                  63 views
                  0 likes
                  Last Post effraenk  
                  Started by ccbiasi, 11-23-2017, 06:06 AM
                  5 responses
                  2,202 views
                  0 likes
                  Last Post leodavis  
                  Started by kujista, Yesterday, 12:39 AM
                  2 responses
                  14 views
                  0 likes
                  Last Post kujista
                  by kujista
                   
                  Working...
                  X