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

How to find the current value of an EMA

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

    How to find the current value of an EMA

    I am trying to get the current price and subtract it from the current price of an EMA line. This way I will have my entry within 1.5 points from the EMA line.

    CurrentBid = GetCurrentAsk();
    // Condition set 1
    if (CrossAbove(EMA(), SMA(), 1))
    {
    Distance = (CurrentBid - (System.Convert.ToDouble(EMA(14))));
    if(Distance < 1.5)
    {
    EnterLong(
    1, "Buy01");
    EnterLong(
    1, "Buy02");
    }
    }
    // Condition set 2
    if (CrossBelow(EMA(), SMA(), 1))
    {
    Distance = ((System.Convert.ToDouble(EMA(14))) - CurrentBid);
    if(Distance < 1.5)
    {
    EnterShort(
    1, "Sell01");
    EnterShort(
    1, "Sell02");
    }
    }


    #2
    Hey cbart, welcome to the forums!

    If you're trying to subtract the current price from the current price of an EMA line, you can just try this:
    Code:
    distance = EMA(14)[0] - Close[0].
    In English, the above says this: set the variable named distance to the difference between the current value of a 14 period EMA and the current price.
    AustinNinjaTrader Customer Service

    Comment


      #3
      For some reason, i am using the similar code, and i even tried the series, i always get the candle value at the time of EMA. for eg: 9 ema when it is under the candle bar , i get 9 ema value as High of the candle bar. I coded these in strategy, i want to find if Bar is below the candle or not.

      but nothing works .

      double distance = EMA(9)[0] - Close[0];

      i tried all possible ways. please help me, how do i find if 9 ema is below current bar or not. i tested in real time as well as playback, the code in strategy does not work right.

      Comment


        #4
        Hello supertradersam,

        Thank you for your inquiry.

        If you want to see if the current value of EMA(9) is less than the current bar, you can use

        Code:
        if (EMA(9)[0] < Close[0])
        EMA - https://ninjatrader.com/support/help...onential_e.htm

        I suggest using a print to confirm and understand the behavior.

        Code:
        Print(string.Format("{0} | EMA(9)[0]: {1} < Close[0]: {2}", Time[0], EMA(9)[0], Close[0]));


        Please let me know if you have any other questions.
        Gaby V.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Klaus Hengher, Yesterday, 03:13 AM
        2 responses
        15 views
        0 likes
        Last Post Klaus Hengher  
        Started by Sebastian - TwinPeaks, Yesterday, 01:31 PM
        2 responses
        13 views
        0 likes
        Last Post Sebastian - TwinPeaks  
        Started by wbennettjr, 07-15-2017, 05:07 PM
        16 responses
        2,530 views
        1 like
        Last Post eladlevi  
        Started by Human#102, Yesterday, 09:54 AM
        2 responses
        8 views
        0 likes
        Last Post Human#102  
        Started by Patlpp, 08-16-2021, 03:10 PM
        10 responses
        498 views
        0 likes
        Last Post Joerg
        by Joerg
         
        Working...
        X