Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using calculated target for other functions within strategy

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

    Using calculated target for other functions within strategy

    Hi all; This is a roll over from last nights discussion:

    I have calculated my profit target:

    targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + (Instrument.MasterInstrument.Round2TickSize(10 * (ATR(14)[0]))), "LE Target", "LE Mmamo2");

    Please note I have used a value of ATR on the bar of entry to calculate a number of ticks to set my target at. (This is coded under 'OnExecution').

    Question is ...... how do I reference this value (# of ticks from formula 10 * (ATR(14)[0]) for use in other calculations in 'OnBarUpdate'.

    For example if I wished to code a proximity exit along the lines of 'If Close[2] is > 90% of my target and the most recent closes were down .... exit.

    If I use 'targetOrder' .... eg (0.9 * targetOrder) ... I get error messages about using operands etc.

    So far I have:

    OnBarUpdate

    { //Proximity exit here. If unrealized PnL > 90% of target in the last 3 bars but price retracing, exit
    if (Position.MarketPosition == MarketPosition.Long && Close[0] < Close[1] && Close[1] < Close[2] && Close[2] > (0.9 * (Instrument.MasterInstrument.Round2TickSize(15 * (ATR(5)[0]))))

    if (stopOrder != null && stopOrder.StopPrice < Position.AvgPrice)
    {
    ExitLong(stopOrder.Quantity, "Prox-Stop", "LE Mmamo2");
    }
    }

    Obvious problem here is I am now using a different value for ATR and as I don't know how many bars will have passed since entry I cant reference the entry bar !!!

    Any suggestions please.

    Ben.

    Have missed Position avg price in formula above sorry. Should read:

    ........ && Close[2] > 0.9 * (Position.AvgPrice + (Instrument.MasterInstrument.Round2TickSize(15 * (ATR(5)[0])))))
    Last edited by stocktraderbmp; 12-21-2011, 06:43 PM. Reason: Missed some code

    #2
    Your original Target would be targetOrder.LimitPrice and the average entryPrice will be entryOrder.AvgFillPrice.

    Just by looking at your code, I that know you can handle the rest.
    Last edited by koganam; 09-02-2014, 03:40 PM.

    Comment


      #3
      Yep thanks;

      Just got up after some well earned rest. Sometimes you can't see the wood for the trees and just need to walk away for a bit.

      Thanks again K. Hope you have a good holiday.

      Ben.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      648 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      109 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      573 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      575 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X