var valOpen()
{
var val = 0;
for(open_trades)
if(strstr(TradeAsset,Asset) && TradeIsOpen)
val += TradeResult;
return val;
}
//+------------------------------------------------------------------+
//| calcTmaTrue() |
//+------------------------------------------------------------------+
double calcTmaTrue( int inx )
{
// return ( iMA( symbol, tf, 21, 0, MODE_LWMA, PRICE_CLOSE, inx ) );
vars Close = series(priceClose());
double dblSum = 0;
double dblSumw = 0;
int jnx, knx;
int sundayCandles = 0;
for ( jnx = 0, knx = 21; jnx < 21; jnx++, knx-- )
{
dblSum += Close[inx + jnx + sundayCandles] * knx;
dblSumw += knx;
}
return ( dblSum / dblSumw );
}
//+------------------------------------------------------------------+
//| calcPrevTrue() |
//+------------------------------------------------------------------+
double calcPrevTrue( int inx )
{
vars Close = series(priceClose());
double dblSum = Close[ inx ] * 20;
double dblSumw = 20;
int jnx, knx;
int sundayCandles = 0;
for ( jnx = 1, knx = 21; jnx < 22; jnx++, knx-- )
{
dblSum += Close[ inx + jnx + sundayCandles ] * knx;
dblSumw += knx;
}
return ( dblSum / dblSumw );
}
//+------------------------------------------------------------------+
//| GetSlope() |
//+------------------------------------------------------------------+
double GetSlope(int shift)
{
int shiftWithoutSunday = shift;
double atr = ATR(100) / 10;
double gadblSlope = 0.0;
if ( atr != 0 )
{
double dblTma = calcTmaTrue( shiftWithoutSunday );
double dblPrev = calcPrevTrue( shiftWithoutSunday );
gadblSlope = ( dblTma - dblPrev ) / atr;
}
return ( gadblSlope );
}
function run()
{
BarPeriod = 240; // 4H Period
StartDate = 20120101;
EndDate = 20130701;
LookBack = 500;
set(PLOTNOW|PLOTPRICE);
//while(asset(loop("EUR/USD","USD/JPY","GBP/USD","AUD/USD","NZD/USD","USD/CAD","USD/CHF")));
//{
vars Price = series(price());
vars PriceOpen = series(priceOpen());
vars TwoFortyMA = series(LowPass(PriceOpen,240));
vars Slope = series(GetSlope(0));
vars SlopeRSI = series(RSI(Slope,2));
if (Price[0] > TwoFortyMA[0] && Price[0] > TestMA[0] && rising(TestMA) && NumOpenLong < 1 )
{
enterLong();
}
if (Price[0] < TwoFortyMA[0] && Price[0] < TestMA[0] && falling(TestMA) && NumOpenShort < 1 )
{
enterShort();
}
TakeProfit = 100*PIP;
//Stop = 100 * PIP;
plot("TwoFortyMA",TwoFortyMA[0],0,GREEN);
plot("TestMA",TestMA[0],0,BLUE);
plot("Slope",Slope[0],NEW,RED);
plot("SlopeRSI",SlopeRSI[0],NEW,GREEN);
//}
}