EasyLanguage - Money Management Strategy

The EasyLanguage Money Market strategy allows you to use risk values that are calculated inside a strategy written in EasyLanguage.  This may be necessary when you do not have your own risk measure not available in Portfolio Maestro and would like to use this measure to calculate position size. To do so, the following steps should be performed:

  1. In the EasyLanguage code of the strategy, add an input psriskpercent(0.01) and add a variable pstradingrisk(1000). The value for psriskpercent is set in decimals, so that 0.01 means 1%, 0.02 means 2%, etc. The value of the input psriskpercent could be changed when running the strategy. The default value of the variable pstradingrisk could be set to any value since it is being calculated in the EasyLanguage code of the strategy.
  2. In Portfolio Maestro the money management strategy calculates a position size as Number of Contracts/Shares = Integer(Portfolio_Equity* psriskpercent/ pstradingrisk). Here Portfolio_Equity is the value of portfolio equity for the bar on which the position is calculated.

Example

If a portfolio equity is $100,000, psriskpercent = 0.05 and pstradingrisk = $1200, then the position size = Integer(100,000*0.05/1200) = 4.

If the calculation leads to pstradingrisk = 0, then the position size = default value. The default value is presently set as 100 for equities and 1 for futures contracts and currencies. User can change the default values by going to File – Properties, selecting Trading tab and making the required changes.

Example

Let’s take a basic trend following strategy written in EasyLanguage

{A basic trend following strategy with built in ATR based initial risk stops}

Inputs: look1(10), Mult(2), StopMult(2) ;

Variables: Upperband(0), Lowerband(0);

UpperBand = Average(close, look1) + Mult * AvgTrueRange(Look1);

Lowerband = Average(close, look1) - Mult * AvgTrueRange(Look1);

{Buy on a stop into strength or sell weakness}

Sell Short Next Bar at Lowerband Stop;

Buy Next Bar at Upperband Stop;

{Initial Risk Stop also using the Average True Range}

If MarketPosition = 1 then begin

        Sell ("IR_LStp") Next bar at EntryPrice - AvgTrueRange(Look1)* StopMult Stop;

end;

If MarketPosition = -1 then begin

        Buy to Cover ("IR_SStp") Next bar at EntryPrice + AvgTrueRange(Look1)* StopMult Stop;

end;

Example

Let us modify it to use the described EasyLanguage money management strategy. The modified code will look as follows.

{A basic trend following strategy with built in ATR based initial risk stops}

Inputs: look1(10), Mult(2), StopMult(2), psriskpercent(0.01) ; {Added input here}

Variables: Upperband(0), Lowerband(0), pstradingrisk(1000); { Added variable here}

pstradingrisk = AvgTrueRange(Look1);  {Any expression for risk can be here}

UpperBand = Average(close, look1) + Mult * pstradingrisk; {Use the new variable here}

Lowerband = Average(close, look1) - Mult * pstradingrisk; {Use the new variable here}

{Buy on a stop into strength or sell weakness}

Sell Short Next Bar at Lowerband Stop;

Buy Next Bar at Upperband Stop;

{Initial Risk Stop also using the same risk measure}

If MarketPosition = 1 then begin

        Sell ("IR_LStp") Next bar at EntryPrice - pstradingrisk * StopMult Stop; {Use the new variable here}

end;

If MarketPosition = -1 then begin

        Buy to Cover ("IR_SStp") Next bar at EntryPrice + pstradingrisk * StopMult Stop; {Use the new variable here}

end;