Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I am lost

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

    I am lost

    Hi community, I am trying to code an indicator that calculates if x previous bar bodies are smaller than the actual bar body. I am new to coding so excuse my lack of skills in this matter.

    When you run this you see that it doesn't go and check the previous barsBack. Is there any efficient way to do this? Thanks

    #region Variables
    // Wizard generated variables
    private int totalBars = 100; // Total Bars to consider
    private int barsBack = 3; // Number of bars back to compare to the actual bar
    private int color = 1; // Not used for now
    private bool considerBodypips = false; // Not used for now
    int firstbar;


    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    // Add(new Plot(Color.FromKnownColor(KnownColor.SkyBlue), PlotStyle.Line, "IndicatorLine"));

    Overlay = true;
    BarsRequired = barsBack;
    }

    protected override void OnBarUpdate()
    {

    if (CurrentBar < totalBars) return; // Check if Chart has enough bars.

    int array = barsBack; //Create a variable for running thru previous bars to consider.


    //Declaring the arrays

    double[] opendata;
    opendata = new double[array];

    double[] bodysize ;
    bodysize = new double[array];

    double[] closedata;
    closedata = new double[array];

    //Calculate actual open - close

    Print(CurrentBar);
    double actualbodysize = Close[0] - Open[0];
    Print(actualbodysize);

    //Loop to go thru the previous barsBack

    for (int y = 0; y < array; y++)
    {
    opendata[y] = Open[y];
    closedata[y]= Close[y];
    bodysize[y] = opendata[y] - closedata[y];

    Print("");
    Print(bodysize);
    Print(opendata[y]);
    Print(closedata[y]);
    Print(bodysize[y]);

    Print("");
    }


    Print("Fuera del loop");




    IndicatorLine.Set(Close[0]);
    }
    Last edited by MillenniumTrader; 09-13-2012, 06:58 AM.

    #2
    Hello MillenniumTrader,

    Welcome to the NinjaTrader Support Forums!

    Not quite sure what exactly what you would like to accomplish, but I believe you are wanting to check the previous 3 barsBack of the CurrentBar for the values.

    Can you try the following for your for() loop:
    Code:
    (...)
    for (int y = 0; y < array; y++)
    {
    	opendata[y] = Open[CurrentBar - y];
    	closedata[y]= Close[CurrentBar - y];
    	bodysize[y] = opendata[y] - closedata[y];
    
    Print("");
    Print(bodysize[y]);
    Print(opendata[y]);
    Print(closedata[y]);
    Print(bodysize[y]);
    
    Print("");
    }
    (..)
    This will check the previous 3 bars from the CurrentBar.

    If that does not work for you could you clarify what you are expecting to happen and what is happening so that I may further assist you?

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thanks, thatis exactly what I am trying to accomplish. For some reason the variable barsBack which has a value of 3 int is giving me a value of 1 inside the loop and before the loop. Why is that? Thanks

      World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

      Comment


        #4
        Hello MillenniumTrader,

        Can you send a toy* NinjaScript code replicating the behavior so that I may look into this. You can either post it in the room or send it to support [at] ninjatrader [dot] com with ATTN: JC and reference this forum.

        To export your source file(s) follow the steps in the following link.
        http://www.ninjatrader.com/support/h...tml?export.htm

        Happy to be of further assistance.

        *Toy - basically a stripped down version of code that isn't necessarily the whole logic; making it easier to identify lines of code.
        JCNinjaTrader Customer Service

        Comment


          #5
          File sent. Thanks

          Comment


            #6
            uuuffffffffffff., I did it JC I don't know but the variable barsBack kept the value of 1 in the property section even assigning the value of 3 in the variable section. I will move on from here. Thanks for your help.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            581 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            338 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
            554 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            552 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X