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

Simple buy and sell strategy not working

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

    Simple buy and sell strategy not working

    The code below is to to place a buy or sell order when triggered.Can you tell me why it doesn't trigger when price is hit? Thanks.

    #region Variables
    // Wizard generated variables
    privateint myInput1 = 1; // Default setting for MyInput1
    privateint myInput2 = 1; // Default setting for MyInput2
    privatestring myInput3 = @""; // Default setting for MyInput3
    privatedouble myInput4 = 1; // Default setting for MyInput4
    privatedouble myInput5 = 1; // Default setting for MyInput5
    // 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()
    {
    CalculateOnBarClose =
    false;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(High, MyInput4, 1))
    {
    EnterShort(DefaultQuantity,
    "");
    }
    // Condition set 2
    if (CrossBelow(Low, MyInput5, 1))
    {
    EnterLong(DefaultQuantity,
    "");
    }

    #2
    From a quick view over the code you want to make sure you input the correct trigger prices as inputs 4 + 5 in reference to the market you run this on.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I adjust the trigger prices when I am running the strategy but I notice a few things when running it.
      1-Sometimes it doesn't work .I have noticed it when the account section is grayed out .
      2-It seems I have to refresh/apply the strategy each time a target is triggered? Is this how it is suppose to work? I need it to continously place orders when targets are hit.
      3-I set the quantity to default but it places a cover order and a trigger order at the same time? anotherwards it reverses direction byitself.

      Comment


        #4
        Hi yellowTrader,

        1. Account section would be greyed out if you are in Sim and thus can only trade on the Sim101 account.

        2. Not sure I follow, since you run this on CalculateOnBarClose = false it should trigger for each cross above / below your input level.

        3. Well this would make sense if you levels are close enough together to be both hit intrabar, especially with your CalculateOnBarClose setting.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Bertrand,
          1-As you can see in the attachment the account section is not Sim101 and it is IB paper account and is grayed out.
          2-When it triggers on the sell side , it places one for "short sell" and another order for "Sell" and when buy side triggers it places an order for "buy to cover" and another order for "buy". Anotherwords it reverses direction which is ok but I want to turn this feature off sometimes.
          3-No the targets are not that close they are a few points apart.
          4-And the most important issue is that the whole strategy works only sometimes ,not all the times. For example I was trying to run the same strategy for both ES and NQ but it only worked for ES and then after a while it started working for NQ as well.
          Attached Files

          Comment


            #6
            1. If you wish to be in simulation please go to the File menu and check the Global Simulation Mode option.

            2. You cannot turn this off. If you don't want to reverse do not submit an entry order on the opposite side of the market. Instead just submit an exit order.

            3. If you are short it will always place you a cover and entry order. Again, if you only want to exit, do not place an EnterLong order. Place an ExitShort order.

            4. You will need to elaborate more on this. Please use TraceOrders = true so you can monitor your orders in the Output Window.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              I am trying to create a time based condition so I can change the value of the time by user defined inputs. But while trying to define the condition using the "condition builder" I can't find any tools to Code a simple condition like:
              If Currentbar = 11:35 AM (where 11:35 is the value of user defined input).
              How can this be done?

              Comment


                #8
                Unfortunately this cannot be done in the wizard, as you would need a DateTime input type. You can however set the manually with the TimeSeries and TimeValue methods.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Doing it manually won't do me any good. I need to be able to change the time values quickly while the strategy is running Just like I am able to chamge price values.
                  You mentioned this can't be done using the wizard. Can it be done any otherway? Can be done straight from the editor?

                  Comment


                    #10
                    Sure, you can add a user defined input to your code from the editor - http://www.ninjatrader-support2.com/...ead.php?t=5782
                    Code:
                    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] DateTime myTime;[/SIZE][/SIZE]
                    [SIZE=2][SIZE=2][/SIZE][/SIZE]

                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      It seems the exit order triggered by a startegy doesn't work when the initial order is placed manually (not placed by the strategy). Is there anyway for a strategy to recognize the excisting positions and act accordingly?

                      Comment


                        #12
                        Unfortunately not yellowTrader - but you could for example call an ATM to manage the exits - http://www.ninjatrader-support.com/H...trategies.html
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          I have setup a simple spread strategy using five user defined inputs . Two of which are the values for upper and lower range and two are the values to exit trade with profit and one is for number of ticks for stop orders.
                          When I type in the values and run the strategy it seems it is working fine but as I need to change these values the strategy seems to go a bit crazy and becomes inconsistant and sends the stop order first before values are triggered.
                          What seems to be the problem? Am I not able to change values after the first run?

                          Comment


                            #14
                            yellowTrader,

                            If you change values you need to restart your strategy.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Ok then. Since I change these numbers quite often and can't keep restarting strategies during trading, what do you recommend I do?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by llanqui, Yesterday, 10:29 AM
                              3 responses
                              22 views
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Started by cshox, Today, 11:11 AM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by Seneca, 08-25-2020, 08:31 AM
                              4 responses
                              5,953 views
                              0 likes
                              Last Post Tin34
                              by Tin34
                               
                              Started by TAJTrades, Today, 11:03 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post TAJTrades  
                              Started by wuannetraam, Today, 02:40 AM
                              3 responses
                              26 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X