Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Failed to call method 'Initialize' for strategy '

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

    Failed to call method 'Initialize' for strategy '

    I get the following error after reloading my NInja script or changing the number of days that I have on the chart.

    Failed to call method 'Initialize' for strategy 'XXXXX': 'TickSize' property can not be accessed from within 'Initialize' Method.

    When i first load the strategy to the chart, it works fine, however if I reload Ninja script or change the number of days loaded, from 15 to 30 day, then i get the error, and cannot run the strategy on the chart, and have to load a new chart. Any ideas as to why this may be?

    #2
    Please move the call to TickSize out of the Initialize() method of your strategy and then retry - http://ninjatrader.com/support/helpG...7/ticksize.htm

    Comment


      #3
      This is my initialise statements. While it generates that error, it is normally not related to the message.

      SetStopLoss(
      "", CalculationMode.Ticks, 56, false);
      TimeInForce = Cbi.TimeInForce.Day;
      EntriesPerDirection =
      2;
      CalculateOnBarClose =
      true;
      period1 =
      10;
      period2 =
      20;
      trend =
      new DataSeries ( this);
      macd = MACD (Input,
      8, 13, 5);
      macd.Input = Input;
      CalculateOnBarClose =
      true;

      Add(StrategyPlot(
      0));
      Add(StrategyPlot(
      1));
      Add(StrategyPlot(
      2));
      Add(StrategyPlot(
      3));
      // Set the color for the indicator plots
      StrategyPlot(0).Plots[0].Pen.Color = Color.Green;
      StrategyPlot(
      0).Plots[0].Pen.Width = 3;
      StrategyPlot(
      1).Plots[0].Pen.Color = Color.Gray;
      StrategyPlot(
      2).Plots[0].Pen.Color = Color.Red;
      StrategyPlot(
      3).Plots[0].Pen.Color = Color.Green;
      // Set the panel which the plots will be placed on. 1 = price panel, 2 = panel under the price panel, etc.
      StrategyPlot(0).PanelUI = 2;
      StrategyPlot(
      1).PanelUI = 2;
      StrategyPlot(
      2).PanelUI = 2;
      StrategyPlot(
      3).PanelUI = 3;
      StrategyPlot(
      3).Name = "Cum profit";
      StrategyPlot(
      0).Name = "ZeroLine";
      StrategyPlot(
      1).Name = "Gain";
      StrategyPlot(
      2).Name= "Loss";
      StrategyPlot(
      0).Plots[0].Min = 0;
      StrategyPlot(
      2).Plots[0].Max = 0;

      Comment


        #4
        This line may be problematic: macd = MACD (Input, 8, 13, 5);

        There is no bars yet so no Input. Please move that along with the other macd.Input line to OnStartUp().
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I've got the same error,
          Code:
          **NT** Failed to call method 'Initialize' for strategy XXXXX: Object reference not set to an instance of an object.
          when trying to backtest a strategy.

          Through trail and error I've found the problem in the SetTrailStop command. When I use
          Code:
          [FONT=Courier New][SIZE=1]
          [SIZE=1][FONT=Courier New]SetTrailStop(CalculationMode.Price, Bollinger([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]14[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]).Middle[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]]);[/SIZE][/FONT]
          [/SIZE][/FONT]
          I get the error mentioned above.

          If I change it to:
          Code:
          [FONT=Courier New][SIZE=1]
          [SIZE=1][FONT=Courier New]SetTrailStop(CalculationMode.Ticks, [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]25[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]);[/SIZE][/FONT]
          [/SIZE][/FONT]
          It does work. And if I move the SetTrailStop from the Intialize() section to the OnBarUpdate() section I don't get an error, but it doesn't work in either case.

          I doubt it if this is some kind of bug, so I must be doing something pretty stupid. Can someone suggest me what I'm doing wrong?

          Comment


            #6
            J_o_s, please just set to a static value in the Initialize() and then move the dynamic call based on the Bollinger value to the OnBarUpdate(), then recheck.

            Comment


              #7
              Thanks for your quick reply Bertrand.
              Originally posted by NinjaTrader_Bertrand View Post
              (..)
              Hm, that works partially. I don't get anymore an error, but the stops aren't being triggerd.

              I've also tried to use the "SamplePriceModification" on the forum, but without succes. A little bit wierd if I may say so.

              This is what I've done:
              1. Imported the SamplePriceModification,
              2. Changed in the code the point at which the stoploss goes to breakeven from 50 points to 10 points (otherwise it would be hard to spot; notice I didn't change anything else).
              3. Run a backtest with this strategy.
              4. Inspected the graph for any exits; I could find none.

              Please see the attached screenshot. There is a buy order @ 2727, en the trade get exits at the stoploss @ 2707. If I'm correct this shouldn't happen according to this code snippet from SamplePriceModification:
              Code:
              [FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000]// If a long position is open, allow for stop loss modification to breakeven[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] (Position.MarketPosition == MarketPosition.Long)[/SIZE][/FONT]
              [SIZE=1][FONT=Courier New]{[/FONT][/SIZE]
              [/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000]// Once the price is greater than entry price+10 ticks, set stop loss to breakeven[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] (Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]] > Position.AvgPrice + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]10[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] * TickSize)[/SIZE][/FONT]
              [SIZE=1][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=1][FONT=Courier New]SetStopLoss(CalculationMode.Price, Position.AvgPrice);[/FONT][/SIZE]
              [SIZE=1][FONT=Courier New]}[/FONT][/SIZE]
              [SIZE=1][FONT=Courier New]}[/FONT][/SIZE]
              [/SIZE][/FONT]
              Honestly, it doesn't matter a lot if SamplePriceModification doesn't work, because I won't trade with it. However, if I try to use the Bollinger Middle band as a trailing stop loss, those doesn't get triggered either.

              Here's what I've done in that context:
              Code:
              [FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000]// Variables[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#008000]
              [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] tickStop = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]10000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]; [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000]// i.e. 10 points[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
              Code:
              [FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] Initialize()[/SIZE][/FONT]
              [SIZE=1][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=1][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1];[/SIZE][/FONT]
               
              [SIZE=1][FONT=Courier New]SetTrailStop(CalculationMode.Price, tickStop);[/FONT][/SIZE]
              [SIZE=1][FONT=Courier New]}[/FONT][/SIZE]
               
              [/SIZE][/FONT]
              and:
              Code:
              [FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] OnBarUpdate()[/SIZE][/FONT]
              [SIZE=1][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=1][FONT=Courier New][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]( Position.MarketPosition == MarketPosition.Long)[/SIZE][/FONT]
              [SIZE=1][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=1][FONT=Courier New]tickStop = Close[[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]] + Bollinger([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]14[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]).Middle[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]];[/SIZE][/FONT]
              [SIZE=1][FONT=Courier New]}[/FONT][/SIZE]
              [/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] (Position.MarketPosition == MarketPosition.Short)[/SIZE][/FONT]
              [SIZE=1][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=1][FONT=Courier New]tickStop = Bollinger([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]14[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]).Middle[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]] - Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]];[/SIZE][/FONT]
              [SIZE=1][FONT=Courier New]}[/FONT][/SIZE]
              [/SIZE][/FONT][/FONT][/SIZE][/SIZE][/FONT]
              What am I doing wrong?

              Regards,
              Attached Files

              Comment


                #8
                Please set a default stop loss value in the Initialize() and reset to this value when flat as in the sample, then set the dynamic Bollinger value in your OnBarUpdate() conditions...SetStopLoss(CalculationMode.Price, Bollinger(2, 20).Middle[0])

                Comment


                  #9
                  Originally posted by NinjaTrader_Bertrand View Post
                  Please set a default stop loss value in the Initialize() and reset to this value when flat as in the sample, then set the dynamic Bollinger value in your OnBarUpdate() conditions...SetStopLoss(CalculationMode.Price, Bollinger(2, 20).Middle[0])
                  Thanks a lot, it works now!

                  In case someone else finds this thread and have the same error/problem, here's what happened:

                  I made a thinking error when creating a trailing stop loss. I've thought I had to use SetTrailStop() in the OnBarUpdate() section. That's not correct, because a SetStopLoss() in the OnBarUpdate() section will be in effect a trailing stop loss, because it is updated every bar.

                  So the code then becomes in the OnBarUpdate() section:
                  Code:
                  [FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000]// Reset the stoploss when all positions are closed[/COLOR][/SIZE][/FONT]
                  [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] (Position.MarketPosition == MarketPosition.Flat)[/SIZE][/FONT]
                  [SIZE=1][FONT=Courier New]{[/FONT][/SIZE]
                  [SIZE=1][FONT=Courier New]SetStopLoss(CalculationMode.Price, Bollinger([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]14[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]).Middle[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]]);[/SIZE][/FONT]
                  [SIZE=1][FONT=Courier New]}[/FONT][/SIZE]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000][FONT=Courier New][SIZE=1][COLOR=#008000]// Modify the stoploss when there is an open position[/COLOR][/SIZE][/FONT]
                  [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] (Position.MarketPosition == MarketPosition.Long || Position.MarketPosition == MarketPosition.Short)[/SIZE][/FONT]
                  [SIZE=1][FONT=Courier New]{[/FONT][/SIZE]
                  [SIZE=1][FONT=Courier New]SetStopLoss(CalculationMode.Price, Bollinger([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]14[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]).Middle[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]]);[/SIZE][/FONT]
                  [SIZE=1][FONT=Courier New]}[/FONT][/SIZE][/SIZE][/FONT]
                  Once again, thanks Bertrand!

                  Regards,

                  Comment


                    #10
                    SetStopLoss("", CalculationMode.Ticks, 56, false);I have removed that line also from my initialise, and it seems to work fine now. Strange that is takes it first, however when the script is rerun on the chart due to data range change or reloading script, it then fails. Should have warned me from first run.

                    Comment


                      #11
                      Thanks for reporting back richa61416 - will check into this behavior here.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      596 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      343 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      103 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      556 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      554 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X