Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating distance between ema and high of a bar is wrong

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

    Calculating distance between ema and high of a bar is wrong


    HI, My calculation of distance between high of signal bar and slow ema 34(gold line) is not correct. In settings I placed 1 tick but it opens with distance of a lot more then just one tick. See Pic. Can you provide me with a suggestion on how to fix it?

    AboveBelowForType2 = 1;


    else if (TradeType2
    && emaAngulation < -EMAAngulation * TickSize
    && emaAngulationXBarsBefore < -EMAAngulationXBarsBefore * TickSize
    && Close[1] > Open[1] // previous bar bullish
    && High[0] > High[1] // current higher high
    && Close[0] < slowEMA[0] // closing above 34
    && slowEMA[0] < cEMA89[0] // 34 is not above 89
    // && High[0] > slowEMA[0] - AboveEMATicks * TickSize && Close[0] < slowEMA[0])
    && High[0] <= slowEMA[0] + AboveBelowForType2 * TickSize // and current bar reversed below Slow EMA(gold line)
    )
    {
    entryOrder = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.Market, TradeSize, 0, 0, "", "BT");

    return;
    }​

    [NinjaScriptProperty]
    [Range(0, int.MaxValue)]
    [Display(Name="Above Below 34EMA ", Description="Type 2 above or below 34ema ticks", Order=9, GroupName="Parameters")]
    public int AboveBelowForType2
    { get; set; }​



    Attached Files
    Last edited by tkaboris; 02-01-2023, 06:57 PM.

    #2
    Hello tkaboris,

    From the given code I don't specifically see what may be happening. I would suggest using a Print to make sure the calculated value is being correctly calculated.

    I also see that a market order is being used and it looks like possibly a renko or price movement based series. Depending on the settings of your script this could also relate to when the condition is becoming true and when the order is submitted. A market order can have slippage so it may move around the general price zone you specified when filled.



    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello tkaboris,

      From the given code I don't specifically see what may be happening. I would suggest using a Print to make sure the calculated value is being correctly calculated.

      I also see that a market order is being used and it looks like possibly a renko or price movement based series. Depending on the settings of your script this could also relate to when the condition is becoming true and when the order is submitted. A market order can have slippage so it may move around the general price zone you specified when filled.


      I cant figure it out. Is there a way to share code with you?

      Comment


        #4
        Hello tkaboris,

        You can paste code into the reply or attach a .cs file for the code. We can't debug your code but we can review it to get a better idea on how to assist.

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello tkaboris,

          You can paste code into the reply or attach a .cs file for the code. We can't debug your code but we can review it to get a better idea on how to assist.
          That would be great.
          Its about strategy called Trade34B2



          Attached Files

          Comment


            #6
            I attached the strategy code, but i dont see it. Did you get it?

            Comment


              #7
              Hello tkaboris,

              I was unable to see what the problem is in the file you had attached, it was also pretty complex so you will need to use prints to debug the script further.

              Comment


                #8
                Hi tkaboris.

                I'll take a look.

                Which line numbers should I focus on?

                Comment


                  #9
                  Originally posted by bltdavid View Post
                  Hi tkaboris.

                  I'll take a look.

                  Which line numbers should I focus on?
                  Hi, on line 191 I mainly focus on Trade34B2 setup. There are several strategies included and they all seem working but Trade34B2 is not opening the right way.

                  str.cs

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  53 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  130 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  70 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  44 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  49 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X