• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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#[email protected]" 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 rontronimous, Today, 06:12 PM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by Vinhasa, Today, 03:15 PM
              3 responses
              13 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by 1001111, Today, 03:03 PM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Tyler  
              Started by Seedbird, Today, 03:06 PM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_BrendanC  
              Started by mtamaku, Today, 02:46 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Kate  
              Working...
              X