Yes...I meant to change that in the EMA for the example from 1 and 3 to 18 and 40 (your right there)...thanks so much for your input...also, thanks Joy and Lance for confirmation...I am testing now and will implement once I see it works on forward testing...smile.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
SMA crossover and Calculate on bar close FALSE
Collapse
X
-
Koganam:
Yes...I meant to change that in the EMA for the example from 1 and 3 to 18 and 40 (your right there)...thanks so much for your input...also, thanks Joy and Lance for confirmation...I am testing now and will implement once I see it works on forward testing...smile.
-
enters upon enabling
I have COBC set to False.
Should I change the 1 to 0 at the end of this?
if (CrossAbove(SMA(Fast), SMA(Slow), 1)
When I initially enable the strategy it still immediately enters nearly all of the instruments. However, once the stop outs take place the strategy runs perfectly and only fires on the crossover.
Please let me know...remember, I run with COBC set to False.
Above in the beginning of OnBarUpdate I do have:
if (Historical) return;
and
if (BarsSinceEntry(0,"",0) > 1)
if (BarsInProgress == 0)
if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired) return;
if (Position.MarketPosition == MarketPosition.Flat)
Thanks guys/gals...
Greg
Comment
-
Hello Greg,
You would want to keep CrossAbove(SMA(Fast), SMA(Slow), 1) on 1 because that is the look back period, if it is set to 0 it will not look back at any of the bars to see if they have crossed.
Are all of your conditions being met for your Entry orders when it is starting to calculate?
Happy to be of further assistance.JCNinjaTrader Customer Service
Comment
-
It sounds as if your strategy is issuing Real Time Historical Orders on entry. What are your Strategy settings in the Contol Panel options?Originally posted by birdog View PostI have COBC set to False.
Should I change the 1 to 0 at the end of this?
if (CrossAbove(SMA(Fast), SMA(Slow), 1)
When I initially enable the strategy it still immediately enters nearly all of the instruments. However, once the stop outs take place the strategy runs perfectly and only fires on the crossover.
Please let me know...remember, I run with COBC set to False.
Above in the beginning of OnBarUpdate I do have:
if (Historical) return;
and
if (BarsSinceEntry(0,"",0) > 1)
if (BarsInProgress == 0)
if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired) return;
if (Position.MarketPosition == MarketPosition.Flat)
Thanks guys/gals...
Greg
Comment
-
Hey JC:
That is what I kinda thought on the surface, but I do use False on Calculate of bar close. See here: http://www.ninjatrader.com/support/f...084#post320084
Given this, I would really like it to trigger once the two lines cross on the current bar since I use COBC false so it reacts the instant a crossover is detected...let me know your thoughts...
Also, yea, I believe all conditions are being meet.
Greg
Originally posted by NinjaTrader_JC View PostHello Greg,
You would want to keep CrossAbove(SMA(Fast), SMA(Slow), 1) on 1 because that is the look back period, if it is set to 0 it will not look back at any of the bars to see if they have crossed.
Are all of your conditions being met for your Entry orders when it is starting to calculate?
Happy to be of further assistance.
Comment
-
With those 2 options, the only reason that your strategy is entering when you enable it is because that is the way that it is written. You will have to debug it by checking that your conditions are properly restricted. It is obvious that you are being triggered in because your conditions are such that that is what happens.Originally posted by birdog View PostKoganam:
Oh...sorry...here is 2 screenshots...should anything be different?
I chose to select False for Sync account position cause it was said to be the least obtrusive.
Is that what you were looking for?

