Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting my trailstop on chart

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

    Plotting my trailstop on chart

    Been reading through old forum posts and reference samples and can't seem to find a good example of how to plot the price of my trailing stop loss on my chart.

    It doesn't have to adjust the stop as it gets adjusted...I'd be happy with just a dot or line at the intial stop level. I've looked at the "SampleMonitorStopProfit" Reference sample and hoping I don't have to go that route.

    Would a simple DrawDot or DrawLine statement work if I place it right next to my entry code? I have a calculated variable "TrailStop" that holds a value in ticks.

    I tried the following, but nothing showed up on the chart. Basically I was trying to plot a horizontal line at a level of the high of the most recent bar minus my Trailstop value, and plot the line for 15 bars.

    Code:
    DrawLine("Buy", true, 1, High[0] - TrailStop, 15, High[0] - TrailStop, Color.Red, DashStyle.Dot, 2);
    Syntax for reference from helpfile:
    DrawLine(string tag, bool autoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Color color, DashStyle dashStyle, int width)

    I guess it would be nice if it would plot dots on the chart as the trail stop order is dynamically updated as the market moves. But for starters, just drawing horizontal line at a specific y value on the chart is all I'm trying to accomplish. Is there is a better way to do this? Any help with the code for this is appreciated. Thanks,

    kc

    #2
    Hi kcsystemtrader, you have to consider, if you want a separate line to show up for all your trailing stop levels, please use a unique tag for the DrawText statement, like "Buy" + CurrentBar.

    You could also create a variable like myStopValue that tracks your stop modifications and then you could plot this from the strategy with the help of this tip - http://www.ninjatrader-support2.com/...ead.php?t=6651

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Hi kcsystemtrader, you have to consider, if you want a separate line to show up for all your trailing stop levels, please use a unique tag for the DrawText statement, like "Buy" + CurrentBar.

      You could also create a variable like myStopValue that tracks your stop modifications and then you could plot this from the strategy with the help of this tip - http://www.ninjatrader-support2.com/...ead.php?t=6651
      I tried...

      Code:
       
      Initialize:
      Add(StrategyPlot(0));
      StrategyPlot(0).Plots[0].Pen.Color = Color.Red;
      StrategyPlot(0).PanelUI = 1;
       
      OnBarUpdate:
      StrategyPlot(0).Value.Set(TrailStop);
      And nothing happened. Also tried the following in OnBarUpdate with no luck:

      Code:
       
      DrawLine("Test" + CurrentBar, true, 1, High[0] - TrailStop, 15, High[0] - TrailStop, Color.Red, DashStyle.Dot, 2);

      What am I missing? Thanks

      Comment


        #4
        Hi kcsystemtrader, this looks good if your 'TrailStop' variable holds the needed values for the adjusted trailing stop.

        Do you get any errors in the Log tab of the Control Center when running your code?

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          Hi kcsystemtrader, this looks good if your 'TrailStop' variable holds the needed values for the adjusted trailing stop.

          Do you get any errors in the Log tab of the Control Center when running your code?

          Which one looks good, the StrategyPlot code or the DrawLine code? I am not running a multi-time frame strategy so I modified the StrategyPlot code that was in the reference sample. TrailStop is a double and it is calculated continuously until right before entry. Once a position is entered it holds the TrailStop value in Ticks. Upon exit, it resets the TrailStop and dynamic calculations for new TrailStop values begin again. I had the StrategyPlot code outside the entry condition code thinking it would always be plotting my TrailStop value, whether in a position or not. Only difference would be once in a position, the TrailStop line that would draw on the chart would become static until the position is exited and the calculation logic resumes.

          Did not see any errors in the Log window. I'll keep fooling with the StrategyPlot code because I think that would be better than just a DrawLine. I had the DrawLine code within the entry condition statement so that it would only draw a horizontal line once for a length of 15 bars upon entry. Thanks,

          kc

          Comment


            #6
            Hi kcsystemtrader, it would be great if you could post more code for us, I think the StrategyPlot would be best here for the trail stop display...do you use SetStopLoss and adjust it, or do you use SetTrailStop?

            Please also take a look at this thread, where a trailing stop code was pusblished - http://www.ninjatrader-support2.com/...ad.php?t=10344

            Comment


              #7
              Here is the strategy I am using for testing on 1 minute bars:

              Code:
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] TestPlotStrategy : Strategy[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]#region[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Variables[/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] ATRPeriod = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] ATRvalue;[/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] TrailStop;[/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] ATRMultiple = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]bool[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] definedTrailStop = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
               
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]#endregion[/COLOR][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]Add(ATR(ATRPeriod));[/FONT][/SIZE]
               
              [FONT=Courier New][SIZE=2]Add(StrategyPlot([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]));[/SIZE][/FONT]
              [FONT=Courier New][SIZE=2]StrategyPlot([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]).Plots[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]].Pen.Color = Color.Red;[/SIZE][/FONT]
              [FONT=Courier New][SIZE=2]StrategyPlot([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]).PanelUI = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]TraceOrders = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; [/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; [/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [FONT=Courier New][SIZE=2][COLOR=#008000]//Reset TrailStop calculation upon closing out a position[/COLOR][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Position.MarketPosition == MarketPosition.Flat)[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]definedTrailStop = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [FONT=Courier New][SIZE=2][COLOR=#008000]// Calculations For Stop Loss [/COLOR][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (definedTrailStop == [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{ [/FONT][/SIZE]
              [FONT=Courier New][SIZE=2]ATRvalue = ATR(ATRPeriod)[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] * [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]100[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]//convert to ticks [/COLOR][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2]Print([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"The current ATR value is "[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] + ATRvalue.ToString());[/SIZE][/FONT]
              [FONT=Courier New][SIZE=2]TrailStop = ATRvalue * ATRMultiple;[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]Print([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]"The current TrailStop value is "[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] + TrailStop.ToString());[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]definedTrailStop = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]} [/FONT][/SIZE]
               
              [SIZE=2][FONT=Courier New]Print([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]"The current value for BarsSinceExit is "[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] + BarsSinceExit().ToString());[/SIZE][/FONT]
               
              [SIZE=2][FONT=Courier New]StrategyPlot([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]).Value.Set(TrailStop);[/SIZE][/FONT]
               
              [FONT=Courier New][SIZE=2][COLOR=#008000]//Entry Conditions[/COLOR][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#008000]// Long Entry Condition[/COLOR][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] ((BarsSinceExit() >= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] || BarsSinceExit() == -[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]) [/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]&& Position.MarketPosition != MarketPosition.Short)[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] < Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]])[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]SetTrailStop([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]"Buy"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], CalculationMode.Ticks, TrailStop, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]EnterLong([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]100[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Buy"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#008000]//The next DrawLine statement was also tested without luck[/COLOR][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#008000]//DrawLine("Buy" + CurrentBar, true, 1, High[0] - TrailStop, 15, High[0] - TrailStop, Color.Red, DashStyle.Dot, 2);[/COLOR][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2]}[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
               
              [FONT=Courier New][SIZE=2][COLOR=#008000]// Short Entry Condition[/COLOR][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] ((BarsSinceExit() >= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] || BarsSinceExit() == -[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]) [/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]&& Position.MarketPosition != MarketPosition.Long)[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] > Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]])[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{ [/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]SetTrailStop([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]"Sell"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], CalculationMode.Ticks, TrailStop, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]EnterShort([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]100[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Sell"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]} [/FONT][/SIZE]
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]#region[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Properties[/SIZE][/FONT]
               
              [FONT=Courier New][SIZE=2][COLOR=#0000ff]#endregion[/COLOR][/SIZE][/FONT]
              [FONT=Courier New][COLOR=black]}[/COLOR][/FONT]

              Comment


                #8
                Hi kcsystemtrader, thanks for posting the code. You calculate the trailing stop value in ticks, which is fine for usage in the SetTrailStop method. To display it on the chart however alongside your strategy, you would need to get the trailing stop price value with the correct scaling. You could do this by calculating it (Position.AvgPrice +/- Trailstop in ticks), plot this value and use to update your SetStopLoss order.

                Comment


                  #9
                  Originally posted by NinjaTrader_Bertrand View Post
                  Hi kcsystemtrader, thanks for posting the code. You calculate the trailing stop value in ticks, which is fine for usage in the SetTrailStop method. To display it on the chart however alongside your strategy, you would need to get the trailing stop price value with the correct scaling. You could do this by calculating it (Position.AvgPrice +/- Trailstop in ticks), plot this value and use to update your SetStopLoss order.
                  Maybe I'm not adding the indicator to the chart correctly. I attached a screenshot of the settings for the Indicator StrategyPlot.

                  I changed this line:

                  StrategyPlot(0).Value.Set(TrailStop);

                  to:

                  StrategyPlot(0).Value.Set(Position.AvgPrice + TrailStop);

                  and I'm still not seeing anything on the chart. Any other ideas? Thanks,

                  kc
                  Attached Files

                  Comment


                    #10
                    kcsystemtrader,

                    I have not been following this thread intimiately, but have you checked your Control Center logs for errors?

                    Alternatively, a lot of people trying to do what you are doing just do something like DrawDot() right from the strategy instead of worrying about trying to use StrategyPlot(). StrategyPlot is a limited functionality plotting designed for use with multi-series strategies. It is a workaround for multi-series plotting and has its limitations. For what you are doing I suggest you just use draw objects straight from the strategy. Or you can just create yourself an indicator that uses the same logic as the strategy to properly plot it instead of StrategyPlot.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      I can't even get DrawDot to work. I have yet to see any custom markers/lines drawn on a chart.

                      Is there a strategy or code snippet that is tested that I could import to see what I should be looking for?

                      Comment


                        #12
                        Is there anything else I need to add besides just the DrawDot statement in onbarupdate?

                        Below I'm just trying to draw a red dot 20 ticks below the close

                        DrawDot("stop", true, 0, Close[0] - (20 * TickSize), Color.Red);

                        Comment


                          #13
                          I just tried the following, and still no luck. Any ideas?

                          Code:
                          [SIZE=2][FONT=Courier New][COLOR=#0000ff]#region[/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2] Variables[/SIZE][/FONT]
                          [FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] TrailStop = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                          [FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] TrailStopPlot = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080].2[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                           
                          [FONT=Courier New][SIZE=2][COLOR=#0000ff]#endregion[/COLOR][/SIZE][/FONT]
                          [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                          [SIZE=2][FONT=Courier New]SetTrailStop([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]"Buy"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],CalculationMode.Ticks,TrailStop,[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
                           
                          [SIZE=2][FONT=Courier New]TraceOrders = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; [/SIZE][/FONT]
                           
                          [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; [/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                          [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                          [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] > Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]])[/SIZE][/FONT]
                           
                          [SIZE=2][FONT=Courier New]EnterLong([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]100[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Buy"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
                           
                          [SIZE=2][FONT=Courier New]DrawDot([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]"test dot"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] + CurrentBar,[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],Position.AvgPrice - TrailStopPlot,Color.Red); [/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]} [/FONT][/SIZE]
                          Last edited by kcsystemtrader; 01-09-2009, 01:58 PM.

                          Comment


                            #14
                            kcsystemtrader,

                            It is almost evident that none of your scripts even work. Please try running SampleMACrossOver.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Josh View Post
                              kcsystemtrader,

                              It is almost evident that none of your scripts even work. Please try running SampleMACrossOver.

                              Still no luck. Please see attached screenshot of the chart. I ran a modified SampleMACrossOver, the only changes being I added the DrawDot statements to draw dots 20 ticks above and below the Avg Position price. I don't see any dots once a position is established.

                              Here's the modified code for the OnBarUpdate section of the sample strategy (no changes elsewhere in the strategy). Please see if it works for you. I ran the test on a Market Replay Connection from 1/7 data on AAPL. Thanks

                              Code:
                              [SIZE=2][FONT=Courier New][COLOR=#0000ff]protected[/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
                              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                              [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (CrossAbove(SMA(Fast), SMA(Slow), [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
                              [SIZE=2][FONT=Courier New]EnterLong();[/FONT][/SIZE]
                              [FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (CrossBelow(SMA(Fast), SMA(Slow), [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
                              [SIZE=2][FONT=Courier New]EnterShort();[/FONT][/SIZE]
                               
                              [FONT=Courier New][SIZE=2][COLOR=#008000]//These are the only changes to strategy[/COLOR][/SIZE][/FONT]
                              [FONT=Courier New][SIZE=2]DrawDot([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"test dot"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],Position.AvgPrice - [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]*TickSize,Color.Red); [/SIZE][/FONT]
                              [SIZE=2][FONT=Courier New]DrawDot([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]"test dot"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],Position.AvgPrice + [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]*TickSize,Color.Red); [/SIZE][/FONT]
                               
                              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              671 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X