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

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.



    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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.

              JesseNinjaTrader Customer Service

              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 Max238, Today, 01:28 AM
                  5 responses
                  42 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Started by giulyko00, Yesterday, 12:03 PM
                  3 responses
                  12 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by habeebft, Today, 07:27 AM
                  1 response
                  14 views
                  0 likes
                  Last Post NinjaTrader_ChristopherS  
                  Started by AveryFlynn, Today, 04:57 AM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by r68cervera, Today, 05:29 AM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X