Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            601 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            347 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
            559 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X