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

Custom methods...

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

    Custom methods...

    Hi,
    I was trying to find info online and in forums but could not. Is there a way to create custom method similar to DrawArrow...() methods used in Ninja please? Is there example or guidelines Ninja can offer. I'm trying to simplify my program where I'm repeatedly calling DrawArrow/Diamond/Tri...() and such. Is it possible to create a custom method where I could put my if uo... then Draw...up() else Draw...Down() logic and call this method in OnBarUpdate(), e.g.
    if <some cond> ...
    {
    PlotSignals(up, 1,2,3)... //This custom method should have all my DrawArrow/Diamond/Triangle...() logic inside
    }
    else if
    {
    PlotSignals(down, 3,2,1)....
    }
    ....
    Currently I repeatedly calling Draw...() methods in my ifs.
    Thank you very much.
    Art.

    #2
    Art, yes this is possible. You can create your own methods that do whatever you want, so in your example, you could have some helper method called PlotSignals() that draws your objects, like this:
    Code:
    void PlotSignals(string direction, int tickOffset)
    {
        if (direction == "up")
            DrawDot("up dot" + CurrentBar, false, 0, Low[0] - tickOffset, Color.Green);
        else if (direction == "down")
            DrawDot("down dot" + CurrentBar, false, 0, High[0] + tickOffset, Color.Red);
    }
    protected override void OnBarUpdate()
    {
        if (Close[0] > Open[0])
            PlotSignals("up", 2);
        else if (Close[0] < Open[0])
            PlotSignals("down", 2);
    }
    Attached Files
    AustinNinjaTrader Customer Service

    Comment


      #3
      Guys need help.....

      Here is the code I am trying to understand.....
      is This mean if my EMA FAST Crossed Above the EMA Slow Line
      And RSI Period with RSI Smooth -2 Bar from Line 50 Then Buy or Sell? is this possible to work for future trade? as to buy if it crossingabove 50 before 2 bars.

      The all Point is [-2]acts as -2 Bars? The code undertands as I do?

      Can the code understand Line 50 befor 2 Bars?

      if (CrossAbove(EMA(Fast), EMA(Slow), 1)
      && RSI(RSIPeriod, RSISmooth)[-
      2] > 50)
      {
      EnterLong();
      }


      Thank You.


      Last edited by XXtrem; 11-07-2010, 04:46 AM.

      Comment


        #4
        Thank you very, very much Austin!
        I'd like to know few more things - how to declare type for color, eg. DrawArrowUp(......, Color.Blue). The last argument looks lk some special type in C#. If in some cases I want to manipulate with colors, e.g. PlotSignals(up, 1,2,3, Blue)... how can I do this please? And I know I can do this w/out further complications, but I still would like to know how to declare and pass value for color in this case please.
        And how to explicitly assign 0 - zero default value to parameter please, e.g.:
        ....
        void PlotSignals(string direction, int arrowPos, int signalStrength==0)
        ....
        Thank you very much again.
        Regards, Art.
        Last edited by Art09; 11-07-2010, 12:53 PM.

        Comment


          #5
          To XXTerm - you are right, although I'm not sure about EMA fast and slow... If one EMA crosses another EMA or SMA would be correct thing probably. I hope Austin will correct us both.
          For example:

          if (CrossAbove(EMA(20), SMA(50), 1)//--> if EMA(20) crosses above SMA(50)...
          //--> yes, [-2] below means 2 bars ago and RSI() is above 50% line
          && RSI(RSIPeriod, RSISmooth)[-2] > 50)
          {
          EnterLong();
          }

          The only thing here is that RSI() can be above 50% and moving down. I think you should specify somehow that RSI() direction is up, e.g. it crosses 50% from down up... If I understood your logic correctly.


          Regards, Art.

          Last edited by Art09; 11-07-2010, 10:38 AM.

          Comment


            #6
            XXtrem, please start a new thread if you have a question unrelated to the original post. I've already answered your question elsewhere.

            Art09, you can definitely pass in colors. See the attached code. For assigning default values, you'll just have to manually pass in the value you want, like 0, into the method.
            Code:
            void PlotSignals(string direction, int tickOffset, Color dotColor)
            {
                if (direction == "up")
                    DrawDot("up dot" + CurrentBar, false, 0, Low[0] - tickOffset, dotColor);
                else if (direction == "down")
                    DrawDot("down dot" + CurrentBar, false, 0, High[0] + tickOffset, dotColor);
            }
            protected override void OnBarUpdate()
            {
                if (Close[0] > Open[0])
                    PlotSignals("up", 2, Color.Green);
                else if (Close[0] < Open[0])
                    PlotSignals("down", 2, Color.Red);
            }
            Attached Files
            AustinNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by suroot, 04-10-2017, 02:18 AM
            4 responses
            3,021 views
            0 likes
            Last Post truepenny  
            Started by Stanfillirenfro, Today, 07:23 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            2 responses
            22 views
            0 likes
            Last Post cmtjoancolmenero  
            Started by olisav57, Yesterday, 07:39 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by cocoescala, 10-12-2018, 11:02 PM
            7 responses
            944 views
            0 likes
            Last Post Jquiroz1975  
            Working...
            X