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!
See more
See less

Partner 728x90

Collapse

EMA / TEMA on my DataSeries

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    EMA / TEMA on my DataSeries

    Hello,
    I have Range Bars 6 chart and I know where the close should end for the last bar - 2 possible positions:
    RBLongClose = Low[0] + Bars.Period.Value * TickSize
    RBShortClose = High[0] - Bars.Period.Value * TickSize

    I would like to see EMA or TEMA value at this possible positions. I thought I can create IDataSeries variable which holds the Close values on historical bars and RBLongClose for the last bar (and similar for short). Than I tried to do EMA calculations on my IDataSeries variable and had it displayed in the chart. It doesn't work right and I can understand why
    See my atteched pics. Everything looks good, but only on the "first" last bar after pressing F5. The farther bar is drawn after reloading the worse result. Im setting Close[1] for my IDataSeries[1] when new bar started drawing.
    See my code:


    protected override void OnBarUpdate()
    {
    if (CurrentBar<Period+1) return;


    double closeLongValue = Bars.Instrument.MasterInstrument.Round2TickSize( Low[0] + ((Bars.Period.Value) * Bars.Instrument.MasterInstrument.TickSize) );
    double closeShortValue = Bars.Instrument.MasterInstrument.Round2TickSize( High[0] - ((Bars.Period.Value) * Bars.Instrument.MasterInstrument.TickSize) );

    // just when CurrentBar has changed
    if (CurrBar!=CurrentBar) {
    CurrBar = CurrentBar;

    // just on the last bar
    if (CurrentBar>=Bars.Count-1) {

    CloseLong.Set(1,Close[1]);
    CloseShort.Set(1,Close[1]);

    CloseLong.Set(0,Close[0]); // for sure
    CloseShort.Set(0,Close[0]); // for sure

    Print(Close[1]+" - "+CloseLong[1]+" : "+CloseShort[1]);

    EMALo.Set(1,EMA(CloseLong,14)[1]);
    EMALo.Set(0,EMA(CloseLong,14)[0]); // for sure
    EMASh.Set(1,EMA(CloseShort,14)[1]);
    EMASh.Set(0,EMA(CloseShort,14)[0]); // for sure
    }
    }


    if (Historical) {
    CloseLong.Set(Close[0]);
    CloseShort.Set(Close[0]);
    } else {
    CloseLong.Set(closeLongValue);
    CloseShort.Set(closeShortValue);
    }

    EMALo.Set(EMA(CloseLong,14)[0]);
    EMASh.Set(EMA(CloseShort,14)[0]);
    .
    .
    .
    CloseLong, CloseShort, EMALo, EMASh are IDataSeries.
    CloseLong and CloseShort should hold historical Closes, only on the last bar it should have closeLongValue / closeShortValue values.

    There is a line: Print(Close[1]+" - "+CloseLong[1]+" : "+CloseShort[1]);
    It shows the same values.

    I need is especially for TEMA calculations.

    Thanks for your help.
    Attached Files

    #2
    Hello Alexik30

    Thank you for your post

    If I'm following you correctly, you are setting the historical values to the close price and when you reload the NinjaScript it will reset those data series values to the close[0] historically.

    I removed the if(Historical) statement and just left the CloseLong and CloseShort sets and it worked.
    Cal H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Skifree, Today, 03:41 AM
    1 response
    2 views
    0 likes
    Last Post Skifree
    by Skifree
     
    Started by usazencort, Today, 01:16 AM
    0 responses
    1 view
    0 likes
    Last Post usazencort  
    Started by kaywai, 09-01-2023, 08:44 PM
    5 responses
    603 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by xiinteractive, 04-09-2024, 08:08 AM
    6 responses
    23 views
    0 likes
    Last Post xiinteractive  
    Started by Pattontje, Yesterday, 02:10 PM
    2 responses
    23 views
    0 likes
    Last Post Pattontje  
    Working...
    X