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

Rounding Error

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

    Rounding Error

    Hey guys I'm having a small problem. I have my code as

    Code:
     //CALCULATE and PRINT RISK REWARD
    								risk = buyEntryPrice - buystopTrigger;
    								reward= buyEntryPrice + profitTarget * TickSize;
    								ratio = Math.Round((reward/risk) * 100); 
    							//Print to Screen the Percentage Return on Trade
    								DrawText("Percent Return" + CurrentBar, true, "ROI %: " +  Instrument.MasterInstrument.Round2TickSize(ratio).ToString(), 1,trigLow - 42 * TickSize, 3, Color.Orange, new Font ("Arial", 9, FontStyle.Bold), StringAlignment.Center, Color.Transparent, Color.Transparent, 0 );
    Results look like this: http://content.screencast.com/users/.../ROI%20pic.png


    What am I doing wrong. can anyone show me Code snippet to get results to show a proper %.

    thank you!

    #2
    Hello ginX10,

    Thanks for your post.

    It is not quite clear if what you are showing is in actual price or tics, so in general:

    To calculate the reward to risk ratio with price:

    risk = buyEntryPrice - buyStopTrigger ;
    reward = ProfitTarget - buyEntryPrice ;
    ratio = Math.Round ((reward / risk) * 100 );

    If you only have the stop and profit targets in tics, then:

    risk = buyEntryPrice - (buyEntryPrice - buyStopTrigger * TickSize) ;
    reward = (ProfitTarget * TickSize + buyEntryPrice) - buyEntryPrice ;
    Ratio = Math.Round ((reward / risk) * 100 );


    Please let me know if I can be of further assistance.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by ginx10k View Post
      Hey guys I'm having a small problem. I have my code as

      Code:
       //CALCULATE and PRINT RISK REWARD
                                      risk = buyEntryPrice - buystopTrigger;
                                      reward= buyEntryPrice + profitTarget * TickSize;
                                      ratio = Math.Round((reward/risk) * 100); 
                                  //Print to Screen the Percentage Return on Trade
                                      DrawText("Percent Return" + CurrentBar, true, "ROI %: " +  Instrument.MasterInstrument.Round2TickSize(ratio).ToString(), 1,trigLow - 42 * TickSize, 3, Color.Orange, new Font ("Arial", 9, FontStyle.Bold), StringAlignment.Center, Color.Transparent, Color.Transparent, 0 );
      Results look like this: http://content.screencast.com/users/.../ROI%20pic.png


      What am I doing wrong. can anyone show me Code snippet to get results to show a proper %.

      thank you!
      Take another look at this statement:
      Code:
      reward= buyEntryPrice + profitTarget * TickSize;
      I doubt that that is the correct reward. More likely, the definition of reward should simply be the profit.
      Code:
      reward= profitTarget * TickSize;

      Comment


        #4
        ROUNDING QUESTION: to Whole Number?

        Quick question. I have the code
        Code:
        roundedSpread = Instrument.MasterInstrument.Round2TickSize(spread);
        which displays http://screencast.com/t/pYdFE24bIy

        I want to know how to display the number as a whole per Instrument's TickSize.

        Example: a .007 spread on E/J would be 7.0. I know that its .007 * 1000 = 7

        So I tried
        Code:
        Instrument.MasterInstrument.Round2TickSize(spread) * TickSize;
        But that gave me a "4E#$@" weird number.

        So is there a way to do this PER Instrument's TickSize

        Comment


          #5
          Hello,

          Thanks for your post.

          To determine the number of ticks of a value, in this case spread, divide the spread by the ticksize.

          roundedSpread = spread / TickSize;

          Please let me know if I can be of further assistance.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Thanks for response. it did give a Whole number. http://screencast.com/t/m3K1tm7wEx

            but still not giving the format I want. as you can see in the pic it shows 16, but the spread is 1.6 am I missing one last piece to get the spread as whole number or mixed number or what ever. I wanna see it say 1.6 or 2.8 not 16 nor 28

            I used this exact code
            Code:
            			roundedSpread = Instrument.MasterInstrument.Round2TickSize(spread)/TickSize;
            thanks!

            Comment


              #7
              Solved

              Nevermind. I just
              Code:
              roundedSpread = Instrument.MasterInstrument.Round2TickSize(spread)/TickSize * .1
              multiplied by .10

              thanks for help!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by RideMe, 04-07-2024, 04:54 PM
              5 responses
              28 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by f.saeidi, Today, 08:13 AM
              1 response
              4 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by DavidHP, Today, 07:56 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by kujista, Today, 06:23 AM
              3 responses
              9 views
              0 likes
              Last Post kujista
              by kujista
               
              Started by Mindset, Yesterday, 02:04 AM
              2 responses
              18 views
              0 likes
              Last Post NinjaTrader_RyanS  
              Working...
              X