protected override void OnBarUpdate() { if(CurrentBar<85) { Print("Not enough bars. Current bar count: " + CurrentBar); return; } else { if(Close[0]>SMA(5)[0]) if(Volume[0]>=(SMA(Volume,10)[1])*2) if(Close[0]>(MAX(High,10)[1])) if(Slope(SMA(50),11,1)<0) if(CrossAbove(SMA(10),SMA(20),20)) if(CountIf(delegate {return Close[0]>SMA(20)[0];},10)>4) if(CountIf(delegate {return (SMA(10)[0]<SMA(20)[0])&&(SMA(20)[0]<SMA(50)[0]);},30)>9) EnterLong(); if(Close[0]<SMA(5)[0]) ExitLong(); } }
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Why is sell being triggered at point not called in code?
Collapse
X
-
Why is sell being triggered at point not called in code?
Hey there... I'm working with a strategy, and I see in the backtest chart, some of the positions are closing when I don't expect... I have one condition check that can call ExitLong(), and that is if(Close[0]<SMA(5)[0]... my positions are exiting with the close over the sma line. The whole method is below, and an image is attached(The 5per sma is the blue dashed line). Any help would be great...
Code:Tags: None
-
Hello,
If you're checking that all these conditions are true, please put them all in the same statement. You can separate the conditions using the && operator.
Code:if(CurrentBar<85) { Print("Not enough bars. Current bar count: " + CurrentBar); return; } else { if(Close[0]>SMA(5)[0] && Volume[0]>=(SMA(Volume,10)[1])*2 && Close[0]>(MAX(High,10)[1]) && Slope(SMA(50),11,1)<0 && CrossAbove(SMA(10),SMA(20),20) && CountIf(delegate {return Close[0]>SMA(20)[0];},10)>4 && CountIf(delegate {return (SMA(10)[0]<SMA(20)[0])&&(SMA(20)[0]<SMA(50)[0]);},30)>9) EnterLong(); if(Close[0]<SMA(5)[0]) ExitLong(); }
MatthewNinjaTrader Product Management
-
Syntax issue?
Thanks Matthew. Is the syntax incorrect? I did that for speed of execution to not have to check all conditions if an early condition is false. Is the code structure related to my sell issue?
Comment
-
Thanks..
Thanks again. My understanding of C# is that when you eliminate curly braces, only one statement immediately following the conditional check can be executed. One for the .NET gurus...
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Skifree, Today, 03:41 AM
|
1 response
2 views
0 likes
|
Last Post
by Skifree
Today, 03:42 AM
|
||
Started by usazencort, Today, 01:16 AM
|
0 responses
1 view
0 likes
|
Last Post
by usazencort
Today, 01:16 AM
|
||
Started by kaywai, 09-01-2023, 08:44 PM
|
5 responses
603 views
0 likes
|
Last Post Today, 12:32 AM | ||
Started by xiinteractive, 04-09-2024, 08:08 AM
|
6 responses
23 views
0 likes
|
Last Post Today, 12:31 AM | ||
Started by Pattontje, Yesterday, 02:10 PM
|
2 responses
23 views
0 likes
|
Last Post
by Pattontje
Yesterday, 11:49 PM
|
Comment