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

Calling an indicator Plot from the past bars

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

    Calling an indicator Plot from the past bars

    Dear Sir or Madam,

    Thank you for giving time to consider this.
    I was trying to create a strategy for my manual trading system. However I found difficulty to code this part, I knew that Wiz does not help with it but I can code it by myself now.

    The problem is that the strategy is a bit complicated, I managed first to creat my own 3 indicators plotting differently on the chart. when several conditions were met,

    To explain better, my own indicators are ploting different colors.

    For short postion: When 1st indicator plots Blue, after several bars 2nd indicator plots Green , and after several bars the same 2nd indicator plots Red. I enter sell position on the close of red plotting.

    For Long position: when Pink from indicator 1 plots, and Red from indicator and Green plot from indicator 2. I enter Long at the green.

    I searched in your forum all the treats and tried to use countIf condition to call for previous

    if (CountIf(delegate {return Close[0] >Open[2] && Close[1]<Open[1];}, 10) > 0)
    {
    }
    However, I was not able to create a countIf condition with an indicator plot.
    Besides, I tried this alternative to use the logic I used for creating the ploting of the indicators However, and since the condition used to plot is very long and complicated including RSI, bollinger and other 2 other indicators related to each other I wasn't able to do so.

    So my question: is there any possibility to create this logic, looking to the last 50 bars if these plots exists (2 plots) and enter when the 3th condition shows (Enter position).
    in other word:

    if (CountIf(delegate {return ındicator1_plot_blue && indicator2_plot_Red;}, 50) == true or exists)
    && the indicator_Plot_green[0] is true
    {
    enter
    }

    I hope I was able to explain myself since it seems very difficult to explain even.
    Looking forwards to hearing from you.
    Thanks .
    Yassine

    #2
    Hello Yassine.Chetouani,

    Thanks for writing in.

    Providing code for our clients is not something that we can offer within our scope of services in the Support department at NinjaTrader. This also gets applied to questions related to programming logic. As we are a small team, we are not equipped to offer such services.

    That being said, I may be able to provide some further direction for you. Have you considered to use a for loop to go through the last 50 bars of an indicator's plot?

    I have attached a small demonstration that modifies the SampleBoolSeries example so it loops through to check if a plots are true for a certain number of bars ago. This sample also serves to demonstrate how to expose an indicator's values which are not plots which may be useful in your script. You can find the original thread with the associated documentation for the components used here: http://ninjatrader.com/support/forum...ead.php?t=4991

    If you would like further assistance developing your code, or with logical questions, I could have a member of our Business Development team pass over a list of NinjaScript Consultants who would be happy to write and develop the code with/for you. If that is the case, please write in to platformsupport[at]ninjatrader[dot]com with the thread URL and the text "Attention Jim."

    You may also receive some guidance from other members on the forum if another member is willing to provide further direction.

    EDIT: I just noticed this is in the NinjaTrader 7 forum. Sorry for the mix up! The demonstration is equally applicable to NinjaTrader 7 if you reference the NinjaTrader 7 version of the script.

    Please let me know if I can be of further help.
    Attached Files
    Last edited by NinjaTrader_Jim; 07-14-2017, 08:27 AM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Dear Jim ,
      Thank you for answering me.
      with reference to your last answer, I want to inform you that I know your internal policies and the impossibility to send a code to customers,
      Kindly, note that I was asking if I am able to use countIf() command to solve my case senario. If Yes, how can I do to replace the condition close [0] && Open[0] in the given NT7 with my case senario. Plot1_shows_true.

      Coming to the subject of introducing a 3th party consultant, please note that I used one your NinjaScript Consultants in one previous complicated strategy I tried to develop and I was completely disappointed, spending money on a strategy that remains unfinished with several bugs, even the guy does not answer my emails and for this reason I decided to do things by myself from now on even if it will take me to become a coder. (let's keep this subject for a later talk)
      So, can you provide me any better guide to solve my senario?
      Thank you

      Comment


        #4
        Hello Yassine,

        I appreciate your understanding of our policies for providing assistance. Keep in mind we mention these policies to prevent misunderstandings of the services we offer from new users reading the forums.

        Writing the correct syntax for using this method so it can be used in your specific context is not something we can offer. Fulfilling such requests opens the door for many other clients to ask for snippets that serve an exact purpose for their needs. This is not a door that we are equipped to open. Additionally, I do not have the code for your strategy to give you the syntax you are looking for.

        You have written the CountIf() statement with the correct syntax when you are referencing the Price objects. If you would like to use the CountIf() statement for indicator plots, I would advise to first try it out with exposed values from the SampleBoolSeries indicator. You could also call the indicator from within this statement and reference the particular bars ago for the plot you wish to reference.

        Here is an example of referencing SMA and EMA indicators in a CountIf()
        Code:
        if (CountIf(delegate {return SMA(14)[0] > SMA(14)[1] && EMA(14)[0]>EMA(14)[1];}, 10) > 0)
        Referencing indicators within a condition for a certain value is covered in the Referencing [] Brackets thread of our forums here: http://ninjatrader.com/support/forum...ad.php?t=19346

        If you had an unpleasant experience with a Certified NinjaScript Consultant, please reach out to your Business Development team liaison to share your experience. I could connect you with the team if you had lost the contact information. Please write in by email if that is the case.
        JimNinjaTrader Customer Service

        Comment


          #5
          Dear Mr. Jim
          I want to thank you for answering me. You have been of a great help with the code below:
          if (CountIf(delegate {return SMA(14)[0] > SMA(14)[1] && EMA(14)[0]>EMA(14)[1];}, 10) > 0)


          Kindly note that I used the conditions from my customed indicator and find out that I did a mistake while coding (red location) so now I was able to plot it.


          However, this time I faced other two problems, which I wish if you can help me to overcome them, as attached in the Picture you can see what the strategy does with the gray arrows:
          Problem 1:
          The strategy does this: if condition 1 && condition 2 exist in the past N bars (countIf) and entry condition 3 is showing, do the action. However, What I want: is to respect the order of the condition with the CountIf().
          Means when condition1 is satisfied After that condition 2 shows up and satisfied after that my entry condition 3 exists, Do the action.
          Problem 2:
          Strategy is doing : the conditions 1 & 2 are satisfied for n previous bars (example 50 bars), So it repeated the action every time condition 3 shows within the 50 bars

          What I need is to do it once. and forget if condition 3 shows a 3th time or 4th time.



          In conclution:
          I need some how,
          Condition 1, after that condition 2 after that condition 3, Do the action one time.


          Can you provide me the necessary information / Solution to overcome this new problems.
          Thank you.

          Coming to the subject of my previous issues with your Consultant, I wish to be connected to the related person/department to forward the subject if you can provide me the email if the department it will be really greatful.
          Thank you .
          Yassine
          Attached Files
          Last edited by Yassine.Chetouani; 07-15-2017, 02:16 AM.

          Comment


            #6
            Hello Yassine,

            I won't be able to provide a direct solution for you, but I may propose that you break your conditions down so you have Condition 1 that sets a bool, Condition 2 that checks the rules for Condition 2 and checks if the bool from Condition 1 has been set to true, and then Condition 3 that checks the rules for Condition 3 and the bool from Condition 2 is true. Finally, you will want to invalidate these bools and set the back to false when these conditions are no longer true.

            If you would like to write in the Business Development team on your own, you may reach them at info[at]ninjatraderecosystem[dot]com. Alternately, you can reach out to me at the platform support email (mentioned in post #2) and I can forward you over to them as well.
            JimNinjaTrader Customer Service

            Comment


              #7
              Dear Jim,

              I want to thank you for the answer. I searched this week-end on the subject and as you said I found that bool command can solve both issues, so I will try to create a new bool code, (there are several examples on this forum) and if I face a problem, I will open a new treat regarding the bool and ask the team again, thank you.

              Now still in the subject of CountIf(), I need a last information regarding a case I have with my strategy, I need to tell the strategy this time to make sure a cross below did not happened within X bars (example 10 bars) ,
              (an CrossAbove existing I can do it now thanks to you) .

              I tried this negative case by switching to <0 but it didn't work :
              Example

              if (CountIf(delegate {return ((CrossBelow(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1);}, 10) < 0)

              Can you correct me if I am wrong. or explain to me how it can be done
              Thank you.
              Yassine

              Comment


                #8
                Hello Yassine,

                As much as I would like to assist you further, these questions are falling under the realm of programming education and questions on syntax. These types of questions escape the scope of services that we provide, and are where we redirect clients to seek additional help from a consultant.

                It is our expectation of our clients that they are able to write their own syntax appropriately and to troubleshoot and debug any programming issues they may come across.

                CrossBelow() already has an argument for specifying a lookback period. It would not be necessary to use CountIf() to look for the cross over the last X number of bars. Using "!" can tell you if the method is NOT true.

                Please refer to the documentation here for syntax: https://ninjatrader.com/support/help...crossbelow.htm

                Additionally, you may find basic programming education in the NinjaTrader 7 help guide here: https://ninjatrader.com/support/help...g_concepts.htm

                Even though we try to be helpful, asking questions about how a bool works or how you can correct your syntax is not something we offer support for.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by jclose, Today, 09:37 PM
                0 responses
                5 views
                0 likes
                Last Post jclose
                by jclose
                 
                Started by WeyldFalcon, 08-07-2020, 06:13 AM
                10 responses
                1,414 views
                0 likes
                Last Post Traderontheroad  
                Started by firefoxforum12, Today, 08:53 PM
                0 responses
                11 views
                0 likes
                Last Post firefoxforum12  
                Started by stafe, Today, 08:34 PM
                0 responses
                11 views
                0 likes
                Last Post stafe
                by stafe
                 
                Started by sastrades, 01-31-2024, 10:19 PM
                11 responses
                169 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X