Vous êtes sur la page 1sur 3

Summary: This indicator script is a price momentum indicator that measures the position o f an underlying symbol price relative

to its moving average. Calculation: The difference between the typical price of an underlying symbol and its simple moving average, divided by the mean deviation of the typical price. Developer: Donald R. Lambert Interpretation: 1. Overbought: When the underlying indicator is moving upwards, but the indicato r script is approaching its upper bound, the underlying indicator is likely to r everse direction and move downwards. 2. Oversold: When the underlying indicator is moving downwards, but the indicato r script is approaching its lower bound, the underlying indicator is likely to r everse direction and move upwards.

Summary: This trading system script generates orders based on the overbought / oversold s tatus of a single indicator. Rules: 1. Buy Market - When the indicator is oversold. 2. Sell Market - When the indicator is overbought. 3. Sell Short Market - When the indicator is overbought. 4. Buy To Cover Market - When the indicator is oversold. ******************************************************************************** **** ' Assign the script parameters to script variables. _overboughtValue = overboughtValue _oversoldValue = oversoldValue _enableShorting = enableShorting _stopLoss = stopLoss _takeProfit = takeProfit _trailingStop = trailingStop _isPercent = isPercent OutputWriteLine("hi world") ' Use for holding indicator keys based on the specified indicator key, i ndexed by symbol index. Redefine _indicatorKeys(SymbolCount() - 1) ' Iterate over all of the account symbols. For i As Integer = 0 To SymbolCount() - 1 ' Create an indicator for each account symbol, based on the spec ified indicator. _indicatorKeys(i) = IndicatorCopy(indicatorKey, i) ' Add the indicator to the symbol chart. ChartIndicator(i, 0,C_MERGE_LEFT, _indicatorKeys(i),C_LINE,1, C_ BLUE) Next

**********************************************************

' Check whether the current symbol is a futures contract which isn't a f ront month contract

If (SymbolInstrument(symbolIndex) = C_FUTURES And Not SymbolIsFrontMonth Contract(symbolIndex)) Return End If ' Get the indicator value, indexed by bar index. Define value As Number = IndicatorValue(_indicatorKeys(symbolIndex)) ' Oversold. If (value < _oversoldValue) Then ' If a short position exists then generate a buy to cover order. If (_enableShorting And PositionExists(C_OPEN, symbolIndex, C_SH ORT)) Then ' Generate a buy to cover market order. BrokerMarket(C_BUY_TO_COVER, symbolIndex, 0, C_DAY, "Ove rsold.") End If ' If no long open positions exist. If (Not PositionExists(C_OPEN, symbolIndex, C_LONG)) ' Generate a buy market order. Define orderIndex As Number = BrokerMarket(C_BUY, symbol Index, 0, C_DAY, "Oversold.") ' Set a stop loss on the order. BrokerSetStopLossPercent(orderIndex, _stopLoss, True) ' Set a take profit on the order. BrokerSetTakeProfitPercent(orderIndex, _takeProfit, True ) ' Set a trailing stop loss on the order. BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trail ingStop) OutputWriteLine("OnSymbolBar Sell " &value &" Symbol I ndex is " &symbolIndex ) OutputWriteLine("Symbol Count = " &SymbolCount) OutputWriteLine("Symbol Id = " &SymbolID(symbolIndex)) End If ' Overbought. ElseIf (value > _overboughtValue) Then ' If a long open position exists. If (PositionExists(C_OPEN, symbolIndex, C_LONG)) ' Generate a sell market order. BrokerMarket(C_SELL, symbolIndex, 0, C_DAY, "Overbought. ")

End If ' If no short open positions exist. If (_enableShorting And Not PositionExists(C_OPEN, symbolIndex, C_SHORT)) Then ' Generate a sell short market order. Define orderIndex As Number = BrokerMarket(C_SELL_SHORT, symbolIndex, 0, C_DAY, "Overbought.") ' Set a stop loss on the order. BrokerSetStopLossPercent(orderIndex, _stopLoss, True) ' Set a take profit on the order. BrokerSetTakeProfitPercent(orderIndex, _takeProfit, True ) ' Set a trailing stop loss on the order. BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trail ingStop) End If End If

Vous aimerez peut-être aussi