Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I don't understand this logic

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

    I don't understand this logic

    Hello,

    When i test my strategy on historical data i receive an error:

    **NT** A BuyToCover stop order placed at '22.06.2010 12:00:00' has been ignored since the stop price is less than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.

    I explore this on chart and i see i create sellstop order in 90. bar and then 91.bar my entry price hit and order execute when execute entry order i create stop entry-x pips from entry. The 91.bar range a little big and my stop price inside this bar body range. Why NT giving this error for this type situations?

    Then i manually add some pips stop price entry-xpips+ 1pip that still inside 91.bar range but outside body range(i mean big from bar.open price and small from bar.high price. This time i don't receive an error but NT stopped this trade. Why NT doing this?

    Actually this trade successful trade i understand this clearly when i look at my chart(I explore price action in 1 min bar chart too.). So with NT do historical test has no meaning!

    I know historical don't have tick by tick test like market replay test. But I think NT behavior is wrong.

    ALSO i really don't understand crossabove and below logic too. Suppose i want to enter long when price fist must be over EMA(21) then must be fall under EMA(21) and if again rise and go above ema21 I want to go long. So simply, i have to define some flags and control EMA21 and close price series cross actions. But at this time suppose price 1.2020 ema21 1.2018 then next bar price do little gap and open new bar at 1.2016 this stuation crossbelow returning false. WHY?

    ALSO ALSO My Strategy Initialize methos have some code. Some code related strategy some codes related indicators for use make a decision buy, sell etc. My strategy calculateonbarclose = false but i want to my indicators don't. for this for example i write like this:

    Add(EMA(21));
    EMA(21).calculateonbarclose = true;

    but at market replay i see EMA calculating tick by tick??????????????? Why? How?

    Thanks...
    Last edited by aytacasan; 08-25-2011, 06:44 AM.

    #2
    aytacasan, what order methods are you using here and which timeframe / symbol are you working on? You might need to add more granular data to simulate getting filled intrabar - http://www.ninjatrader.com/support/f...ead.php?t=6652

    And before submitting a StopMarket / StopLimit order you would need to check for it's validity against the current price, this would be the same as in realtime / simulated trading where invalid stop orders are rejected as well.

    Correct, Market Replay will allow for tick by tick replay with the intrabar formation known in the replayed data portion, in backtesting this is not possible and the CalculateOnBarClose is defaulted to 'true' here by the backtesting engine.

    I'm sorry I did not follow your CrossBelow issue - would you have a chart to demonstrate this perhaps?

    Please call your indicator then on FirstTickOfBar like shown in this example if you would like to keep the strategy code in CalculateOnBarClose = false :

    Comment


      #3
      instrument : 6E 09-11
      Time Frame : 60 Minute
      Orders Types : EnterLongStop & EnterShortStop, I check OrderState in OnExecution if this orders filled/partial filled/cancelled and filled > 0 i use ExitLongStop(StopLoss) and ExitLongLimit(Take Profit) for buy or ExitShortStop(StopLoss) and ExitShortLimit(Take Profit) for sell.

      I'm certainly check price is suitable before crete new order, for example i'm trailing open position via manually and before create new stoploss order i'm checking value is suitable.

      I'm already now using FirstTickOfBar of course my question is not related this. I put my strategy on my chart that strategy calculateonbarclose == false, And its initialize methot i'm adding some indicators for example EMA(21) and i also write EMA(21).calculateonbarclose = true; then start replay and i see on my chart ema21 refreshing tick by tick

      MY OPINION IS IF YOU AVAILABLE I CAN SEND MY CODE MAYBE WE WILL NEGOTIATE BETTER. MY CODE IS CLEAN AND NOT COMPLEX.

      OK?
      Attached Files
      Last edited by aytacasan; 08-25-2011, 08:49 AM.

      Comment


        #4
        aytacasan, first of all : please don't use caps here on the forums as it could be interpreted as shouting which is not acceptable to keep the climate productive and helping - thanks.

        For the rejected stop : please share as simple as possible snippet that would reproduce this so we can check into and offer our suggestions.

        CalculateOnBarClose should not exist in the called indicators, you should not attempt to set this for the indicator at all, just set this generally for the strategy and the logic outlined in the sample then for merging on bar close and on every tick calculations using FirstTickOfBar.

        We will look into the CrossAbove logic as well, which EMA are you exactly using in your example?

        Thanks,

        Comment


          #5
          Hi Bertrand,

          Sory if you feel like this, my purpose is only to indicate what is so important in my post, like underline some words. There was no bad intention, after that I will be more careful about it, maybe use different colors.

          About simple snippet: i want to send all strategy code via private message. You'll see complete code is like snippet. When code arrive you, If you still want this again form me, i'll try to cut some lines.

          I understand CalculateOnBarClose issue clearly. But if so there is a big proplem. Because i think there is a bug and this don't be easy to show you. But if you want i can give you some inputs. How can you live this problem on your screen. Shortly, one bar giving short signal(via two EMA cross) very long red bar and my strategy create EnterShortStop and next bar small bull bar cause to cancel order(this time reverse cross occur). Actually as logic this is imposible, already NT chart refreshing seceonds later but my order previously cancelled(should not be).

          Lastly, in my screenshot blue EMA period is 21.

          Regards.
          Last edited by aytacasan; 08-26-2011, 07:17 AM.

          Comment


            #6
            If you like you can send me the stripped down code showing the issue to our support email (support at ninjatrader dot com) to my Attn.

            I'm sorry but not following you on where you see the issue with CalculateOnBarClose, if you work in the supported framework shown in our example you would be able to combine both ways to call the OnBarUpdate(), COBC false / true.

            I checked into your CrossAbove issue and don't see why you feel this is incorrect, please see the screenshot attached, plotting the price as Line On Close and your 21 EMA for comparisons, in addition the study plots a dot below the bar exactly where your expressed condition triggered - before those 2 blue dots on the 1st of June, there was no crossover of the close price over the EMA 21.
            Attached Files

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              If you like you can send me the stripped down code showing the issue to our support email (support at ninjatrader dot com) to my Attn.

              I'm sorry but not following you on where you see the issue with CalculateOnBarClose, if you work in the supported framework shown in our example you would be able to combine both ways to call the OnBarUpdate(), COBC false / true.

              I checked into your CrossAbove issue and don't see why you feel this is incorrect, please see the screenshot attached, plotting the price as Line On Close and your 21 EMA for comparisons, in addition the study plots a dot below the bar exactly where your expressed condition triggered - before those 2 blue dots on the 1st of June, there was no crossover of the close price over the EMA 21.
              I think no need to send you code. Because I understand actually what is my strategy problems. Please tell me these:

              1. If I want to work with calculateonbarclose=true strategy and if i want to check crossabove to series how should i write the code? Of course like this

              OnBarUpdate()
              if (crossabove(EMA(X), EMA(Y), 1) then buystop(High[0]+ 5pip) else sellstop(Low[0]-5pip);

              But now i want to work with calculateonbarclose=true strategy and my code have to change like this:

              OnBarUpdate()
              if (firsttickofbar)
              {
              if (crossabove(EMA(X), EMA(Y), 2) then buystop(High[1]+5pip) else sellstop(Low[1]-5pip);
              }

              am i right? If so sometimes when one bar first tick come crossabove returning true and then next ticks cross stuation maybe change because tick by tict in progress.

              Shortly when i first tick is come, I don't want to consider last bar instant case for decide to buy/sell, i want to consider previous compalitly finished bar case about crossover is happend or not. How can i do this?

              2.Yes you are right, i think about it later and cross function is actually not incorrect but problem is it's not appropriate for my strategy. Because, suppose open[1] and close[1] above EMA(suppose bear candle) and next bar happening gap and open[0] below EMA but bar closed above EMA (bull candle) so actually croseabove(close, EMA, 1) return false. But for my strategy logic actually price go below EMA and return above EMA I think for this i have to write own function that compalitly consider this stuations. If i'm not wrong there is not any inline function at NT for this.Isn't it?

              3.When i work COBC=true and also if i need Last Price: i could override OnMarketData fuction and read last price manually from this function. I know this but i want to learn this, is there any other way for do this?

              Regards.
              Last edited by aytacasan; 08-28-2011, 01:46 PM.

              Comment


                #8
                aytacasan, in this case I would then custom code the cross condition needed, as you could point directly to the EMA index values to compare for comparison, if you reference here the bar back further the open tick on which you call the calcs would not have any influence or 'whipsaw' your condition as it becomes true intrabar.

                The crossing statement you had would only deal with the Close values thus not incorporating any logic related to the candle formation (OHL), this could be definitely custom code then to be picked up.

                Correct, in COBC = true you could still 'grab' the last value from OnMarketData() - the other way would be setting COBC = false and using Close[0] here as replacement should you wish to work from OnBarUpdate().

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                646 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                367 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                107 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                569 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X