هديتي لكم بعد طول غياب ...قالب للولث لاب..جديد... احلى منة مافية ...وعطونا تجاربكم
أقتباس c# code for wealth-lab:
Using system;
using system.collections.generic;
using system.text;
using system.drawing;
using wealthlab;
using wealthlab.indicators;
using community.components; // divergence between two dataseries (detect, plot)
namespace wealthlab.strategies
{
public class pzostrategy : Wealthscript
{
private strategyparameter paramperiod;
public pzostrategy()
{
paramperiod = createparameter("pzo period", 14, 2, 252, 2);
}
protected override void execute()
{
int period = paramperiod.valueint;
dataseries r = new dataseries( bars, "r" );
dataseries tv = ema.series( close, period, emacalculation.modern );
dataseries pzo = new dataseries( bars, "pzo" );
adx adx = adx.series( bars,14 );
ema ema = ema.series( close, 60, emacalculation.modern );
for(int bar = period; bar < bars.count; bar++) {
r[bar] = math.sign( close[bar] - close[bar-1] ) * close[bar];
}
dataseries vp = ema.series( r, period, emacalculation.modern );
for(int bar = period; bar < bars.count; bar++) {
if( tv[bar] != 0 )
pzo[bar] = 100 * vp[bar] / tv[bar];
}
chartpane pzopane = createpane( 30, true, true );
plotseriesoscillator( pzopane, pzo, 60, -60, color.red, color.blue, color.black, linestyle.solid, 1 );
drawhorzline( pzopane, 60, color.darkgreen, linestyle.dotted, 2 );
drawhorzline( pzopane, -60, color.red, linestyle.dotted, 2 );
drawhorzline( pzopane, 40, color.darkgreen, linestyle.solid, 1 );
drawhorzline( pzopane, -40, color.red, linestyle.solid, 1 );
drawhorzline( pzopane, 0, color.darkblue, linestyle.solid, 1 );
chartpane divpane = createpane( 30, true, true );
series sh = new series(this);
dataseries pd = sh.plotpeakdivergence(3, pricepane, high, 4d, pzopane, pzo, 4d);
plotseries(divpane, pd, color.blue, linestyle.solid, 2);
dataseries td = sh.plottroughdivergence(3, pricepane, low, 4d, pzopane, pzo, 4d);
plotseries(divpane, td, color.red, linestyle.solid, 2);
chartpane adxpane = createpane( 30, true, true );
plotseries(adxpane, adx, color.purple, linestyle.histogram, 2);
drawhorzline(adxpane, 18, color.red, linestyle.dashed, 2 );
plotseries(pricepane, ema, color.blue, linestyle.solid, 1);
int start = math.max(adx.firstvalidvalue,period);
start = math.max( start, ema.firstvalidvalue );
for(int bar = start; bar < bars.count; bar++)
{
bool bull = adx[bar] > 18 && close[bar] > ema[bar];
bool bear = adx[bar] > 18 && close[bar] < ema[bar];
bool osc = adx[bar] < 18;
if( bull ) setbackgroundcolor( bar, color.fromargb( 30, color.blue ) );
if( bear ) setbackgroundcolor( bar, color.fromargb( 30, color.red ) );
if( osc ) setbackgroundcolor( bar, color.fromargb( 30, color.green ) );
if (islastpositionactive)
{
position p = lastposition;
if( p.positiontype == positiontype.long ) {
if( p.entrysignal.tolower().contains("uptrend") ) {
if( pzo[bar] > 60 && turndown( bar, pzo ) ||
( close[bar] < ema[bar] && pzo[bar] < 0 ) ||
(pd[bar] <= -1.0 && pzo[bar] < 40.0) )
sellatmarket( bar+1, p, "trend sell" );
}
else if( p.entrysignal.tolower().contains("buy nontrend") ) {
if( pzo[bar] > 40.0 ) {
if( adx[bar] > 18 )
sellatmarket( bar+1, p, "nontrend sell rule #1" );
}
else {
if( pzo[bar] < -5 )
sellatmarket( bar+1, p, "nontrend sell rule #2" );
}
}
}
else {
if( p.entrysignal.tolower().contains("downtrend") ) {
if( pzo[bar] < -60 && turnup( bar, pzo ) ||
( close[bar] > ema[bar] && pzo[bar] > 0 ) ||
(td[bar] <= -1.0 && pzo[bar] > -40.0) )
coveratmarket( bar+1, p, "trend cover" );
}
else if( p.entrysignal.tolower().contains("short nontrend") ) {
if( pzo[bar] < -40.0 ) {
if( adx[bar] > 18 )
coveratmarket( bar+1, p, "nontrend cover rule #1" );
}
else {
if( pzo[bar] < -5 && crossover( bar, pzo, 15 ) )
coveratmarket( bar+1, p, "nontrend cover rule #2" );
}
}
}
}
else
{
bool buy = bull && ( crossover( bar, pzo, -40 ) || crossover( bar, pzo, 0 ) );
bool shrt = bear && ( crossunder( bar, pzo, 40 ) || crossunder( bar, pzo, 0 ) );
bool nt_buy = osc && (crossover( bar, pzo, -40 ) || crossover( bar, pzo, 15 ));
bool nt_shrt = osc && (crossunder( bar, pzo, 40 ) || crossunder( bar, pzo, -5 ));
if( buy ) {
setbarcolor( bar, color.blue );
buyatmarket( bar+1, "buy uptrend" );
}
else if( shrt ) {
setbarcolor( bar, color.red );
shortatmarket( bar+1, "short downtrend" );
}
else if( nt_buy ) {
setbarcolor( bar, color.cyan );
buyatmarket( bar+1, "buy nontrend" );
}
else if( nt_shrt ) {
setbarcolor( bar, color.orange );
shortatmarket( bar+1, "short nontrend" );
}
}
}
}
}
}
دعواتكم لي