This is an example printout of how the System Editor's Export menu option will create a text file of the system blox components and the script information contained in the printed system. This information will appear in the default text reader program, Notepad.exe, or other text reader that is assigned to open text files in Windows.
===================================================================================
system: Dual Moving Average - START
===================================================================================
===================================================================================
block: Dual Moving Average Entry Exit
===================================================================================
-----------------------------------------------------------------------------------
Parameters
-----------------------------------------------------------------------------------
longMovingAverageDays [ LONG Moving Average (Days) ]; Integer;
shortMovingAverageDays [ SHORT Moving Average (Days) ]; Integer;
useATRStops [ Use AND Hold ATR Stops ]; Boolean;
atrDays [ ATR (Days) ]; Integer; block
stopInATR [ Stop (in ATR) ]; Float;
riskPerTrade [ Risk (%) ]; Percent;
-----------------------------------------------------------------------------------
Indicators
-----------------------------------------------------------------------------------
longMovingAverage [ LONG Moving Average ]; Exponential Moving Average; Close; block;
shortMovingAverage [ SHORT Moving Average ]; Exponential Moving Average; Close; block;
averageTrueRange [ Indicator name goes here... ]; Average TRUE Range; ; block;
EhlersNonLinearMA [ EhlersNonLinearMA ]; Ehlers NonLinear Ma; Close; block;
-----------------------------------------------------------------------------------
script: Exit Orders
-----------------------------------------------------------------------------------
' Exit position on open if moving averages cross
If instrument.position = LONG AND shortMovingAverage < longMovingAverage THEN
broker.ExitAllUnitsOnOpen
ENDIF
If instrument.position = SHORT AND shortMovingAverage > longMovingAverage THEN
broker.ExitAllUnitsOnOpen
ENDIF
' ---------------------------------------------
' Enter stop if "Use ATR Stop" is true
' ---------------------------------------------
If useATRStops THEN
broker.ExitAllUnitsOnStop( instrument.unitExitStop )
ENDIF
-----------------------------------------------------------------------------------
script: Entry Orders
-----------------------------------------------------------------------------------
VARIABLES: currentclose, stopPrice Type: Price
' Get the current close.
currentClose = instrument.close
' If we are not long and the faster moving averages are above the slower one.
If instrument.position <> LONG AND
shortMovingAverage > longMovingAverage THEN
' If we are using ATR stops...
If useATRStops THEN
' Compute the stop price.
stopPrice = currentClose - (stopInATR * averageTrueRange)
' Enter a long on the open using this stop.
broker.EnterLongOnOpen( stopPrice )
' NOT using ATR stops...
ELSE
' Enter a long on the open with no stop.
broker.EnterLongOnOpen
ENDIF
ENDIF
' If we are not short and the faster moving averages are below the slower one.
If instrument.position <> SHORT AND
shortMovingAverage < longMovingAverage THEN
' If we are using ATR stops...
If useATRStops THEN
' Compute the stop price.
stopPrice = currentClose + (stopInATR * averageTrueRange)
' Enter a short on the open using this stop.
broker.EnterShortOnOpen( stopPrice )
' NOT using ATR stops...
ELSE
' Enter a short on the open with no stop.
broker.EnterShortOnOpen
ENDIF
ENDIF
-----------------------------------------------------------------------------------
script: Unit Size
-----------------------------------------------------------------------------------
VARIABLES: riskEquity, dollarRisk Type: Money
' Compute the risk equity.
riskEquity = system.tradingEquity * riskPerTrade
' If we are using ATR stops...
If useATRStops THEN
If instrument.IsStock THEN
dollarRisk = order.entryRisk * instrument.stockSplitRatio * instrument.conversionRate
ELSE
dollarRisk = order.entryRisk * instrument.bigPointValue
ENDIF
ELSE
If instrument.IsStock THEN
dollarRisk = averageTrueRange * instrument.stockSplitRatio * instrument.conversionRate
ELSE
dollarRisk = averageTrueRange * instrument.bigPointValue
ENDIF
ENDIF
' Set the trade size
order.SetQuantity( riskEquity / dollarRisk )
If order.quantity < 1 THEN
order.Reject( "Order Quantity less than 1" )
ENDIF
===================================================================================
block: Margin Equity Risk Manager
===================================================================================
-----------------------------------------------------------------------------------
block Permanent VARIABLES
-----------------------------------------------------------------------------------
newMarginValue [ ]; Floating; 0.000000; block
plotCash [ Cash ]; Series; 0.000000; test
-----------------------------------------------------------------------------------
Parameters
-----------------------------------------------------------------------------------
maxMarginEquity [ Max Margin Equity (%) ]; Percent; block
checkMarginOnFill [ Check Margin on Fill ]; Boolean; block
-----------------------------------------------------------------------------------
script: Can Fill order
-----------------------------------------------------------------------------------
If checkMarginOnFill AND order.isEntry THEN
If instrument.IsFuture THEN
newMarginValue = order.quantity * instrument.margin
If test.totalMargin + newMarginValue > test.totalEquity * maxMarginEquity THEN
order.Reject( "Cannot add " + AsString( newMarginValue, 2 ) + " additional margin to " + AsString( test.totalMargin, 2 ) + " existing with total equity of " + AsString( test.totalEquity, 2 ) + " and max margin equity threshold of " + AsString( maxMarginEquity, 2 ) )
ENDIF
ENDIF
If instrument.IsStock THEN
newMarginValue = order.quantity * order.fillPrice * instrument.conversionRate * instrument.stockSplitRatio
If newMarginValue > test.cash * maxMarginEquity THEN
order.Reject( "Cannot add " + AsString( newMarginValue, 2 ) + " additional purchase equity with cash of " + AsString( test.cash, 2 ) + " and max threshold of " + AsString( maxMarginEquity, 2 ) )
ENDIF
ENDIF
ENDIF
-----------------------------------------------------------------------------------
script: Can Add Unit
-----------------------------------------------------------------------------------
If order.isEntry THEN
If instrument.IsFuture THEN
newMarginValue = order.quantity * instrument.margin
If test.totalMargin + newMarginValue > test.totalEquity * maxMarginEquity THEN
order.Reject( "Cannot add " + AsString( newMarginValue, 2 ) + " additional margin to " + AsString( test.totalMargin, 2 ) + " existing with total equity of " + AsString( test.totalEquity, 2 ) + " and max margin equity threshold of " + AsString( maxMarginEquity, 2 ) )
ENDIF
ENDIF
If instrument.IsStock THEN
newMarginValue = order.quantity * order.orderPrice * instrument.conversionRate * instrument.stockSplitRatio
If newMarginValue > test.cash * maxMarginEquity THEN
order.Reject( "Cannot add " + AsString( newMarginValue, 2 ) + " additional purchase equity with cash of " + AsString( test.cash, 2 ) + " and max threshold of " + AsString( maxMarginEquity, 2 ) )
ENDIF
ENDIF
ENDIF
-----------------------------------------------------------------------------------
script: After Trading Day
-----------------------------------------------------------------------------------
plotCash = test.cash
===================================================================================
block: Trade Direction Portfolio Manager
===================================================================================
-----------------------------------------------------------------------------------
Parameters
-----------------------------------------------------------------------------------
tradeDirection [ Trade Direction (LONG/SHORT/All) ]; Selector;
-----------------------------------------------------------------------------------
script: Filter Portfolio
-----------------------------------------------------------------------------------
'Set to no trades
instrument.DenyAllTrades
'Set to trade TYPE: indicated by tradeDirection parameter
If tradeDirection = TRADE_ALL THEN instrument.AllowAllTrades
If tradeDirection = TRADE_LONG THEN instrument.AllowLongTrades
If tradeDirection = TRADE_SHORT THEN instrument.AllowShortTrades
===================================================================================
system: Dual Moving Average - END
===================================================================================
Last Edit: 9/12/2020 |
Edit Time: 9/12/2020 9:50:00 AM |
Topic ID#: 187 |