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!
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
NinjaTrader
How to express the statement
Collapse
X
-
Hello tkaboris,
You would need to use a int variable and increment it to count bars where your condition is not true. You would need a second condition to check if that int variable is greater than X and if so do your action and reset the int variable to 0 so it can repeat the process.
JesseNinjaTrader Customer Service
-
Originally posted by NinjaTrader_Jesse View PostHello tkaboris,
You would need to use a int variable and increment it to count bars where your condition is not true. You would need a second condition to check if that int variable is greater than X and if so do your action and reset the int variable to 0 so it can repeat the process.
Comment
-
Originally posted by NinjaTrader_Jesse View PostHello tkaboris,
Not that I am aware of that is very specific.
Are you manually coding or using the strategy builder? I can likely link to some releated concept samples but would need to know how you will be making the script.
Comment
-
Hello tkaboris,
In that case you can use a simple variable like the following for incrementing on each bar.
Code:private int myIntVariable; protected override void OnBarUpdate() { if(ConditionToCheckIfPriceTocuhedEma) { myIntVariable = 0; // reset to 0 when the price tocuhes } else { myIntVariable++; // increment the variable each bar where the condition is true. } if(myIntVariable > 5) { //enter } }
JesseNinjaTrader Customer Service
Comment
-
I put this logic to open short at 89EMA only if last time price hasnt reached 89EMA in the last 20 bars back. Its not working...
else if (Trade89B
&& (Close[1] < Open[1] && High[1] > Open[1])// previous bar bullish
&& (Close[0] < Open[0] && High[0] > Open[0]) // current bar bearish with wick
&& High[0] > High[1] // current wick higher
&& High[0] > cEMA89[0] && Close[0] < cEMA89[0] // piercing through 89 ema
&& slowEMA[0] < cEMA89[0] - DForDW89 * TickSize) // enough distance to 34 ema, not overlapping
{
int count = 0;
for (int i=0; i < Bars.Count - 1; i++)
{
if (Close[i] <= cEMA89[i])
{
count++;
}
}
if (count >= 20)
{
entryOrder = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.Market, TradeSize, 0, 0, "", "89B");
}
return;
}
Comment
-
Hello tkaboris,
You would need to use a print to see what's not working. I had only provided a suggestion on how to increment a variable, you would still need to till use Print to debug and make sure that works for your use case. You are also using a loop over the bars which is not what I had intended with that example, you would normally process bars by just allowing the OnBarUpdate to be called and not using a loop.JesseNinjaTrader Customer Service
Comment
-
Would this be the right syntax ? Also Do i need to state property as bool for ConditionToCheckIfPriceTocuhedEma down there at the end so I dont get "... doesnt exist in context" error?
Code:else if (Trade89B && (Close[1] < Open[1] && High[1] > Open[1]) // previous bar bullish && (Close[0] < Open[0] && High[0] > Open[0]) // current bar bearish with wick && High[0] > High[1] // current wick higher && High[0] > cEMA89[0] && Close[0] < cEMA89[0] // piercing through 89 ema && slowEMA[0] < cEMA89[0] - DForDW89 * TickSize) // enough distance to 34 ema, not overlapping { if(ConditionToCheckIfPriceTocuhedEma) { myIntVariable = 0; // reset to 0 when the price tocuhes } else { myIntVariable++; // increment the variable each bar where the condition is true. } if(myIntVariable > 5) { entryOrder = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.Market, TradeSize, 0, 0, "", "89B"); } // entryOrder = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.Market, TradeSize, 0, 0, "", "89B"); return; }
Comment
-
Hello tkaboris,
ConditionToCheckIfPriceTocuhedEma isn't something that is real that's just a placeholder to say you need to use your own conditions there.
The code I provided is not something you can copy/paste into a script, that's only showing how to increment a variable but otherwise contains no valid conditions.
The general concept that I described is just to increment a variable based on your conditions from OnBarUpdate. You could also make price conditions similar to what you posted in post 7.
To know if something is working or not you will need to compile and test it, most likely you will also need to use prints to debug it.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by cocoescala, 10-12-2018, 11:02 PM
|
6 responses
939 views
0 likes
|
Last Post
by Jquiroz1975
Today, 06:51 AM
|
||
Started by gbourque, Today, 06:39 AM
|
1 response
4 views
0 likes
|
Last Post Today, 06:50 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
1 response
17 views
0 likes
|
Last Post Today, 06:16 AM | ||
Started by benmarkal, Yesterday, 12:52 PM
|
3 responses
23 views
0 likes
|
Last Post Today, 05:22 AM | ||
Started by helpwanted, Today, 03:06 AM
|
1 response
20 views
0 likes
|
Last Post Today, 03:35 AM |
Comment