# NEOTICKER DATA BEGIN ScriptType=Indicator Description=Brokerage Position Monitor Name=BrokeragePositionMonitor Language=Formula Links=1 MinBars=0 TimerInterval=100 EarlyBinding=0 MetaStyle=Normal ValueRange=Same as Source Placement=Smart Multiplot_num_plots=2 Multiplot_color_0=255 Multiplot_style_0=Line Multiplot_width_0=1 Multiplot_enabled_0=1 Multiplot_name_0=Pos Size Multiplot_breakstyle_0=0 Multiplot_color_1=33587200 Multiplot_style_1=Line Multiplot_width_1=1 Multiplot_enabled_1=1 Multiplot_name_1=Pos $ P/L Multiplot_breakstyle_1=0 UpdateByTick=0 TradingSystemUI=1 PrimaryLinkOnly=1 NotifyOnRemoval=0 Param_count=3 Param_name_0=Max Position Size Param_inuse_0=1 Param_type_0=integer.gt.0 Param_default_0=3 Param_name_1=Max Dollar Loss Param_inuse_1=1 Param_type_1=real Param_default_1=500 Param_name_2=Trailing Period Param_inuse_2=1 Param_type_2=integer Param_default_2=20 Explanation_Lines=0 # NEOTICKER DATA END ' Brokerage Position Monitor ' written by Lawrence Chan ' Copyright (c) 2006 TickQuest Inc. ' All Rights Reserved ' Links ' 1 - price series ' Usage ' 1. set the correct price multiple and min tick size in the system tab ' 2. disable single entry per direction and close position eod ' 3. link to the instrument you trade ' 4. enable brokerage interface and obtain feedback from the brokerage ' calculation should not start until after real-time update $ready := (islastbar <> 0) or ($ready <> 0); ' get current brokerage data $current_pos_size := BrokerPosSize; $current_pos_entrycost := BrokerPosAvgEntry; $abs_pos_size := absvalue ($current_pos_size); plot1 := if ($ready, $current_pos_size, 0); plot2 := choose ( $ready = 0, 0, $current_pos_size > 0, (c - $current_pos_entrycost), $current_pos_size < 0, ($current_pos_entrycost - c), 0) * pricemultiple; ' basic conditions $in_short := $ready <> 0 ' we are in real-time update and $current_pos_size < 0; ' and we are currently in a short position $in_long := $ready <> 0 ' we are in real-time update and $current_pos_size > 0; ' and we are currently in a long position ' absolute stop loss based on position wide stop loss amount $shortside_stoploss := $in_short <> 0 and plot2 <= - param2; buyatmarkettif ( $shortside_stoploss, $abs_pos_size, otfGoodTilCancel, "Exit short - abs stop loss"); $longside_stoploss := $in_long <> 0 and plot2 <= - param2; sellatmarkettif ( $longside_stoploss, $abs_pos_size, otfGoodTilCancel, "Exit long - abs stop loss"); ' absolute maximum position exposure checking $shortside_overexposure := $in_short <> 0 and $abs_pos_size > param1; buyatmarkettif ( $shortside_stoploss = 0 and $shortside_overexposure <> 0, $abs_pos_size - param1, otfGoodTilCancel, "Cover extra short contracts"); $longside_overexposure := $in_long <> 0 and $abs_pos_size > param1; sellatmarkettif ( $longside_stoploss = 0 and $longside_overexposure <> 0, $abs_pos_size - param1, otfGoodTilCancel, "Cover extra long contracts"); ' Example of trailing stop $shortside_trailing := $in_short <> 0 and plot2 > 0 ' we are profitable and hhv (1, h, param3) < h; ' the previous highest high is violated buyatmarkettif ( $shortside_stoploss = 0 and $shortside_overexposure = 0 and $shortside_trailing <> 0, $abs_pos_size, otfGoodTilCancel, "Cover short - trailing stop"); $longside_trailing := $in_long <> 0 and plot2 > 0 ' we are profitable and llv (1, l, param3) > l; ' the previous lowest low is violated sellatmarkettif ( $longside_stoploss = 0 and $longside_overexposure = 0 and $longside_trailing <> 0, $abs_pos_size, otfGoodTilCancel, "Cover long - trailing stop");