Greg
I noticed that you had a lot of if statements that were not followed by block delimiters. That style of coding is very prone to creating logic errors. I think that you should adopt a more standard coding style until you become a whole lot more familiar with the platform. Standard coding means that you should enclose all statements that are subject to a condition, inside a block, even if they are single statements.
I always surprise myself with the extra statements that I usually end up adding to blocks that I thought would be single statements, especially when I have to start sprinkling the code with "Print" statements when the code is not doing what I think that it should. Once I have the final code, I can always clean up and remove braces around really single statements if I want to.
Start by blocking out your code properly. The logic error may soon even look obvious.
Comment
-
Koganam:
Thanks for the input...I find the delimiters, for me, actually harder to follow for some reason (but will do that)...So, it is ok to do it and then once it is the way I want it to remove them later where I would prefer to have them in line (like an outline format without some of them)?
Lastly, do you have (or have some links to) some good quality coded base templates that work well and have all the functional abilities/handling in place where I might just adjust to what I am wanting to do and work backwards?
Thoughts?
In the meantime, I will do what you mentioned (Sledge briefly mentioned this too somewhere else).
Greg
Comment
-
Koganam:
Please see prior post...I am working on adding delimiters etc...during the course of doing so (though)...I noticed this:
Look at the first namespace (that actually should be this right?:
NinjaTrader.Strategy (not the name of my strategy)...could that be a issue?
Code:// This namespace holds all strategies and is required. Do not change it. namespace Gver6_MyStrat1_AvdSB { /// <summary> /// SMA and...xxx. /// </summary> [Description("Gver6_MyStrat1_AvdSB using...xxx." + "This strategy...xxx.)] public class Gver6_MyStrat1_AvdSB : Strategy {
Comment
-
I have no idea how you got that. In all my strategies, the namespace is NinjaTrader.Strategy, even if I use my own namespaces to also declare other enums or classes for use by using a using statement.Originally posted by birdog View PostKoganam:
Please see prior post...I am working on adding delimiters etc...during the course of doing so (though)...I noticed this:
Look at the first namespace (that actually should be this right?:
NinjaTrader.Strategy (not the name of my strategy)...could that be a issue?
Code:// This namespace holds all strategies and is required. Do not change it. namespace Gver6_MyStrat1_AvdSB { /// <summary> /// SMA and...xxx. /// </summary> [Description("Gver6_MyStrat1_AvdSB using...xxx." + "This strategy...xxx.)] public class Gver6_MyStrat1_AvdSB : Strategy {
Comment
-
Koganam:
I am going all the way to the beginning of where I started to try to figure out what happened. Actually, I may already be there (at least a bit closer). I have traced all the way back and now I am getting yellow on some strategy instruments immediately upon enabling and green on others. In your mind, is this how it should function when the strategy is suppose to wait for the next signal to fire before entering?
Over time the yellows turn green...let me know your thoughts whenever you are free and able...smile.
OR, should they all go immediately green upon enabling and then still only fire when the explicit condition of the crossover is meet (or both depending on the status of each instrument)?
Greg
Originally posted by koganam View PostWith those 2 options, the only reason that your strategy is entering when you enable it is because that is the way that it is written. You will have to debug it by checking that your conditions are properly restricted. It is obvious that you are being triggered in because your conditions are such that that is what happens.
I noticed that you had a lot of if statements that were not followed by block delimiters. That style of coding is very prone to creating logic errors. I think that you should adopt a more standard coding style until you become a whole lot more familiar with the platform. Standard coding means that you should enclose all statements that are subject to a condition, inside a block, even if they are single statements.
I always surprise myself with the extra statements that I usually end up adding to blocks that I thought would be single statements, especially when I have to start sprinkling the code with "Print" statements when the code is not doing what I think that it should. Once I have the final code, I can always clean up and remove braces around really single statements if I want to.
Start by blocking out your code properly. The logic error may soon even look obvious.
Last edited by birdog; 02-10-2013, 07:02 PM.
Comment
-
With the options that you are using, if the strategy goes yellow on enabling, it means that the strategy would have been in the market if it had been enabled earlier. IOW, the strategy has made a historical (virtual) order that puts it in the market, and will wait until it makes another virtual order to take it flat, before it will enter a real order.Originally posted by birdog View PostKoganam:
I am going all the way to the beginning of where I started to try to figure out what happened. Actually, I may already be there (at least a bit closer). I have traced all the way back and now I am getting yellow on some strategy instruments immediately upon enabling and green on others. In your mind, is this how it should function when the strategy is suppose to wait for the next signal to fire before entering?
Over time the yellows turn green...let me know your thoughts whenever you are free and able...smile.
OR, should they all go immediately green upon enabling and then still only fire when the explicit condition of the crossover is meet (or both depending on the status of each instrument)?
Greg
It can be very annoying, especially if the market comes back to your entry price, before it reaches the virtual exit. There are coding workarounds to force immediate enablement. They all involve adjusting the strategy parameters to somehow ensure that the virtual order that is turning the strategy yellow, does not get taken.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
649 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
576 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment