Hey guys,
I'm trying to duplicate Mark Johnson's PGO for TradersStudio - here's the code I have from a Chartscript:
{#OptVar1 30;1;50;1}
{#OptVar2 0;-5;10;1}
{#OptVar3 89;5;150;5}
var Bar, MP, MAlen: integer;
var Avg, PGO, PGOlast: float;
var EntLevel, ExitLevel: float;
EntLevel := #OptVar1/10;
ExitLevel := EntLevel*#OptVar2/10;
MAlen := #OptVar3;
for Bar := MAlen to BarCount() - 1 do
begin
{ SetCommission(50);}
PGO := (PriceClose(Bar) - SMA(Bar, #Close, MAlen))/EMA(Bar,TrueRangeSeries, MAlen);
Avg := SMA(Bar, #Close, MAlen);
MP := MarketPosition;
{ Exit position if PGO crosses zero. This happens when the Close crosses Avg. }
if (MP > 0) and (PGO < ExitLevel) then
SellAtMarket( Bar+1, Lastposition, 'LX');
if (MP < 0) and (PGO > -ExitLevel) then
CoverAtMarket( Bar+1, LastPosition, 'SX');
{ Enter long/short when PGO goes above 3.0 or below -3.0. }
{ Tell $imulator our exit will be at or near Avg. }
if (MP <= 0) and (PGO > EntLevel) then
begin
buyAtMarket( Bar+1, 'LE');
SetPositionRiskStop(LastPosition, Avg);
end;
if (MP >= 0) and (PGO < -EntLevel) then
begin
shortAtMarket( Bar+1, 'SE');
SetPositionRiskStop(LastPosition, Avg);
end;
end;
And....position size:
var A, fEquity, VP: float;
VP := 0.02;
fEquity := Equity(BarCount-1);
if (fEquity<100000) or (fEquity>1300000) then A := 1
else if (fEquity>100000) and (fEquity<180000) then A := 1+(fEquity-100000)/80000
else if (fEquity>180000) and (fEquity<600000) then A := 2-0.6*(fEquity-180000)/420000
else if (fEquity>600000) and (fEquity<1300000) then A := 1.4-0.4*(fEquity-600000)/700000;
SetPositionSizeFixed( VP*A*fEquity );
Anybody have any thoughts on doing this in TS? My main question is the OptVar1-3 at the top of the script - I just don't understand what these do or what their function is.
Any help greatly appreciated....can't wait for v2.5!
Best,
Damian