Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help building strategy

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

    #16
    Originally posted by koganam View Post
    What is the error in your log?

    I expect it to say: "You are accessing an index with a value that is invalid since its out of range ...", in which case you need to escape your first bar.

    In which case, I would suggest that you look at my response in this tread.

    ref: http://www.ninjatrader.com/support/f...ape+currentbar
    I actually double checked and the TraceOrder was already set to true. This is the Output message I get:
    11/27/2012 6:00:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=0 Currency=1.301 Simulated=False
    11/27/2012 6:00:00 AM Entered internal PlaceOrder() method at 11/27/2012 6:00:00 AM: BarsInProgress=1 Action=SellShort OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.2968 SignalName='' FromEntrySignal=''
    check the chart attached, according to me there is something wrong in my code, on this trade the stategy would clearly have done money, whilst NT is telling me I am stopped out
    Attached Files

    Comment


      #17
      Originally posted by sburtt View Post
      I actually double checked and the TraceOrder was already set to true. This is the Output message I get:


      check the chart attached, according to me there is something wrong in my code, on this trade the stategy would clearly have done money, whilst NT is telling me I am stopped out
      Check your code. That looks like your StopLoss was placed at Close[0] when the trade was entered.

      If that is not the case, you may have a corrupt Database. Repair the Database, and restart NT, then try again. I presume that you are seeing this in Backtest? At least, that is what the picture suggests.
      Last edited by koganam; 02-26-2013, 02:28 PM.

      Comment


        #18
        Yes this is a backtrsting result. The code is the one you read below in the previous post, i've simply copied and pasted it. I've tried running it on a virtual machine, hence a separate database and the result is the same. What if i send you the cs file via message and you try running it on your machine? Would it be asking to much?

        Comment


          #19
          Originally posted by sburtt View Post
          Yes this is a backtrsting result. The code is the one you read below in the previous post, i've simply copied and pasted it. I've tried running it on a virtual machine, hence a separate database and the result is the same. What if i send you the cs file via message and you try running it on your machine? Would it be asking to much?
          I can do that for you.

          Comment


            #20
            check your email inbox, let me know if haven't received it

            Comment


              #21
              Originally posted by sburtt View Post
              check your email inbox, let me know if haven't received it
              I have got it, and I do not see how your Strategy can run at all. I asked you what the error is in your log. After we resolve those questions, I will see about loading the Strategy onto my test system.

              Comment


                #22
                Originally posted by koganam View Post
                I have got it, and I do not see how your Strategy can run at all. I asked you what the error is in your log. After we resolve those questions, I will see about loading the Strategy onto my test system.
                I am not sure I know what your referring to, however if you are referring to the Log tab on the right side of the Control Center, I don't see any error. see the attached screenshot
                Attached Files

                Comment


                  #23
                  Is this the information your asking for?

                  Comment


                    #24
                    Hello sburtt,

                    Viewing your your Output window and the place that you expected your stop loss to be set at, it appears that you would like to set the Stop Loss at an absolute price. If that is the case then you may try to change your stop loss to: SetStopLoss(CalculationMode.Price, High[0]+TickSize);
                    JCNinjaTrader Customer Service

                    Comment


                      #25
                      Originally posted by NinjaTrader_JC View Post
                      Hello sburtt,

                      Viewing your your Output window and the place that you expected your stop loss to be set at, it appears that you would like to set the Stop Loss at an absolute price. If that is the case then you may try to change your stop loss to: SetStopLoss(CalculationMode.Price, High[0]+TickSize);
                      that made the trick, thanks

                      Comment


                        #26
                        Originally posted by koganam View Post
                        I have got it, and I do not see how your Strategy can run at all. I asked you what the error is in your log. After we resolve those questions, I will see about loading the Strategy onto my test system.
                        Hey Koganam, the CalculationMode was what I was missing in SetStopLoss(CalculationMode.Price, High[0]+TickSize) to make it work properly. Anyhow I sent you the strategy, are you still interested in helping me out on how to code the trailing stop loss?

                        Thanks guys

                        Comment


                          #27
                          Hello sburtt,

                          The SetTrailingStop() would be setup a similar way but you would only be able to use a Calculation mode of Ticks or Percent since it will be automatically moved when the price moves in the direction of your trade.

                          You may also modify your SetStopLoss() when your specific conditions are met as well. For an example of this you may view the following thread.
                          JCNinjaTrader Customer Service

                          Comment


                            #28
                            Originally posted by NinjaTrader_JC View Post
                            Hello sburtt,

                            The SetTrailingStop() would be setup a similar way but you would only be able to use a Calculation mode of Ticks or Percent since it will be automatically moved when the price moves in the direction of your trade.

                            You may also modify your SetStopLoss() when your specific conditions are met as well. For an example of this you may view the following thread.
                            http://www.ninjatrader.com/support/f...ead.php?t=3222
                            JC I'm trying to trail a stop that hasn't a fix % value (or tick value) for all trades, but rather changes each time based on the risk I am willing to take. Let's assume I define the risk (R) per each trade in the following way: R = High[0]-Low[0]. We could also define R in %terms in this way R = High[0] / Low[0] -1

                            Given what you mention above how could I create a trailing stop that starts only after the close of 3rd candle based on R?

                            would something like this work:
                            Code:
                            protected override void OnBarUpdate() 
                            { 
                               if (Position.MarketPosition == MarketPosition.Flat) 
                                                      { 
                                        if (*condition*)
                                           {                                 
                                              SetStopLoss(CalculationMode.Price,High[0]); 
                                              EnterLong();
                                            }
                                      }
                                            double  R = (High[0] / Low[0] - 1);
                            
                               else if(Position.MarketPosition == MarketPosition.Long 
                                          && BarsSinceEntry() >= 3
                                          &&  Position.GetProfitLoss(Close[0], PerformanceUnit.Percent) > R)    
                                                {
                                                    SetTrailStop(CalculationMode.Percent, Position.AvgPrice + R);    
                                                 }
                                  }

                            Comment


                              #29
                              Originally posted by sburtt View Post
                              Hey Koganam, the CalculationMode was what I was missing in SetStopLoss(CalculationMode.Price, High[0]+TickSize) to make it work properly. Anyhow I sent you the strategy, are you still interested in helping me out on how to code the trailing stop loss?

                              Thanks guys
                              I noted the CalculationMode matter. Unfortunately, I do not trade currencies, and so I do not have any historical data, nor could I manage to acquire any. I finally decided to test your strategy using data for IBM.

                              Well, if you have managed to resolve the matter of handling the Stop, then I guess that does it for now.

                              Comment


                                #30
                                Originally posted by sburtt View Post
                                JC I'm trying to trail a stop that hasn't a fix % value (or tick value) for all trades, but rather changes each time based on the risk I am willing to take. Let's assume I define the risk (R) per each trade in the following way: R = High[0]-Low[0]. We could also define R in %terms in this way R = High[0] / Low[0] -1

                                Given what you mention above how could I create a trailing stop that starts only after the close of 3rd candle based on R?

                                would something like this work:
                                Code:
                                protected override void OnBarUpdate() 
                                { 
                                   if (Position.MarketPosition == MarketPosition.Flat) 
                                                          { 
                                            if (*condition*)
                                               {                                 
                                                  SetStopLoss(CalculationMode.Price,High[0]); 
                                                  EnterLong();
                                                }
                                          }
                                                double  R = (High[0] / Low[0] - 1);
                                 
                                   else if(Position.MarketPosition == MarketPosition.Long 
                                              && BarsSinceEntry() >= 3
                                              &&  Position.GetProfitLoss(Close[0], PerformanceUnit.Percent) > R)    
                                                    {
                                                        SetTrailStop(CalculationMode.Percent, Position.AvgPrice + R);    
                                                     }
                                      }
                                What you are describing sounds more like you are manually trailing a Stop. In which case your construct should be:
                                Code:
                                 SetStopLoss(CalculationMode.Percent, R);
                                i.e., you need to be moving your hard Stop, not resetting a TrailingStop. If you still prefer the double whammy of a manually trailed, trailing stop, you would still need to use only "R" as your percent value.

                                Comment

                                Latest Posts

                                Collapse

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