Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

pattern to calculate stop ticks from other stop calcluation modes

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

    pattern to calculate stop ticks from other stop calcluation modes

    Money Management Scenario -
    variable nticks has a related cash value <= param riskFactor - % of tradeable account size.
    Rules exist to validate that the size of the stop is with <=nticks.
    Before the stop is place the stop size is validated. It must work for all stop calculation mode - without changing the placeStop method...

    Following code
    Stops maybe place in the following enum modes via method:
    It also has an initial simple version for stop tick calculation - which only works for
    ticks,currency,ATRPercentage(same as ticks)

    I guess i am looking for input as to how to express a % and price stop as ticks
    version 1.0 below

    ///<summary>
    /// Enum for stop or target price calculation
    ///</summary>
    publicenumorderCalculationMode
    {
    Percent = 0,
    Price = 1,
    Ticks = 2,
    Currency = 3,
    ATRPercentage = 4
    }
    ///<summary>
    /// Place Stop by this.Stop value and this.StopCalcMode orderCalculationMode
    ///</summary>
    publicvoid placeStop()
    {
    if (Stop > 0)
    {
    if (StopCalcMode == (int)orderCalculationMode.ATRPercentage)
    {
    //stop is a percentile
    SetStopLoss("", CalculationMode.Ticks, Instrument.MasterInstrument.Round2TickSize((aTRVal ue * Stop) / 100), SimulatedStop);
    }
    elseif (StopCalcMode == (int)orderCalculationMode.Currency)
    {
    //stop is cash
    SetStopLoss(this.Stop, SimulatedStop);
    }
    elseif (StopCalcMode == (int)orderCalculationMode.Percent)
    {
    //stop is a percentile
    SetStopLoss("", CalculationMode.Percent, Stop, SimulatedStop);
    }
    elseif (StopCalcMode == (int)orderCalculationMode.Price)
    {
    //stop is a price
    SetStopLoss("", CalculationMode.Price, Stop, SimulatedStop);
    }
    elseif (StopCalcMode == (int)orderCalculationMode.Ticks)
    {
    //stop is n ticks
    SetStopLoss("", CalculationMode.Ticks, Stop, SimulatedStop);
    }
    }
    }


    ///<summary>
    ///
    returns stop ticks
    ///</summary>
    ///
    <param name="stop"></param>
    ///
    <returns></returns>
    privatedouble calcStopTicks(double stop)
    {
    if (StopCalcMode == (int)orderCalculationMode.ATRPercentage)
    {
    return Instrument.MasterInstrument.Round2TickSize(aTRValu e * (stop / 100));
    }
    elseif (StopCalcMode == (int)orderCalculationMode.Currency)
    {
    return Instrument.MasterInstrument.Round2TickSize(stop / (Instrument.MasterInstrument.PointValue * tickValue));
    }
    elseif (StopCalcMode == (int)orderCalculationMode.Ticks)
    {
    return stop;
    }
    else
    {
    thrownewException("Stop Calculations only valid with StopCalcMode ATRPercentage,Currency,Ticks");
    }
    return -1;
    }
    Last edited by MicroTrends; 07-02-2010, 07:07 AM.
    MicroTrends
    NinjaTrader Ecosystem Vendor - micro-trends.co.uk

    #2
    Hi MicroTrends,

    To clarify, is this code working for you as is or are you experiencing a specific issue?
    TimNinjaTrader Customer Service

    Comment


      #3
      Hi the code works whereby i wish to obtain the stop value in ticks from all possbile calculation modes - so validation of stop size can occure before placement. I was looking for any input on how to get the ticks for a stop which will use price or %.
      The bottom method will do it for ticks and currency.

      I guess really that for % it is just a case of:

      for a short -reverse for long
      ticks = Round2TickSize(close[0] -(close[0] + n%))

      price

      ticks = Round2TickSize(close[0] -(nPrice))
      MicroTrends
      NinjaTrader Ecosystem Vendor - micro-trends.co.uk

      Comment


        #4
        Hi MicroTrends,

        An intriguing idea, however, unfortunately, we do not offer custom writing of code logic, perhaps others can give some helpful input here.
        TimNinjaTrader Customer Service

        Comment


          #5
          no problem - getCurrentAsk might be better than close for anyone looking at it...:-)
          MicroTrends
          NinjaTrader Ecosystem Vendor - micro-trends.co.uk

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,227 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          7 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          440 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          12 views
          0 likes
          Last Post FAQtrader  
          Working...
          X