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

Price Entry and EMA Close

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

    Price Entry and EMA Close

    I created the below with the Strategizer for trading the FOREX. The purpose is to create an entry after an EMA crossing opportunity for the entry point has passed. I want to enter a trade short at the current price and have the trade exit on the EMA crossabove of the 5,6 ema's.

    The programming has created three unusual problems when activated in the Sim mode during active trading times. I entered the the GBPUSD pair short when it was trading at 1.9932. I was instantly showing a $154.00 profit as the trade was showing the crossbelow ENTRY point of 2.0086 (which was missed), 154 pips above my present entry point. How can I get the program to enter at the current price and start from there?

    It is also filling trades concurrently in the 1,10,15 min along with the intended 60 min interval. The 1, 10, 15 fills have a "start" next to them. The 60 has a "stop" as would be normal.

    The third observation is the strategy looks to be backtesting on it's own during the strategy activation and shows the entry marks throughout the various intervals.

    My priority here is to get the PRICE entry to work properly.


    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    ///<summary>
    /// PRICE Entry SHORT EMA exit 56LONG
    ///</summary>
    [Description("PRICE Entry SHORT EMA exit 56LONG")]
    [Gui.Design.DisplayName(
    "PRICE Entry SHORT EMA exit56LONG")]
    publicclass PriceEntryShortEMAExit56LONG : Strategy
    {
    #region Variables
    // Wizard generated variables
    privateint entryPrice = 1; // Default setting for EntryPrice
    privateint fast = 5; // Default setting for Fast
    privateint slow = 6; // Default setting for Slow
    // User defined variables (add any user defined variables below)
    #endregion
    ///<summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    ///</summary>
    protectedoverridevoid Initialize()
    {
    Add(EMA(
    5));
    Add(EMA(
    6));
    CalculateOnBarClose =
    true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (EntryPrice <= GetCurrentBid())
    {
    EnterShort(DefaultQuantity,
    "");
    PlaySound(
    @"C:\Program Files\NinjaTrader 6\sounds\OrderFilled.wav");
    }
    // Condition set 2
    if (CrossAbove(EMA(5), EMA(6), 1))
    {
    ExitShort(
    "", "");
    PlaySound(
    @"C:\Program Files\NinjaTrader 6\sounds\TargetFilled.wav");
    }
    }

    #2
    What NT version are you using?

    Orders will be generated on whatever time frame you run the the strategy on. As a strategy is activated it will run on all historical data. If you do not wish this to happen, add some code in OnBarUpdate() such as:

    if (Historical) return;
    RayNinjaTrader Customer Service

    Comment


      #3
      What about the entry price?

      How can I get the program to enter at the current price and start from there as it shows the avg. price as 2.0086 (154 ticks above entry)vs. the 1.9932 in which it was supposed to have entered?

      As for Historical data, do I put that within the parentheses?

      Comment


        #4
        Using NT 6.0

        The version is 6.0.

        Comment


          #5
          When EnterShort() is called, a sell short will be executed at the market price. The price of your fill is truly where the market was at the time the method to go short was called.

          See below.

          ///<summary>
          ///
          Called on each bar update event (incoming tick)
          ///
          </summary>
          protectedoverridevoid
          OnBarUpdate()
          {


          if (Historical) return;
          // Condition set 1
          if
          (EntryPrice <= GetCurrentBid())
          {
          EnterShort(DefaultQuantity,
          ""
          );
          PlaySound(
          @"C:\Program Files\NinjaTrader 6\sounds\OrderFilled.wav"
          );
          }
          // Condition set 2
          if (CrossAbove(EMA(5), EMA(6), 1
          ))
          {
          ExitShort(
          "", ""
          );
          PlaySound(
          @"C:\Program Files\NinjaTrader 6\sounds\TargetFilled.wav"
          );
          }
          }
          RayNinjaTrader Customer Service

          Comment


            #6
            If (Historical) return

            Sorry, I am still learning. I created the strategy with the Wizard.
            1. It appears the only way for me to add the code is to unlock and edit what the Wizard has written. Is that correct? I have no problem about doing that, but I wanted to find out if the Wizard could do it.
            2. Will the new code cause the ENTRY price on the Control panel to show the correct amount at entry? As mentioned before, I am getting entry level prices from the point of the crossover ema's and not the current price.
            3. I tried to enter a LIVE trade yesterday, however, when I placed the strategy that we have been discussing, the price started showing an instant $122.00 from the earlier crossover I had missed. Now that is how I would like to trade, after the fact. I bailed out before it filled to avoid any more confusion.
            Have a Great Easter

            Comment


              #7
              1) You would have to unclock the code
              2) Would not make any difference. In real-time --> Orders are filled at current market price
              RayNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by thanajo, 05-04-2021, 02:11 AM
              3 responses
              467 views
              0 likes
              Last Post tradingnasdaqprueba  
              Started by Christopher_R, Today, 12:29 AM
              0 responses
              10 views
              0 likes
              Last Post Christopher_R  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              166 responses
              2,236 views
              0 likes
              Last Post sidlercom80  
              Started by thread, Yesterday, 11:58 PM
              0 responses
              4 views
              0 likes
              Last Post thread
              by thread
               
              Started by jclose, Yesterday, 09:37 PM
              0 responses
              9 views
              0 likes
              Last Post jclose
              by jclose
               
              Working...
              X