Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator to Strategy

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

    Indicator to Strategy

    am i missing something to reference the indicator to strategy?

    Indicator
    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] MagentaBarTest : Indicator[/SIZE][/FONT]
    Code:
    [SIZE=2][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]([/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]1+2=3[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New])[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]BarColor = Color.Magenta;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    Strategy
    Code:
    if(MagentaBarTest()BarColor = Color.Magenta) 
    {
    [SIZE=2][FONT=Courier New][COLOR=#008000][COLOR=black]EnterShort(DefaultQuantity, "short");[/COLOR][/COLOR][/FONT][/SIZE]
    [FONT=Courier New]}[/FONT]
    Last edited by duck_CA; 03-02-2009, 06:54 PM.

    #2
    When comparing for equality you want to use ==, for assignments just one =.

    So please try changing this in your indicator and strategy, as you check for equality in both cases.

    Comment


      #3
      confused

      sorry...not following...

      not sure how to reference the indicator to stragegy...are you saying that both need the "==" in place of the "="?

      Comment


        #4
        Originally posted by duck_CA View Post
        sorry...not following...

        not sure how to reference the indicator to stragegy...are you saying that both need the "==" in place of the "="?
        He is saying that you have a problem with the logic in your code:

        Code:
        if
        (
        1+2=3
        )
        {
        BarColor = Color.Magenta;
        }


        "==" is for comparison and "=" is for assignment.

        Change your code to:
        Code:
        if
        ( 1+2==3 )
        {
        BarColor = Color.Magenta;
        }

        Comment


          #5
          Thanks Phyre!

          Comment


            #6
            Find the 3rd Magenta Bar ago

            trying to reference the 3rd Magenta bar ago...


            Code:
            if(MagentaBarTest()BarColor = Color.Magenta) [3]
            {
            [SIZE=2][FONT=Courier New][COLOR=#008000][COLOR=black]EnterShort(DefaultQuantity, "short");[/COLOR][/COLOR][/FONT][/SIZE]
            [FONT=Courier New]}[/FONT]

            Comment


              #7
              Hi, you would need to create a DataSeries that tracks the barcolors you assign according to your conditions.

              For example 1 is conditions met and 0 is not met.

              Then you need to expose this dataseries programmatically because it's not a plot - http://www.ninjatrader-support2.com/...ead.php?t=4991

              This can then be accessed from your strategy later.

              Also for your BarColor check you need to use the == as you check for equality and not assign a value to a variable.

              Comment


                #8
                can i see what the indicator looks like?

                Notice that we are accessing the
                public BoolSeries we made in the indicator. */
                Code:
                [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]
                [FONT=Courier New][SIZE=2][COLOR=#008000]// Add our indicators to the strategy for charting purposes[/COLOR][/SIZE][/FONT]
                [FONT=Courier New][SIZE=2]Add(MACD([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]12[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]26[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]));[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]Add(SampleBoolSeries());[/FONT][/SIZE]
                 
                [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/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]
                [FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>[/COLOR][/SIZE][/FONT]
                [FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000] Called on each bar update event (incoming tick)[/COLOR][/SIZE][/FONT]
                [FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>[/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] OnBarUpdate()[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                [FONT=Courier New][SIZE=2][COLOR=#008000]/* When our indicator gives us a bull signal we enter long. Notice that we are accessing the[/COLOR][/SIZE][/FONT]
                [SIZE=2][FONT=Courier New][COLOR=#008000]public BoolSeries we made in the indicator. */[/COLOR][/FONT][/SIZE]
                [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (SampleBoolSeries().BullIndication[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]])[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]EnterLong();[/FONT][/SIZE]
                 
                [FONT=Courier New][SIZE=2][COLOR=#008000]// When our indicator gives us a bear signal we enter short[/COLOR][/SIZE][/FONT]
                [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (SampleBoolSeries().BearIndication[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]])[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]EnterShort();[/FONT][/SIZE]

                Comment


                  #9
                  The indicator is provided in the reference sample as well. Load it from the indicator side.
                  Josh P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  627 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  359 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  105 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  562 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  567 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X