Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to Create a Strategy Using Custom Indicators

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

    Trying to Create a Strategy Using Custom Indicators

    Hello,

    I am trying to create a strategy using my custom indicators in order to run some basic backtests.

    My indicators are based on conditional statements, and when they are met then the current bar is marked with a diamond above or below the bar depending on if it is a buy or sell signal.

    Basically, the strategy I want to build would backtest potential trades as follows:
    I will use a Black Sell as the example (a black diamond above the current bar).

    1) When Black Sell is true, then

    2) Enter a (short) limit order at (bottom of current bar - 1tick) ( Low[0]-(TickSize*1))

    3) The profit target, or exit, would be 5 for this example: (Low[0]-(TickSize*5))

    4) The Stop out would be (High(0)+(TickSize*1)

    If price never hits the entry point before the stop is hit, then nothing happens in regards to trade entry and nothing is recorded.


    Is it possible to use the Strategy Wizard in order to create this strategy, or would this be an advanced scripting project?

    #2
    As always, thank you in advance

    Comment


      #3
      vern13, depending on how the black diamond indicator indicates the condition, it could be possible to do this in the Strategy Wizard. If the only thing it does is draws a diamond, then it probably isn't possible to add in the Strategy Wizard unless you add some extra code in the indicator itself to show when a diamond occurs.

      Do you have the source code for the black diamond indicator? If so, please try editing it so it also sets a plot to 1 when a diamond is drawn for a long position, -1 for a short, and 0 for no signal. You can then reference this plot and when plot = 1, go long, or when it is -1, go short.

      As for the actual trade conditions, you can do those in the Wizard without a problem.
      AustinNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Austin View Post
        vern13, depending on how the black diamond indicator indicates the condition, it could be possible to do this in the Strategy Wizard. If the only thing it does is draws a diamond, then it probably isn't possible to add in the Strategy Wizard unless you add some extra code in the indicator itself to show when a diamond occurs.

        Do you have the source code for the black diamond indicator? If so, please try editing it so it also sets a plot to 1 when a diamond is drawn for a long position, -1 for a short, and 0 for no signal. You can then reference this plot and when plot = 1, go long, or when it is -1, go short.

        As for the actual trade conditions, you can do those in the Wizard without a problem.
        Here is the source code for the conditions needed to achieve a Black Sell as I have them programmed into the ninjascript:

        Plot0.Set(if(CurrentBar<3)return;if((High[1]<High[3])&&(Close[1]<Close[2])) DrawDiamond("tag1" + CurrentBar.ToString(),true,0,High[0]+(TickSize*50),Color.Black); else RemoveDrawObject("tag1"+CurrentBar.ToString()));
        }


        Comment


          #5
          I just am not sure on where to add the plotting definitions...is that in the ninjascript directly or is that hidden in the strategy wizard somewhere I have missed?

          Comment


            #6
            Vern, does this code actually produce a plot? What are the exact conditions for the black diamond? I can't really decipher what you have here, and I had no idea code like this would function. Please separate it into two (or more, if necessary) statements for clarify, like:
            Code:
            if (CurrentBar<3) return;
            if ((High[1] < High[3]) && (Close[1] < Close[2]))
                DrawDiamond("tag1" + CurrentBar.ToString(),true,0,High[0]+(TickSize*50),Color.Black);
            else RemoveDrawObject("tag1" + CurrentBar.ToString()));
            
            Plot0.Set(....? what goes here);
            The code you currently have in .Set() doesn't return a value, so I'm not sure how this is working right now.
            AustinNinjaTrader Customer Service

            Comment


              #7
              yes, this code produces a black diamond above the signal bar, that appears and dissappears as the conditions are met and then null as the conditions change on a tick by tick basis. If the conditions are met at the bar close, then the black diamond stays.

              Comment


                #8
                I am not an experienced programmer, so I am a bit foggy on what you are asking. Here is the basic breakdown of the script:

                I believe the Plot0.set input is Plot0.Set(if(CurrentBar<3)return;


                Exact conditions for the BlackSell: if((High[1]<High[3])&&(Close[1]<Close[2]))

                The plotting script:
                DrawDiamond("tag1" + CurrentBar.ToString(),true,0,High[0]+(TickSize*50),Color.Black);

                The Tick by Tick updating script:

                else RemoveDrawObject("tag1"+CurrentBar.ToString()));

                The script does function rather well, I have checked vs my other charting platform for accuracy in live conditions. I hope this is what you are asking.

                Comment


                  #9
                  This is exactly what I'm looking for. I'll take a look here shortly.
                  AustinNinjaTrader Customer Service

                  Comment


                    #10
                    ok, thank you

                    Comment


                      #11
                      Originally posted by vern13 View Post
                      I am not an experienced programmer, so I am a bit foggy on what you are asking. Here is the basic breakdown of the script:

                      I believe the Plot0.set input is Plot0.Set(if(CurrentBar<3)return;


                      Exact conditions for the BlackSell: if((High[1]<High[3])&&(Close[1]<Close[2]))

                      The plotting script:
                      DrawDiamond("tag1" + CurrentBar.ToString(),true,0,High[0]+(TickSize*50),Color.Black);

                      The Tick by Tick updating script:

                      else RemoveDrawObject("tag1"+CurrentBar.ToString()));

                      The script does function rather well, I have checked vs my other charting platform for accuracy in live conditions. I hope this is what you are asking.
                      Do you actually see a Plot on your chart?

                      Not the drawn diamonds: an actual plotted line.
                      Last edited by koganam; 07-29-2011, 02:07 PM.

                      Comment


                        #12
                        no, I do not see a plotted line on my chart.

                        Comment


                          #13
                          vern13, it would be easiest by far to just integrate the diamond conditions into the Strategy Wizard and then buy/sell from there. If you would like to use the indicator approach instead, please take a look at my revision of your indicator. I've sorted the code out and set the plot to -1 when a sell signal is present and 0 when no signal is present:
                          Code:
                          protected override void OnBarUpdate()
                          {
                              if (CurrentBar < 3)
                                  return;
                              
                              if ((High[1] < High[3]) && (Close[1] < Close[2]))
                              {
                                  Plot0.Set(-1);
                                  DrawDiamond("my diamond" + CurrentBar.ToString(), false, 0, High[0] + 10 * TickSize, Color.Black);
                              }
                              else
                              {
                                  Plot0.Set(0);
                                  RemoveDrawObject("my diamond" + CurrentBar.ToString());
                              }
                          }
                          You can then reference this indicator in your strategy:
                          Code:
                          if (BlackDiamondSellSignal.Plot0[0] == -1)
                          {
                             EnterShort();
                          }
                          To import the attached indicator, download it to your computer and then in NinjaTrader go to File -> Utilities -> Import NinjaScript -> point it to the file you just downloaded.
                          Attached Files
                          AustinNinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_Austin View Post
                            vern13, it would be easiest by far to just integrate the diamond conditions into the Strategy Wizard and then buy/sell from there. If you would like to use the indicator approach instead, please take a look at my revision of your indicator. I've sorted the code out and set the plot to -1 when a sell signal is present and 0 when no signal is present:
                            Code:
                            protected override void OnBarUpdate()
                            {
                                if (CurrentBar < 3)
                                    return;
                             
                                if ((High[1] < High[3]) && (Close[1] < Close[2]))
                                {
                                    Plot0.Set(-1);
                                    DrawDiamond("my diamond" + CurrentBar.ToString(), false, 0, High[0] + 10 * TickSize, Color.Black);
                                }
                                else
                                {
                                    Plot0.Set(0);
                                    RemoveDrawObject("my diamond" + CurrentBar.ToString());
                                }
                            }
                            You can then reference this indicator in your strategy:
                            Code:
                            if (BlackDiamondSellSignal.Plot0[0] == -1)
                            {
                               EnterShort();
                            }
                            To import the attached indicator, download it to your computer and then in NinjaTrader go to File -> Utilities -> Import NinjaScript -> point it to the file you just downloaded.
                            Hi Austin

                            I am trying to compile this but I am getting an error saying:

                            BlackDiamondSellSignal(int) is a method which is not valid in the current context.

                            I get another error compiling if I try to add
                            Add(BlackDiamondSellSignal) in Initialize().

                            How do you add an indicator to a strategy for this to work?

                            Comment


                              #15
                              Hi again Austin

                              I declared

                              private
                              BlackDiamondSellSignal myBlackDiamondSellSignal;

                              then made the comparison

                              myBlackDiamondSellSignal.Plot0[0] == -1

                              It compiled so I assume that was missing?

                              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