Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Simple script that changes color of candle if wick is larger than candle
Collapse
X
-
Originally posted by NinjaTrader_PaulH View Post
-
Hello WeyldFalcon,
Thanks for your replies.
Regarding the IsOverLay, the check box in the strategy wizard will set the IsOverlay true or false for you in OnStateChange(). You can always change it directly in the code. When making changes especially to indicators plots or panels, make sure that you remove the indicator from the chart and then apply the new indicator. If you use reload Ninjascript the newest changes would not be applied.
Regarding not working as expected, I would suggest using print statement to print out all the values you are working with, including the math results such as Print ("High = "High[0]+" Open = "+Open[0]+ " H-O / Ticksize = "+(High[0]-Open[0])/TickSize).ToString()); I suspect it may be a rounding issue but the print should help clarify.Paul H.NinjaTrader Customer Service
Comment
-
modified it a little
Draw.Text(this, "test"+CurrentBar, "L="+Low[0]+"O="+Open[0]+"T="+TickSize+"O-L/T="+(Open[0]-Low[0])/TickSize, 0, Low[0]);
You are correct but why? I get 1847.3 for Open, 1846.6 for Low, 0.1 for Tick size but then 7.00000000000045 for (Open-Low)/TickSize. If I do that in my head I get .7/.1=7 exactly, what am I missing?
Is it cleaner to cast the final value to Int or cast each value to int prior to doing the division? or is there a better way to grab the values so they are not slightly off?
Comment
-
Hello WeyldFalcon,
Thanks for your reply.
When you cast to an int, you end up throwing off (not using) the remainder so 8.9999 becomes 8.
You may want to use Math.Round() and then cast, Math.Round() is not a Ninjascript item so I can only provide a link to an external reference here: https://www.dotnetperls.com/math-round
Paul H.NinjaTrader Customer Service
- Likes 1
Comment
-
Got it thank you.
if (Close[0]/TickSize>Open[0]/TickSize && Math.Round((Open[0]-Low[0])/TickSize, MidpointRounding.AwayFromZero)>=WickSizeMin && Math.Round((Open[0]-Low[0])/TickSize, MidpointRounding.AwayFromZero)<=WickSizeMax)
// { //hammer
BarBrush = BarColorUp;
// Draw.Text(this, "test"+CurrentBar, "O="+Open[0]+"L="+Low[0]+"T="+TickSize+"O-L/T="+Math.Round((Open[0]-Low[0])/TickSize, MidpointRounding.AwayFromZero), 0, Low[0]);
// }
else if (Close[0]/TickSize<Open[0]/TickSize && Math.Round((High[0]-Open[0])/TickSize, MidpointRounding.AwayFromZero)>=WickSizeMin && Math.Round((High[0]-Open[0])/TickSize, MidpointRounding.AwayFromZero)<=WickSizeMax)
// {//inverted hammer
BarBrush = BarColorDown;
// Draw.Text(this, "test"+CurrentBar, "H="+High[0]+"O="+Open[0]+"T="+TickSize+"H-O/T="+Math.Round((High[0]-Open[0])/TickSize, MidpointRounding.AwayFromZero), 0, High[0]);
// }
- Likes 1
Comment
-
For those confused as to why I used Draw.Text instead of Print there are 2 reasons
1) I did not know I needed to check NinjaScript Output for print data
2) I wanted to see the output on the specific candle that was causing the issue
Comment
-
Here is my update now that I realized I will want to use this with more than just ES one day so I implemented percentage-based instead of tick-based.
Code:if (Close[0]>Open[0] && (Open[0]-Low[0])/(High[1]-Low[1])*100>=WickPercMin && (Open[0]-Low[0])/(High[1]-Low[1])*100<=WickPercMax) BarBrush = BarColorUp; else if (Close[0]<Open[0] && (High[0]-Open[0])/(High[1]-Low[1])*100>=WickPercMin && (High[0]-Open[0])/(High[1]-Low[1])*100<=WickPercMax) BarBrush = BarColorDown;
- Likes 1
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by MaupinFinche, Today, 05:08 AM
|
0 responses
2 views
0 likes
|
Last Post
by MaupinFinche
Today, 05:08 AM
|
||
Started by Enkidu, Yesterday, 06:40 AM
|
9 responses
35 views
0 likes
|
Last Post
by Enkidu
Yesterday, 01:11 PM
|
||
Started by Mestor, 03-10-2023, 01:50 AM
|
12 responses
307 views
0 likes
|
Last Post
by z.franck
Today, 04:29 AM
|
||
Started by AgriTrdr, 07-16-2023, 12:54 PM
|
32 responses
267 views
0 likes
|
Last Post
by f.saeidi
Yesterday, 06:49 AM
|
||
Started by Mestor, Today, 03:15 AM
|
0 responses
2 views
0 likes
|
Last Post
by Mestor
Today, 03:15 AM
|
Comment