Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Strategy Development

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

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 02-09-2018, 01:40 PM   #1
dorony
Member
 
Join Date: Jan 2018
Posts: 50
Thanks: 7
Thanked 1 time in 1 post
Default Pull Back Logic Possible?

Hello,

I need a specific type of logic to be created to define a "pullback".

Is the logic provided below possible with implementing in the scripter?

Create logic which will look for a sequence where a stock is above the mid bb at all times

And then check if the last 2 bars highs are less than the 3rd bar which is the proposed high.

As long as the 3rd bar has never been broken higher and the price is still above the midd bb, then the 3rd bar stays set as the current high for the pullback

The trigger to enter in a position is when the price breaks above the SET HIGH

This cancels if the price breaches the mid bb.

And then restarts once it has been cancelled or triggered to enter in a position.
Is this type of logic possible?


Is it possible to set one specific candle value while new bars continue to develop?
dorony is offline  
Reply With Quote
Old 02-09-2018, 01:49 PM   #2
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,111
Thanks: 770
Thanked 1,913 times in 1,842 posts
Default

Hello dorony,

Thank you for your post.

This logic is possible to develop in NinjaScript.

I am not sure I understand your last question though. What candle value would you be setting?

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-09-2018, 01:59 PM   #3
dorony
Member
 
Join Date: Jan 2018
Posts: 50
Thanks: 7
Thanked 1 time in 1 post
Default

Thank you...

Quote:
And then check if the last 2 bars highs are less than the 3rd bar which is the proposed high.

As long as the 3rd bar has never been broken higher and the price is still above the midd bb, then the 3rd bar stays set as the current high for the pullback
So as long as the 3rd bar has never been broken. How do I set the 3rd candle to stay relevant as long as its holding the mid bb.
dorony is offline  
Reply With Quote
Old 02-09-2018, 03:50 PM   #4
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,111
Thanks: 770
Thanked 1,913 times in 1,842 posts
Default

Hello dorony,

Thank you for your response.

Can you provide a screenshot that might provide further insight into this matter?

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-12-2018, 11:51 AM   #5
dorony
Member
 
Join Date: Jan 2018
Posts: 50
Thanks: 7
Thanked 1 time in 1 post
Default

I attached a chart of IMGN on the 1min with a pull back.

As you can see the CandleBar[3] is greater than the candles ahead of it.

So this means the 3rd candle is greater than the 2nd 1st and current candle high.

It is also above the Middle Bollinger band.

At this point. I want it to signify a pull back and continue to do so until the price breaks below the mid bb or breaks above the candle high within the sequence I mentioned which is the 3rd candle.

My question is as the chart continues to develop new candle bars, how do I get it to continue to use the value of the 3rd bar even though that won't be the case when new candles are developed.

I hope this makes sense.
Attached Images
File Type: jpg nt8.JPG (67.4 KB, 11 views)
dorony is offline  
Reply With Quote
Old 02-13-2018, 10:32 AM   #6
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,111
Thanks: 770
Thanked 1,913 times in 1,842 posts
Default

Hello dorony,

Thank you for your response.

So another way to put it would be to have the the value of the "size" of the 3rd bar back to update consistently?

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-13-2018, 03:06 PM   #7
dorony
Member
 
Join Date: Jan 2018
Posts: 50
Thanks: 7
Thanked 1 time in 1 post
Default

I want it to lock in its high value of the 3rd candle even when it technically becomes the 4th and 5th candle as time goes on.

Let me know if you want a more thorough explanation. I will try to explain it clearer.
dorony is offline  
Reply With Quote
Old 02-13-2018, 03:53 PM   #8
dorony
Member
 
Join Date: Jan 2018
Posts: 50
Thanks: 7
Thanked 1 time in 1 post
Default

I created the logic or the code that I believe should be written to evaluate whether a pull back back has developed (in my own pull back definition)

I don't know how to create a value that remains constant once its been triggered.

Maybe this will make it easier to understand my logic and what I am looking for.

