Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 07-14-2017, 06:22 AM   #1
Yassine.Chetouani
Member
 
Join Date: Nov 2015
Posts: 42
Thanks: 16
Thanked 5 times in 4 posts
Default 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
Yassine.Chetouani is offline  
Reply With Quote
Old 07-14-2017, 08:10 AM   #2
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 852
Thanks: 54
Thanked 208 times in 202 posts
Default

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
File Type: zip SampleBoolSeriesLoops.zip (5.4 KB, 2 views)
Last edited by NinjaTrader_Jim; 07-14-2017 at 08:27 AM.
NinjaTrader_Jim is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jim for this post:
Old 07-14-2017, 08:29 AM   #3
Yassine.Chetouani
Member
 
Join Date: Nov 2015
Posts: 42
Thanks: 16
Thanked 5 times in 4 posts
Default

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
Yassine.Chetouani is offline  
Reply With Quote
Old 07-14-2017, 03:57 PM   #4
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 852
Thanks: 54
Thanked 208 times in 202 posts
Default

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.
NinjaTrader_Jim is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jim for this post:
Old 07-15-2017, 02:13 AM   #5
Yassine.Chetouani
Member
 
Join Date: Nov 2015
Posts: 42
Thanks: 16
Thanked 5 times in 4 posts
Default

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 Images
File Type: png Screenshot_1.png (15.9 KB, 1 views)
Last edited by Yassine.Chetouani; 07-15-2017 at 02:16 AM.
Yassine.Chetouani is offline  
Reply With Quote
Old 07-17-2017, 08:43 AM   #6
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 852
Thanks: 54
Thanked 208 times in 202 posts
Default

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.
NinjaTrader_Jim is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jim for this post:
Old 07-17-2017, 12:23 PM   #7
Yassine.Chetouani
Member
 
Join Date: Nov 2015
Posts: 42
Thanks: 16
Thanked 5 times in 4 posts
Default

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
Yassine.Chetouani is offline  
Reply With Quote
Old 07-17-2017, 01:42 PM   #8
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 852
Thanks: 54
Thanked 208 times in 202 posts
Default

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.
NinjaTrader_Jim is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jim for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MTF indicator calling plot is giving Close[0] zeller4 Indicator Development 18 08-10-2015 08:17 AM
Can't plot past current bar - Ichi Clouds incomplete rrangetrader Platform Technical Support 53 06-29-2014 01:46 AM
Past Plot() values Zeos6 General Development 9 06-11-2011 09:21 PM


All times are GMT -6. The time now is 05:43 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.