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

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

      Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.

      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 GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,229 views
            0 likes
            Last Post xiinteractive  
            Started by andrewtrades, Today, 04:57 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            7 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            441 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            12 views
            0 likes
            Last Post FAQtrader  
            Working...
            X