Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ask and Bid prices in the same strategy

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

    Ask and Bid prices in the same strategy

    Hi,

    How can I open order (buy) by Ask price but close it by Bid price?

    Now when I do EnterLong()\ExitLong() it always use Bid price?

    Thanks,
    Ronen

    #2
    Hello ronenk,

    Thank you for your post.

    You can use GetCurrentAsk() and GetCurrentBid() to pull the price levels you wish, and then submit the orders to the side you wish to enter.
    For example:
    Code:
    			if (Close[0] > Open[0])
    				EnterLongStop(GetCurrentAsk());
    			if (Close[0] < Open[0])
    				ExitLongStop(GetCurrentBid());

    Comment


      #3
      How can I get value of bar on script init

      Hi,

      Thanks for your previous answer.

      Now I have another problem:

      I need to get open/high/low/close price of bar for specified time, for different instrument, for example:

      OnConfigure I add new data series

      else if (State == State.Configure)
      {
      AddDataSeries("6A 06-16", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Ask);
      AddDataSeries("6B 06-16", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Ask);
      }

      and on (State == State.DataLoaded)

      I need to be able to get price for bar that was in the past, for example 2016.4.27 10:00 for data serie 1:

      int bar_no = CurrentBars[1] - BarsArray[1].GetBar(new DateTime(2016,4,27,10,00,00))
      Print(Times[1][bar_no]);


      This returns error, because Times[1] has no bars? but BarsArray[1].GetBar(new DateTime(2016,4,27,10,00,00) returns some integer number.


      Some how do I get price per instrument per time at State.DataLoaded state?

      Thanks!

      Comment


        #4
        Hello ronenk,

        The earliest you would be able to check for this is in State.Transition.

        All historical data will need to be processed by the script first before it can retrieve the historical bar located at the bar index you are obtaining with GetBar().
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          How to I remove a timeseries?

          I need to get data from different dataseries and I don't want to load them all at once, I need to load them dynamically, add data series, do some actions, remove data series... If i load all (there're more than 100 my computers stucks...)

          How can I do it?

          Is there something like:
          RemoveDataSeries(id); ? that will remove it from memory.

          thanks

          Comment


            #6
            Hello ronenk,

            Unfortunately, there isn't a way to dynamically add or remove data series. We are currently tracking such a feature request with the tracking ID of SFT-882.

            I will add your vote to this feature request.

            Please, let us know if we may be of further assistance.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Restart strategy

              Thanks for your answer,

              If I cannot dynamically add or remove data series, I can solve it if I could restart strategy, so it'll run (State == State.Configure) part.

              Is there any way to automatically restart strategy from inside itself?

              For example:

              else if (State == State.Configure)
              {

              AddDataSeries("6E 06-16", Data.BarsPeriodType.Minute, 1,Data.MarketDataType.Ask);

              } else if (State == State.DataLoaded) {
              // Do some actions with loaded data

              StrategyRestart();


              }


              Thanks,
              Ronen

              Comment


                #8
                So is there any way to restart strategy?

                So is there any way to restart strategy?

                Comment


                  #9
                  Hello ronenk,

                  Thank you for your patience.

                  There would not be any supported means within NinjaScript to restart the strategy within itself.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by cmtjoancolmenero, Yesterday, 05:05 PM
                  2 responses
                  30 views
                  0 likes
                  Last Post cmtjoancolmenero  
                  Started by naanku, Yesterday, 07:25 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by nissan200sx55, Yesterday, 06:25 AM
                  3 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by memonic, 05-01-2024, 01:23 PM
                  6 responses
                  32 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by fredericlebre, Today, 01:19 AM
                  1 response
                  15 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Working...
                  X