NexusFi: Find Your Edge


Home Menu

 





Can Prior SMA Crossover Price Levels be Stored?


Discussion in NinjaTrader

Updated
    1. trending_up 1,526 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Can Prior SMA Crossover Price Levels be Stored?

  #1 (permalink)
 Piptick 
Brooklyn, NY USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Forex EUR/USD
Posts: 12 since Mar 2012
Thanks Given: 1
Thanks Received: 1

Hello all,

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.

Thanks in advance for any help provided.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
How to apply profiles
Traders Hideout
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
33 thanks
Just another trading journal: PA, Wyckoff & Trends
28 thanks
Bigger Wins or Fewer Losses?
23 thanks
Tao te Trade: way of the WLD
23 thanks
GFIs1 1 DAX trade per day journal
21 thanks
  #2 (permalink)
 vegasfoster 
las vegas
 
Experience: Intermediate
Platform: Sierra Chart
Broker: Velocity/IB
Trading: 6E
Posts: 1,145 since Feb 2010
Thanks Given: 304
Thanks Received: 844

Maybe try something like,

int crossup = SMA(6)[0] > SMA(18)[0] && SMA(6)[1] < SMA(18)[1] ? 1 : 0;
int crossdown = SMA(6)[0] < SMA(18)[0] && SMA(6)[1] > SMA(18)[1] ? 1 : 0;

Cross1[0] = crossup ==1 || crossdown ==1 ? SMA(18)[0] : Cross1[1];
Cross2[0] = crossup ==1 || crossdown ==1 ? Cross1[1] : Cross2[1];
etc.

Will need to define Cross1 and Cross2 as dataseries.

Reply With Quote
Thanked by:
  #3 (permalink)
 Piptick 
Brooklyn, NY USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Forex EUR/USD
Posts: 12 since Mar 2012
Thanks Given: 1
Thanks Received: 1


Thanks for your response vegasfoster.

"Maybe try something like,

int crossup = SMA(6)[0] > SMA(18)[0] && SMA(6)[1] < SMA(18)[1] ? 1 : 0;
int crossdown = SMA(6)[0] < SMA(18)[0] && SMA(6)[1] > SMA(18)[1] ? 1 : 0;

Cross1[0] = crossup ==1 || crossdown ==1 ? SMA(18)[0] : Cross1[1];
Cross2[0] = crossup ==1 || crossdown ==1 ? Cross1[1] : Cross2[1];
etc.

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)[0] : Cross1[1];" and "? Cross1[1] : Cross2[1];" part of the statements I'm not familiar with. Could you give me a brief walk through of the logic?

Started this thread Reply With Quote
  #4 (permalink)
 Piptick 
Brooklyn, NY USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Forex EUR/USD
Posts: 12 since Mar 2012
Thanks Given: 1
Thanks Received: 1

vegasfoster,

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)[0] > SMA(18)[0] && SMA(6)[1] < SMA(18)[1] ? 1 : 0;
int crossdown = SMA(6)[0] < SMA(18)[0] && SMA(6)[1] > SMA(18)[1] ? 1 : 0;

Logic: If statement is true value = "1", otherwise it's "0"

Cross1[0] = crossup ==1 || crossdown ==1 ? SMA(18)[0] : Cross1[1];
Logic: whether there's an SMA(18) crossover up or down, value will = SMA(18)[0] price level
which is stored as the 2nd and current SMA crossover price level (Cross1[0])...
... otherwise if the crossover SMA(18) value is not current (1 bar or more ago), it
will be stored as "Cross1[1]", the most recent and last SMA(18) crossover price level.


Cross2[0] = crossup ==1 || crossdown ==1 ? Cross1[1] : Cross2[1];
Logic: whether there's an SMA XO up or down, if a fresh current SMA(18) crossover took place
"Cross1[1]" then becomes the prior SMA(18) crossover price level and
"Cross1[0]" then becomes the current SMA(18) crossover price level
... otherwise when SMA(18) crossover is 1 bar old or more,
"Cross2[1]" becomes the stored prior SMA(18) crossover price level and
"Cross1[1]" becomes the most recent and last SMA(18) crossover price level.

Started this thread Reply With Quote
Thanked by:




Last Updated on April 23, 2013


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts