Currency Trader Magazine



Strategy Code

 August 2010
June 2011
July 2011
August 2011
 September 2011
 

From August 2010 "Time-adjusted range and volume" by Caspar Marney:

Indicator Strategy code:

{***********************************************}
{Copyright Caspar Marney 2010}
{***********************************************}

input: VolumeMultiple(1), RangeMultiple(1), HoursBack(24);

var: start(0), end1(0), end2(0), x(0), p(-1), count(0), avg(0), avgrange(0), barsinday(0), DayNumber(0), DayHigh(-999999), DayLow(999999),
 mins.in.session(1440), autobars(True), upcolor(cyan), dncolor(red);
 
array: xv[199,1440](0),  xr[199,1440](0);
 
if bartype < 2 then begin
 
start= (Sessionstarttime(1,1));
end1= (sessionendtime(1,1));
end2= (sessionendtime(1,2));
 
value1 = timetominutes(start);
value2 = timetominutes(end2);
if start > end2 then
value3 = 1440+(value2-value1);
 
if start < end2 then
    value3 = -(value1-value2);
if autobars = false then value3 = mins.in.session;
     
barsinday = ceiling(value3/barinterval);
 
 
if d<>d[1] then begin 
    if count=barsinday then begin 
        p=iff(p<HoursBack-1,p+1,0); 
        for x=1 to barsinday begin 
            xv[p,x]=ticks[barsinday+1-x];
            xr[p,x]=truerange[barsinday+1-x]/Close*100; 
        end; 
    end; 
    count=1; 
end else count=count+1; 
 
   
if xv[HoursBack-1,count]>0 then begin 
    avg=0; 
    for x=0 to HoursBack-1 begin 
        avg=avg+xv[x,count]; 
    end; 
    avg=avg/HoursBack;  
end;


if xr[HoursBack-1,count]>0 then begin 
    avgrange=0; 
    for x=0 to HoursBack-1 begin 
        avgrange=avgrange+xr[x,count]; 
    end; 
    avgrange=avgrange/HoursBack; 
end;
 
end;

{**************************STRATEGY*************************}

If ticks>avg*VolumeMultiple AND truerange/Close*100 > avgrange*RangeMultiple then begin;

If High >= Highest(High, HoursBack) then Buy 100000 Contracts this bar;

If Low <= Lowest(Low, HoursBack) then SellShort 10000 Contracts this bar;

End;


{********************EXITS******************}

If MarketPosition = 1 and Low <= Lowest(Low, 24) then Sell this bar;

If MarketPosition = -1 and High >= Highest(High, 24) then BuytoCover this bar;

SMA Strategy Code

{***********************************************}
{Copyright Caspar Marney 2010}
{***********************************************}

input: VolumeMultiple(1), RangeMultiple(1), HoursBack(24);
var:  Avg(0), AvgRange(0);
 

{**************************STRATEGY*************************}

avg = averageFC(ticks, HoursBack);
avgRange = averageFC(trueRange, HoursBack)/Close*100;

If ticks>avg*VolumeMultiple AND truerange/Close*100 > avgrange*RangeMultiple then begin;

If High >= Highest(High, HoursBack) then Buy 100000 Contracts this bar;

If Low <= Lowest(Low, HoursBack) then SellShort 100000 Contracts this bar;

End;

{********************EXITS******************}

If MarketPosition = 1 and Low <= Lowest(Low, 24) then Sell this bar;

If MarketPosition = -1 and High >= Highest(High, 24) then BuytoCover this bar;

Back to top


From June 2011 "The Total Power Indicator" by Daniel Fernandez:|

Right-click here and choose a "Save" option to download strategy code for this article.

Back to top



From July 2011 "Algorithmic support and resistance: Trading Widner oscillators in FX" by Daniel Fernandez

Widner oscillator MetaTrader code

// implemented by Daniel Fernandez, Asirikuy.com 2011

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 LightSeaGreen
#property indicator_color3 Crimson
#property indicator_color4 DarkGreen
//---- buffers
double WSO[];
double WRO[];
double WSO_Average[];
double WRO_Average[];
double resistance[6];
double support[6];

