Sample translation of a large strategy

164 views
Skip to first unread message

Joel Reymont

unread,
May 18, 2007, 5:33:25 PM5/18/07
to top...@googlegroups.com
Fist C# and then EasyLanguage. There are, of course, a few things
still left to polish.

Thanks, Joel

------

public class TestStrategy : Strategy {
private int patienceThreshold = 5;
private DataSeries sym1;
private int ema;
private int wholepart;
private DataSeries sym2;
private double pointsTarget = 1.5.;
private int xDown;
private int decipart;
private int trigger;
private bool[] init_once;
private int factor1;
private int pointsRisked = 2;
private int factor2;
private int xUp;
private int n1;
private int emaLength = 20;
private int factor3;
private int n2;
private int factor4;

protected double PointSize(int bip)
{
return BarsArray[bip].Instrument.MasterInstrument.PointValue;
}

protected void OnFirstBar(int bip)
{
xUp = 0;
xDown = 0;
factor1 = 0;
factor2 = 0;
factor3 = 0;
factor4 = 0;
n1 = 0;
n2 = 0;
decipart = 0;
wholepart = 0;
ema = 0;
trigger = 0;
sym1 = new DataSeries(this);
sym2 = new DataSeries(this);
}

protected override void Initialize()
{
init_once = new bool[BarsArray.length];
foreach (bool elem in init_once)
elem = false;
}

protected override void OnBarUpdate()
{
int bip = BarsInProgress;
if (!init_once[bip])
{
OnFirstBar(bip);
init_once[bip] = true;
};
factor1 = (High[0] - Low[0]) * 2.5.;
factor2 = (Close[0] + High[0] + Low[0]) / 3;
factor3 = XAverage(factor1, emaLength);
factor4 = XAverage(factor2, emaLength);
xUp = factor4 + factor3;
xDown = factor4 - factor3;
sym1.Set(xDown);
sym2.Set(xUp);
if (MarketPosition() = 0)
{
n1 = LowestBar(Low[0], 15);
n2 = HighestBar(High[0], 15);
ema = XAverage(Close[0], emaLength);
decipart = FracPortion(ema);
wholepart = IntPortion(ema);
if ((decipart <= 0.125.))
{
trigger = wholepart;
}
else
{
if ((decipart > 0.125.) && (decipart <= 0.375.))
{
trigger = wholepart + 0.25.;
}
else
{
if ((decipart > 0.375.) && (decipart <= 0.625.))
{
trigger = wholepart + 0.5.;
}
else
{
if ((decipart > 0.625.) && (decipart <=
0.875.))
{
trigger = wholepart + 0.75.;
}
else
{
if ((decipart > 0.875.))
{
trigger = wholepart + 1.;
};
};
};
};
};
if ((Low[n1] < sym1[n1]) && (IntPortion(Time[0] / 100) <
15) && RateOfChange(ema, 2) < 0)
{
EnterShortLimit(trigger, "SE");
};
if ((High[n2] > sym2[n2]) && (IntPortion(Time[0] / 100)
< 15) && RateOfChange(ema, 2) > 0)
{
EnterLongLimit(trigger, "LE");
};
}
else
{
if (MarketPosition() = 1)
{
if (BarsSinceEntry() >= patienceThreshold)
{
ExitLong("LX Dead");
}
else
{
if (BarsSinceEntry() >= 1)
{
ExitLongLimit(EntryPrice() + pointsTarget,
"LX Trgt");
ExitLongStop(EntryPrice() - pointsRisked,
"LX Stop");
};
};
}
else
{
if (BarsSinceEntry() >= patienceThreshold)
{
ExitShort("SX Dead");
}
else
{
if (BarsSinceEntry() >= 1)
{
ExitShortLimit(EntryPrice() - pointsTarget,
"SX Trgt");
ExitShortStop(EntryPrice() + pointsRisked,
"SX Stop");
};
};
};
};
}

[Description("")]
[Category("Parameters")]
public int PatienceThreshold
{
get
{
return patienceThreshold;
};
set(int value)
{
patienceThreshold = value;
};
}


[Description("")]
[Category("Parameters")]
public int EmaLength
{
get
{
return emaLength;
};
set(int value)
{
emaLength = value;
};
}


[Description("")]
[Category("Parameters")]
public double PointsTarget
{
get
{
return pointsTarget;
};
set(double value)
{
pointsTarget = value;
};
}


[Description("")]
[Category("Parameters")]
public int PointsRisked
{
get
{
return pointsRisked;
};
set(int value)
{
pointsRisked = value;
};
}

}

------

{
Original on
https://www.tradestationworld.com/discussions/topic.asp?TOPIC_ID=13917
http://www.geocities.com/wealth_lab/Scalper.html

translated by eKam 7/7/2003
}
input:
emaLength(20),
patienceThreshold(5),
pointsTarget(1.5),
pointsRisked(2);

var:
xUp(0), xDown(0);

var:
factor1(0), factor2(0), factor3(0), factor4(0);

factor1 = (H - L)*2.5;
factor2 = (C + H + L) / 3;
factor3 = XAverage(factor1,emaLength);
factor4 = XAverage(factor2,emaLength);
xUp = factor4 + factor3;
xDown = factor4 - factor3;

{ Entry Rules }
if MarketPosition = 0 then begin
var:
n1(0),n2(0),decipart(0),wholepart(0),ema(0),trigger(0);

n1 = LowestBar ( Low, 15 );
n2 = HighestBar( High, 15 );
ema = XAverage(C,emaLength);
decipart = FracPortion(ema);
wholepart = IntPortion (ema);

if (decipart<=0.125) then trigger=wholepart
else if (decipart> 0.125) AND (decipart<=0.375) then
trigger=wholepart+0.25
else if (decipart> 0.375) AND (decipart<=0.625) then
trigger=wholepart+0.50
else if (decipart> 0.625) AND (decipart<=0.875) then
trigger=wholepart+0.75
else if (decipart> 0.875) then
trigger=wholepart+1.00;

if (L[n1]<xDown[n1])
AND (IntPortion(Time/100) < 15)
AND RateOfChange(ema,2) < 0 then
Sell Short("SE") Next Bar at trigger limit;

if (H[n2]>xUp[n2])
AND (IntPortion(Time/100) < 15)
AND RateOfChange(ema,2) > 0 then
Buy ("LE") Next Bar at trigger limit;
end

{ Exit Rules }
else if MarketPosition = 1 then begin { we're long }
if BarsSinceEntry >= patienceThreshold then
Sell ("LX Dead") Next Bar at Market
else if BarsSinceEntry >= 1 then begin
Sell ("LX Trgt") Next Bar at EntryPrice + pointsTarget limit;
Sell ("LX Stop") Next Bar at EntryPrice - pointsRisked stop;
end;
end
else begin { MarketPosition = -1; i.e. we're short }
if BarsSinceEntry >= patienceThreshold then
Buy to Cover("SX Dead") Next Bar at Market
else if BarsSinceEntry >= 1 then begin
Buy to Cover ("SX Trgt") Next Bar at EntryPrice - pointsTarget limit;
Buy to Cover ("SX Stop") Next Bar at EntryPrice + pointsRisked stop;
end;
end;


--
http://wagerlabs.com/

Reply all
Reply to author
Forward
0 new messages