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

Setu up on indicators

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

    Setu up on indicators

    I have created a file with all my set ups of entry and exit of trades to use in one of my strategies.

    Now, I want to use these same set ups in a Indicator. Is it possible?

    How can I do it ??

    #2
    ocorrea, the main logic would be the same - the indicator would just not enter trades and manage position, so you would need to come up with a different way to visualize the infos / signals then. So what you created now would be an indicator you call in your strategy or is the actual logic all in a strategy file?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I would like to to graph the strategy.

      In my "UserDefinedMehods" in a file separate, I put my set ups to entry and exit with I use in my strategy.

      for exemple:

      {
      partial class Strategy
      {
      public int ECPR23(int C, int M, double LI, double LS, int PROF, int ft)
      { int Key0 = 0;
      if ( Open[0] > SMA(M)[0]
      && Close[0] > Close[5]
      && myLinRegSlope(LI,LS,PROF,M)[0] > LS)
      { Key0 = 1}
      return (Key0);
      }
      .
      .
      .
      public int SCPR23(int C, int M, double LI, double LS, int PROF)
      { int Key0 = 0;
      if( Open[1] < SMA(C)[1]
      && Close[1] < SMA(C)[1]
      && Close[1] < Close[2]
      && SMA(C)[1] < SMA(C)[2]
      && SMA(C)[2] < SMA(C)[3]
      && myLinRegSlope(LI,LS,PROF,C)[1] < myLinRegSlope(LI,LS,PROF,C)[2]
      && myLinRegSlope(LI,LS,PROF,C)[2] < myLinRegSlope(LI,LS,PROF,C)[3]
      )
      { Key0 = 1;}

      return (Key0);
      }
      .
      .
      .
      public int RCPR23(int C, double LI, double LS, int PROF)
      { int Key0 = 0;
      if ( ADX(C)[1] >= 40
      && Close[1] < SMA(C)[1]
      && Close[2] < SMA(C)[2]
      && Close[3] < SMA(C)[3]
      && SMA(C)[1] < SMA(C)[2]
      && SMA(C)[3] < SMA(C)[4]
      && SMA(C)[4] < SMA(C)[5] )
      { Key0 = 1; }
      return (Key0);
      }

      In my indicator I would like to graph the points of entry and exit of the strategy, as follow:

      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.DarkGreen), PlotStyle.TriangleUp, "ECP"));
      Add(new Plot(Color.FromKnownColor(KnownColor.DarkGreen), PlotStyle.TriangleDown, "EVD"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Maroon), PlotStyle.TriangleDown, "SCP"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Firebrick), PlotStyle.TriangleUp, "SVD"));
      Overlay = true;
      }
      protected override void OnBarUpdate()
      {
      if (ECPR23>0){ECP.Set(Open[0] - 2);return;}
      if (EVDR23>0){EVD.Set(Open[0] - 2);return;}
      if (SCPR23>0){SCP.Set(Open[0] - 2);return;}
      if (SVDR23>0){SVD.Set(Open[0] - 2);return;}
      }

      when compiling the indicator are presented these errors:


      NinjaScript File Error Code Line Column
      Indicator\myStrategyTest0.cs O nome 'ECPR23' não existe no contexto atual CS0103 - click for info 44 8
      Indicator\myStrategyTest0.cs O nome 'EVDR23' não existe no contexto atual CS0103 - click for info 45 8
      Indicator\myStrategyTest0.cs O nome 'SCPR23' não existe no contexto atual CS0103 - click for info 46 8
      Indicator\myStrategyTest0.cs O nome 'SVDR23' não existe no contexto atual CS0103 - click for info 47 8

      Comment


        #4
        ocorrea, thanks. There's two user defined method files, one for indicators, one for strategies. It can't find the method you define in the partial strategy base here. So please replicate the custom methods as well in the user defined methods cs for the indicator base class and you should be able to use and compile as expected.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Then I need have two files with set ups? One for strategies and other for Indicators? So I can not use the same for both?

          Comment


            #6
            It should be fine to have them all residing in the indicator file, as the strategies should be able to get those as well.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              It should be fine to have them all residing in the indicator file, as the strategies should be able to get those as well.
              Not unless the objects/methods are marked as static.

              Comment


                #8
                Thanks koganam, you are correct. Looking more into, for the partial classes they would need to be in the same namespace.
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by bmartz, 03-12-2024, 06:12 AM
                4 responses
                31 views
                0 likes
                Last Post bmartz
                by bmartz
                 
                Started by Aviram Y, Today, 05:29 AM
                4 responses
                12 views
                0 likes
                Last Post Aviram Y  
                Started by algospoke, 04-17-2024, 06:40 PM
                3 responses
                28 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by gentlebenthebear, Today, 01:30 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by cls71, Today, 04:45 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X