extern int averagePeriod = 4;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
 {
 string short_name;
//---- 2 additional buffers are used for counting.
 IndicatorBuffers(4);
//---- indicator lines
 SetIndexStyle(0,DRAW_LINE, 1, 1);
 SetIndexBuffer(0, WSO);
 SetIndexStyle(1,DRAW_LINE, 1, 1);
 SetIndexBuffer(1, WRO);
 SetIndexStyle(2,DRAW_LINE, 1, 3);
 SetIndexBuffer(2, WSO_Average);
 SetIndexStyle(3,DRAW_LINE, 1, 3);
 SetIndexBuffer(3, WRO_Average);

 return(0);
 }
//+------------------------------------------------------------------+
//| WSO and WRO |
//+------------------------------------------------------------------+
int start()
 {
 int i,k;
 
 Comment("Coded by Daniel Fernandez, please visit my blog at mechanicalforex.com");
 
 i=Bars-50 ;
 
 while (i >= 0)
 
 {
 
 if (High[i+4] == High[ iHighest( NULL, 0, MODE_HIGH, 9, i ) ])
 {
 
 k = 0 ;
 
 while (k <= 4)
 {
 resistance[k+1] = resistance [k] ;
 k++ ;
 }
 
 resistance[0] = High[i+4] ;
 
 }
 
 if (Low[i+4] == Low[ iLowest( NULL, 0, MODE_LOW, 9, i ) ])
 {
 
 k = 0 ;
 
 while (k <= 4)
 {
 support[k+1] = support[k] ;
 k++ ;
 }
 
 support[0] = Low[i+4] ;
 
 }
 
 
 WSO[i] = 100*( 1-(MathFloor(support[0]/Close[i]) + MathFloor(support[1]/Close[i]) + MathFloor(support[2]/Close[i]) +
 MathFloor(support[3]/Close[i]) + MathFloor(support[4]/Close[i]) + MathFloor(support[5]/Close[i])) / 6) ;

 WRO[i] = 100*( 1-(MathFloor(resistance[0]/Close[i]) + MathFloor(resistance[1]/Close[i]) + MathFloor(resistance[2]/Close[i]) +
 MathFloor(resistance[3]/Close[i]) + MathFloor(resistance[4]/Close[i]) + MathFloor(resistance[5]/Close[i])) / 6) ;
 
 i-- ;
 
 }
 
 int limit=Bars-50;
 
 i = 0 ;
 
 while (i<limit)
 
 {
 
 WSO_Average[i] = iMAOnArray(WSO,Bars,averagePeriod ,0,MODE_SMA,i);
 
 WRO_Average[i] = iMAOnArray(WRO,Bars,averagePeriod ,0,MODE_SMA,i);
 
 i += 1 ;
 }
 return(0);
}
//+------------------------------------------------------------------+

Back to top


From August 2011 "Tackling trending and ranging markets with CMI" by Daniel Fernandez

****************

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 80
#property indicator_level2 75
#property indicator_level3 50
#property indicator_level4 25
#property indicator_level5 20
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue

//---- input parameters
extern int periodCMI=50;
extern int periodSig=10;

//---- buffers
double CMIBuffer[];
double MABuffer[];

double high1, low1 ;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(2);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,CMIBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,MABuffer);


//---- name for DataWindow and indicator subwindow label
   short_name="CMI("+periodCMI+","+periodSig+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
   SetIndexLabel(1,"CMI");
   SetIndexLabel(1,"CMI Signal");
  
//----
   SetIndexDrawBegin(0,periodCMI+periodSig);
   SetIndexDrawBegin(1,periodCMI+periodSig);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| MA and Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive;
   Comment("Please visit my blog at mechanicalforex.com");
//----
   if(Bars<=periodCMI) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=periodCMI;i++) CMIBuffer[Bars-i]=0.0;
//----
   i=Bars-periodCMI-1;
   if(counted_bars>=periodCMI) i=Bars-counted_bars-1;
   int MAPeriod=1;
   while(i>=0)
   {
     high1=High[iHighest(NULL, 0, MODE_HIGH , periodCMI, i)] ;
    low1=Low[iLowest(NULL, 0, MODE_LOW , periodCMI, i)] ;
  
     CMIBuffer[i] = (((MathAbs(Close[i]-Close[i+periodCMI-1]))/(high1-low1))*100);
     i--;
   }

   int total=0;
   for (i=Bars-periodSig-periodSig-1;i>=0;i--)
   {
     MABuffer[i]=iMAOnArray(CMIBuffer,total,periodSig,0,0,i);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Back to top


From September 2011 "Filtering trend signals with the Parabolic Time Indicator" by Daniel Fernandez

Right-click here and choose a "Save" option to download strategy code for this article.

Back to top


|
email this story
|
print this story