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 fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,406 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        98 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        8 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        160 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        9 views
        0 likes
        Last Post Belfortbucks  
        Working...
        X