I was thinking about trying my hand at Ninjascript programming to do a simple setups. I wanted to know if there's a way for Ninjatrader to store the particular price level of an SMA associated with an SMA crossover for comparison to a prior identical crossovers that occurred earlier.
For instance, if a 6-period SMA crosses above the 18-period SMA at the close of the current bar Ninjascript (as per instructions) would record the closing price level of the 18-period SMA the crossover occurred on... but the Ninjascript would also have recorded the 18-period SMA price level that occurred on an identical 6/18-period SMA crossover that occurred prior to the current one.
The two 18-period SMA price levels would then be compared to see which is lesser/greater to check for possible momentum.
Would that price level be considered a variable?
Is this possible?
I'm definitely not a programmer, so I ask that the response be in layman's terms.
Will need to define Cross1 and Cross2 as dataseries."
I'm new to Ninjascript programming. I'm not familiar with the "? 1 : 0;" part of the statement. It seems it's referencing a previous and current SMA crossover occurrence. Please correct me if I'm wrong.
The "? SMA(18) : Cross1;" and "? Cross1 : Cross2;" part of the statements I'm not familiar with. Could you give me a brief walk through of the logic?
I think I may understand the logic. I figure the best way to understand this is to do as much on my own as possible, so I did some brainstorming. Please, at your convenience, let me know if my understanding of the logic is correct.
int crossup = SMA(6) > SMA(18) && SMA(6) < SMA(18) ? 1 : 0;
int crossdown = SMA(6) < SMA(18) && SMA(6) > SMA(18) ? 1 : 0;
Logic: If statement is true value = "1", otherwise it's "0"
Cross1 = crossup ==1 || crossdown ==1 ? SMA(18) : Cross1;
Logic: whether there's an SMA(18) crossover up or down, value will = SMA(18) price level
which is stored as the 2nd and current SMA crossover price level (Cross1)...
... otherwise if the crossover SMA(18) value is not current (1 bar or more ago), it
will be stored as "Cross1", the most recent and last SMA(18) crossover price level.
Cross2 = crossup ==1 || crossdown ==1 ? Cross1 : Cross2;
Logic: whether there's an SMA XO up or down, if a fresh current SMA(18) crossover took place
"Cross1" then becomes the prior SMA(18) crossover price level and
"Cross1" then becomes the current SMA(18) crossover price level
... otherwise when SMA(18) crossover is 1 bar old or more,
"Cross2" becomes the stored prior SMA(18) crossover price level and
"Cross1" becomes the most recent and last SMA(18) crossover price level.
Last edited by Piptick; April 23rd, 2013 at 09:47 PM.