door Joop Henzen » zo 20 aug 2006, 11:54
Bijgaand nog even een aanpassing in de WMA Crossover
In deze zijn zoals eerder vermeld de Profit en Stoploss in percentages gedefinieerd
Verder zijn met behulp van Pierre statements aangepast zodat je ook gebruik kunt maken van het tabje Trading en Marktrichting Long of Short
In de vorige versie ging het systeem altijd Long EN Short
groet Joop Henzen
{-------------------------------------------------------
[INFO]
Author=
Created=2006-08-01
Modified=2006-08-17
Reference=
Usage=
[INPUTS]
[PLOTS]
PLOT1=1,-3,8421504,8421504,0,0,1,1,1,1
PLOT2=1,-2,8421504,8421504,0,0,1,1,1,1
PLOT3=1,-2,8421504,8421504,0,0,1,1,1,1
PLOT4=1,-2,8421504,8421504,0,0,1,1,1,1
[DESCRIPTION]
[END]
-------------------------------------------------------}
value function zWMACrossover (value xShortBars=11, value xLongBars=23,value xTrendBars=155,
value xProfit=36, value xStoploss=16) begin
{--- calculate todays position of the WMA's ---}
value xShortWMA[], xLongWMA[],xTrend;
xShortWMA := vWMA(Close,xShortBars);
xLongWMA := vWMA(Close,xLongBars);
xTrend := XAverage(Close,xTrendBars);
{--- check for any crossing ---}
value xAbove, xBelow;
xAbove := vCrossesAbove(xShortWMA,xLongWMA);
xBelow := vCrossesBelow(xShortWMA,xLongWMA);
{--- buy or sell depending on the crossings ---}
if xAbove and Close>xTrend then Buy;
if xBelow and Close<xTrend then Sell;
{---- handle long side ----}
Value xProfitLevel, xStopLevel;
if MarketPosition=1 then begin
xProfitLevel = EntryPrice(0)*((100+xProfit)/100);
xStopLevel = EntryPrice(0)*((100-xStopLoss)/100);
if Close>xProfitLevel or Close<xStopLevel then Exitlong;
end;
{---- handle short side ----}
if MarketPosition=-1 then begin
xProfitLevel = EntryPrice(0)*((100-xProfit)/100);
xStopLevel = EntryPrice(0)*((100+xStopLoss)/100);
if Close<xProfitLevel or Close>xStopLevel then Exitshort;
end;
{--- plot the WMA values and the current position ---}
plot1(xShortWMA,'WMA'+NumToStr(xShortBars));
plot2(xLongWMA,'WMA'+NumToStr(xLongBars));
plot3(CurrentContracts,'Position');
plot4(xTrend);
end;