If ((Low[4] > Mid BB[4]) – To make sure price has never broken below the mid bb from the beginning process.

&& If (High[4] < High[3]) -- This is to make sure that the candle is higher than the previous one.

&& (Low[3] > Mid BB[3] – Continues to make sure that the price has not broken below the mid bb.

&& (High[3] > High[2]) – If it continues to pass through the statements as true, then High[3] will become a constant value to be used. (even when it becomes High[4]…[5]…[6] and so on. (Or I am thinking I can keep High[3] as constant by calling back the candle by its Time stamp. ie. High[3] is 12:00pm est)

&& (Low[2] > Mid BB[2]) – Continues to make sure that the price has not broken below the mid bb.

&& (High[3] > High[1])

&& (Low[1] > Mid BB[1]) – Continues to make sure that the price has not broken below the mid bb.

&& (Low[0] > Mid BB[0]) – Continues to make sure that the price has not broken below the mid bb.

Then High[3] is marked as the high of the “pull back” – This should become a constant variable as long as the mid bb is never breached and then looks for entry within the code below.

&& (High[0] > “Pull Back”)

So this is my definition of a pull back. The pull back will continue to exist as long as it doesn’t break below the mid bb and will trigger if it breaks the MARKED and FIXED “pull back” candle high level. This is where maybe I need to mark High[3] as a time stamp as stated above.

Then it would be If (1minute candle at 12pm est HIGH is > Low[2], Low[1]...)

So an entry can occur as it continues to develop candles as long as it never breaks the mid bb and will continue to wait for the price to break the “pull back” candle high.

If it breaks below the mid bb, then the “pull back” candle becomes invalid and cancels, and resets to look for another pull back development.
Attached Images
File Type: jpg nt82.JPG (112.5 KB, 3 views)
Last edited by dorony; 02-13-2018 at 06:05 PM.
dorony is offline  
Reply With Quote
Old 02-14-2018, 08:51 AM   #9
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,111
Thanks: 770
Thanked 1,913 times in 1,842 posts
Default

Hello dorony,

Thank you for your response and additional details.

You would assign the "size" value and/or bar number of the bar to a variable or set of variables (such as double for a value or int for a bar number) when your condition for that bar is true. That way the variable is only updated on when the condition is true.

Please let me know if you have any questions.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-14-2018, 09:11 AM   #10
dorony
Member
 
Join Date: Jan 2018
Posts: 50
Thanks: 7
Thanked 1 time in 1 post
Default

Could you provide an example please...

Not sure how to even begin that.
dorony is offline  
Reply With Quote
Old 02-14-2018, 03:19 PM   #11
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,111
Thanks: 770
Thanked 1,913 times in 1,842 posts
Default

Hello dorony,

Thank you for your response.

Please refer to the basic example of this below:
Code:
		private double holdValue = 0;
		private int holdBarNumber = 0;
		protected override void OnBarUpdate()
		{
			if (Close[0] > Open[0]) // pseudo condition, replace with your condition
			{
				holdValue = Close[0]; //store the close when the condition was true
				holdBarNumber = CurrentBar; // store the current bar number when the condition was true
			}
			
			if (holdValue != 0 && holdBarNumber != 0) // check if we have values for the variables
			{
				Print("Close price at last condition was " + holdValue);
				Print("Bar timestamp of last condition was " + Time[CurrentBar - holdBarNumber]); // subtract the bar number from the current bar number to get the proper BarsAgo int
			}
		}
Please let me know if I may be of further assistance.
Last edited by NinjaTrader_PatrickH; 02-15-2018 at 11:38 AM.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-14-2018, 07:12 PM   #12
dorony
Member
 
Join Date: Jan 2018
Posts: 50
Thanks: 7
Thanked 1 time in 1 post
Default

I kinda get what the code is getting at but after inputting condition and testing it, it doesn't do what I expect it to do as per the image I sent you.

remember that as long as the condition is met, and the low prices of each candle are greater than the middle bollinger band then it can continue to find an entry when the current candle high is greater than the holdvalue.

Here is what I have so far for the code. Let me know if you see anything wrong with this.

protected override void OnBarUpdate()
{
if (CurrentBars[0] < 5)
return;


if ((High[3] > High[2])
&& (Low[2] > midbbBull.Middle[2])
&& (High[3] > High[1])
&& (Low[1] > midbbBull.Middle[1]))
{
holdValue = High[3];
holdBarNumber = CurrentBar;
}

if (holdValue != 0 && holdBarNumber != 0)
{
Print("Close price at last condition was "+ holdValue);
Print ("Bar timestamp of last condition was "+ Time[CurrentBar - holdBarNumber]);
}

if ((Low[0] > midbbBull.Middle[0])
&& (High[0] > holdValue))
{
EnterLong();
}


Also I dont' need the current bar to be held. I need the High[2] but when I try to input that it gives me an error that it must be a double.
Last edited by dorony; 02-15-2018 at 10:42 AM.
dorony is offline  
Reply With Quote
Old 02-15-2018, 11:41 AM   #13
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,111
Thanks: 770
Thanked 1,913 times in 1,842 posts
Default

Hello dorony,

Thank you for your response.

For the error message you need to define the variable as a double and not an int.

My example was just that, a simplified example. Based on your response I would recommend taking a look at the basic programming concepts at the following link to get yourself familiarized with the concepts used: https://ninjatrader.com/support/help...g_concepts.htm

Now, that link is for NinjaTrader 7 but the same concepts apply in NinjaTrader 8. For a bit more detail in NinjaTrader 8 please visit the following link: https://ninjatrader.com/support/help..._practices.htm

Please let me know if you have any questions.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-15-2018, 12:39 PM   #14
dorony
Member
 
Join Date: Jan 2018
Posts: 50
Thanks: 7
Thanked 1 time in 1 post
Default

Thanks I read it and understand it.

Still very foggy in terms of what needs to be done. But to try and follow through with your help,

doesn't that mean I don't need "holdBarNumber = CurrentBar; // store the current bar number when the condition was true"

Since holdValue is really only what I need in order to use the high price of a certain candle within the condition?

If not then what is the purpose of holdbarvalue?
dorony is offline  
Reply With Quote
Old 02-15-2018, 02:57 PM   #15
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,111
Thanks: 770
Thanked 1,913 times in 1,842 posts
Default

Hello dorony,

Thank you for your response.

That was simply an example of storing the CurrentBar but it is not necessary for your intended behavior.

Please let me know if I may be of further assistance.
NinjaTrader_PatrickH is offline  
Reply With Quote
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
pull historical data brucelevy Platform Technical Support 1 08-06-2017 02:24 PM
Where can I pull the strategy name cgeorgan General Development 2 04-13-2011 08:06 AM
Pull-Down List with Strings SharkCub Indicator Development 1 07-31-2010 10:06 AM
Why can't I pull up a daily chart? BrianNC Platform Technical Support 1 10-07-2009 03:21 AM
How do you pull up an ES chart? Mark_486 Platform Technical Support 1 06-05-2008 03:59 PM


All times are GMT -6. The time now is 03:42 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.