Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cobc

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

    Cobc

    Hello,

    when I have set COBC=true in the script strategy then "setstoploss" works also within a bar and not only at close of bar.

    But for my targets eg
    if (GetCurrentAsk(0) < Position.AvgPrice - 6 * TickSize)
    ExitShort..........;

    this is only realized at close of bar, so eg with 5 Range-Bars with 10 pips in profit and not with 6 pips.

    How can one do with COBC so that also targets are realized at certain pips and not close of bar (but avoiding "setprofittarget" - as I don´t want to work with brackets)

    Thank you!
    Tony

    #2
    Hello tonynt,
    Thanks for writing in and I am happy to assist you.

    You can set COBC to true place your exit logic in the OnMarketData event. As such your entry codes which is placed in OnBarUpdate will be calculated at bar close but your exits will be calculated realtime.



    Alternatively you can set COBC to false but filter the entry codes in the FirstTickOfBar (thus it gets calculated only once at the start of the bar). Since COBC is set to false your exit logic will be calculated on every tick.

    Please see the below sample code which demonstrates this.


    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.

      The question is only important because of CPU of my computer (or maybe its not important). Is there a big difference for CPU and PC-ressources when running a script-strategy with COBC=true or with COBC=false? If not, I can continue using COBC=false.

      In the meantime I found in the forum the information that "OnBarUpdate() fires on each bar update or tick (COBC setting for study), while the OnMarketData() fires on each Level 1 event change (bid, ask, last ...)" - does this work on forex? And is there a difference for the PC-ressources then?

      At this moment I want to add another question please: is it possible to start a script with "SetStopLoss("S2A", CalculationMode.Ticks, 10, false);" but to change it later on referring to certain condtions to "SetTrailStop("S2A",CalculationMode.Ticks, 3, false);

      (I know I can not use both together, therefore I ask if I can substitute SetStopLoss by SetTrailStop during a running script, eg when certain ticks in profit. For better understanding - its not only to change 10 by 3 - of course I could do only with Trail - this is only an example here, the SetStopLoss starts with certain variables)

      Thank you!
      Tony


      Originally posted by NinjaTrader_Joydeep View Post
      Hello tonynt,
      Thanks for writing in and I am happy to assist you.

      You can set COBC to true place your exit logic in the OnMarketData event. As such your entry codes which is placed in OnBarUpdate will be calculated at bar close but your exits will be calculated realtime.



      Alternatively you can set COBC to false but filter the entry codes in the FirstTickOfBar (thus it gets calculated only once at the start of the bar). Since COBC is set to false your exit logic will be calculated on every tick.

      Please see the below sample code which demonstrates this.


      Please let me know if I can assist you any further.
      Last edited by tonynt; 03-09-2012, 01:34 PM. Reason: clearify question

      Comment


        #4
        Hello tonynt,
        How CPU intensive it will be depends on your code. For example if your entry logic are complex and CPU intensive but your exit codes are not, then your strategy wont be CPU intensive since the entry logic are being calculated once.

        OnMarketData opens a data stream and you will get all bid/ask/last price through OnMarketData and thus it is resource intensive. However you can filter the data as:
        Code:
        protected override void OnMarketData(MarketDataEventArgs e)
        {
        	if (e.MarketDataType == MarketDataType.Last)
        	{
        		//do something only when last price updates
        	}
        }

        No, you cannot mix SetStopLoss with SetTrialStop.

        However you can reassign the SetStopLoss method.

        For example if you initially placed SetStopLoss(CalculationMode.Tick, 10) order you can reassign it as SetStopLoss(CalculationMode.Tick, 3). This will change your stop loss order.

        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Thank you. To understand correctly - for same entry-conditions which one is more CPU intensive - onbarupdate or onmarketdata?

          And last question in this concern please: when I have COBC=false; and simple entry-condtion eg Close[0] < Open[0]) why is the entry done immediately when enabling the strategy - and now when "Close" < Open?

          Thanks
          Tony

          Originally posted by NinjaTrader_Joydeep View Post
          Hello tonynt,
          How CPU intensive it will be depends on your code. For example if your entry logic are complex and CPU intensive but your exit codes are not, then your strategy wont be CPU intensive since the entry logic are being calculated once.

          OnMarketData opens a data stream and you will get all bid/ask/last price through OnMarketData and thus it is resource intensive. However you can filter the data as:
          Code:
          protected override void OnMarketData(MarketDataEventArgs e)
          {
              if (e.MarketDataType == MarketDataType.Last)
              {
                  //do something only when last price updates
              }
          }
          No, you cannot mix SetStopLoss with SetTrialStop.

          However you can reassign the SetStopLoss method.

          For example if you initially placed SetStopLoss(CalculationMode.Tick, 10) order you can reassign it as SetStopLoss(CalculationMode.Tick, 3). This will change your stop loss order.

          Please let me know if I can assist you any further.
          Last edited by tonynt; 03-09-2012, 02:48 PM.

          Comment


            #6
            Hello tonynt,
            OnMarketData will be more resource intesive.

            From help file:
            This is a real-time data stream and can be CPU intensive if your program code is compute intensive (not optimal)


            It is difficult to say without seeing the complete code, but with COBC set to false, orders will be submitted as and when the condition meets and wont wait for the close of the bar. If you want the trades to be submitted only on the close of the bar with COBC set to false then please filter the code with FirstTickOfBar function.

            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Thank You! So, finally for understanding the Close[0]

              The code simply (for testing COBC) is:
              (COBC=false)
              .........
              if (Position.MarketPosition == MarketPosition.Flat && Close[0] < Open[0])
              {EnterShort(1000, "S1A");}

              The entry is not after close - its immediately when enabling the strategy.

              Shouldn´t be the entry only after "Close[0]" even when COBC= false?

              Then we got it.

              Thank you
              Tony

              Originally posted by NinjaTrader_Joydeep View Post
              Hello tonynt,
              OnMarketData will be more resource intesive.

              From help file:



              It is difficult to say without seeing the complete code, but with COBC set to false, orders will be submitted as and when the condition meets and wont wait for the close of the bar. If you want the trades to be submitted only on the close of the bar with COBC set to false then please filter the code with FirstTickOfBar function.

              Please let me know if I can assist you any further.
              Last edited by tonynt; 03-09-2012, 03:38 PM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by FrancisMorro, Today, 03:24 AM
              0 responses
              1 view
              0 likes
              Last Post FrancisMorro  
              Started by Segwin, 05-07-2018, 02:15 PM
              10 responses
              1,770 views
              0 likes
              Last Post Leafcutter  
              Started by Rapine Heihei, 04-23-2024, 07:51 PM
              2 responses
              31 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by Shansen, 08-30-2019, 10:18 PM
              24 responses
              944 views
              0 likes
              Last Post spwizard  
              Started by Max238, Today, 01:28 AM
              0 responses
              11 views
              0 likes
              Last Post Max238
              by Max238
               
              Working...
              X