[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

2 timeframes - triggering trades at the wrong place



PureBytes Links

Trading Reference Links

Hello,

i was trying to code a system that would trigger trades using 2 timeframes.

First the Longer time frame indicator (MACD) would need to set the
trend as being "up" after wich a shorter time frame trigger (Stochastics)
would be used.

However, for some reason trades are being triggered at the wrong
place. (see red square on screenshot) Only if the yellow dots are moving
up (wich shows the macd difference as becomming wider) the longer
term conditions would be "up" however it clearly shows the yellow
dots going down. The shorter term timeframe is used right at the point.
Fast Stochastics is crossing the 60 level at that point and being above the
slow stochastics wich is the right condition for a long trade.

I can not find out what i have done wrong. In some way i implement
the 2 timeframes wrong but unfortunatly can not find what is wrong.

Maybe someone can help. code is inside the code.txt file.

Thanks in advance,

greetings,


Henry Amand

ps: this is my second attempt. this time i did not send an .els because i
think because of some list limit the first attempt might not have arrived.
If it does, then sorry, if it does not, what is the size limit for the list
?


Signal - Long side
========================================


{***************************************
 Written by: Henry
             (hopefully with a little help of the Omega-list :-)
 Description: Multiple time periods : 12 min. MACD + 3 min. stochastics
              No trading between 12:00 and 14:00 because of (maybe) low volatility
			  during that time.
 Idea: Micha Peters - 4th Day of TA - The Netherlands
       data1 = shorter time period of stochastics - 3 minute
       data2 = longer time period of MACD Histogram - 12 minute

****************************************}

{The usual stuf to start a system}

Input: FastMA(8), SlowMA(34), MACDMA(8);                                     {macd inputs}
Input: stochlength(5), stochfast(3), stochslow(3);                           {stoch inputs}
Input: LunchGo(1230), LunchEnd(1400), LGo_Min(5), Lend_min(5);               {time to trade inputs}
vars: macdf(0), macds(0), macddif(0), macdtrend(False);                      {macd variables}
vars: overbot(60), oversold(40), stochb(0), stochf(0), stochs(0);            {stoch variables}
vars: LnchGo(0), LnchEnd(0);                                                 {time to trade variables}


{Setting up some stuf for later use}

{MACD calculations (difference between fast and slow) to calculate MACD of data2
 macdtrend will specify trend up or not on longer time period (data2)}

MACDf = XAverage(close, FastMA)data2 - XAverage(close, SlowMA)data2;         {MACD calculations to use in the trend calculation}
MACDs = xaverage(MACDf, macdma);
macddif = macdf - macds;                                                     {macd trend is calculated from macddif}


{calculating stochastic for use with shorter time period (data1). MACD and Stoch Could also be done using 
 functions with macd and fastk etc. but this is done to show exactly in this code what is all happening}

stochb = (close - (lowest (low,stochLength))) / 
	(Highest (high,stochLength)-(lowest (low,stochLength))) * 100;           {stochastics base. %k will be derived from this}
Stochf = Average(stochb,stochfast);                                          {also know as %k}
Stochs = average(stochf,stochslow);                                          {also know as %d}


{now lets begin to do something usefull and startup the proces}

If CurrentBar > 25 then begin

{setting time not to trade. Not functioning yet (have also not looked at it yet)
If time > 0900 and time < 2000 then begin
If time <= LunchGo or Time >= Lnchend then begin;   }

{Is the trend long on the longer time period ?}

if macddif > macddif[1] then MACDTrend = true
else macdtrend = false;


{use our shorter time period stochastics to enter the trade if the trend is up.
 We Enter the trade when the stochf (fast stoch) is above the overbought line and when the stochf
 is above the stochs (slow stoch)}

{
If MACDTrend = true and stochf > overbot and stochf > stochs then buy on close;
}
if MACDTrend = true and stochf crosses above overbot and stochf > stochs then Buy This Bar  on close;


{ofcourse we want to exit at some point}

If stochf crosses below stochs then exitlong;


if MarketPosition = 0 then MACDTrend = False;

{The End}

end;



======================================
indicators used as shown in the graph
======================================



MACD for longer time frame
======================================
Input: FastMA(8), SlowMA(34), macdma(8);

vars: Zero(0), MACDf(0), macds(0), macddif(0);

MACDf = XAverage(close, FastMA) - XAverage(close, SlowMA);    
MACDs = xaverage(MACDf, macdma);
MACDdif = macdf - macds;

{Plot1(macd1);
Plot2(macd2);}
Plot3(macddif);
Plot4(zero);






The used stochastics
=======================================

{*******************************************************************
Description	: This Indicator plots a Stochastic as used in the micha signal
Provided By	: Henry  
********************************************************************} 

Input: stochlength(5), stochfast(3), stochslow(3);                           {stoch inputs}
vars: overbot(60), oversold(40), stochb(0), stochf(0), stochs(0);            {stoch variables}

stochb = (close - (lowest (low,stochLength))) / 
	(Highest (high,stochLength)-(lowest (low,stochLength))) * 100;   {stochastics base. %k will be derived from this}
Stochf = Average(stochb,stochfast);                     {also know as %k}
Stochs = average(stochf,stochslow);                     {also know as %d}


plot1(stochf);
plot2(stochs);
plot3(Overbot);
plot4(Oversold);

Attachment: Description: "wrong-trade.gif"