201302041215Acme N System - Source Code

[LegacyColorValue = TRUE];

 

{****************************************

Acme N System: Use the Range Ratio to find Narrow Range Patterns

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

 

Inputs:

{N Parameters}

RatioLength1(1),

RatioLength2(7),

RangePercent(0.7),

MaxRangeRatio(0.7),

RetraceBars(2),

{Filter Parameters}

FiltersOn(True),

FilterLength(14),

MinimumPrice(20),

MinimumADX(18),

MinimumHV(0.5),

{Position Parameters}

Equity(100000),

RiskModel(3),

RiskPercent(2.0),

RiskATR(1.0),

EntryFactor(0.10),

DrawTargets(True);

 

Variables:

N(0),

ATR(0.0),

ATRLength(20),

MA(0.0),

MALength(50),

TradeFilter(True),

BuyStop(0.0),

ShortStop(0.0),

{N Variables}

NLength1(5),

NLength2(10),

NLength3(4),

LowVolatility(False);

 

ATR=Volatility(ATRLength);

MA=Average(C,MALength);

 

{Set Entry and Exit Stops}

 

BuyStop = H+(EntryFactor*ATR);

ShortStop=L-(EntryFactor*ATR);

 

{Acme N Setup}

Condition1 = AcmeNarrowRange(NLength1,1) and

AcmeNarrowRange(nLength1,0)[1];

Condition2=L>L[1] and H<H[1] and L[1]>L[2] and H[1]<H[2];

Condition3=AcmeNarrowRange(Nlength2,0);

Condition4=AcmeInsideDayNR(NLength3,0);

Condition5=AcmeRangeRatio(RatioLength1,RatioLength2)<=MaxRangeRatio;

LowVolatility=Condition1 or Condition2 or Condition3 

or Condition4 or Condition5;

 

{Run trade filters}

 

If FiltersOn then

TradeFilter=C>MinimumPrice and

ADX(FilterLength)>=MinimumADX and

AcmeVolatility(FilterLength)>=MinimumHV;

 

If LowVolatility and

Range<=RangePercent*ATR and

Tradefilter then begin

{Calculate shares based on risk model}

N = AcmeGetShares(Equity,RiskModel,RiskPercent,RiskATR,1000);

 

{Narrow Range}

 

   TradeFilter=True;

   if FiltersOn then

    TradeFilter=MedianPrice>MA;

 

If TradeFilter and

AcmeRetraceDown(RetraceBars) and

TradeFilter then begin

{Draw Entry Targets on the Chart}

If DrawTargets Then

Condition1=AcmeEntryTargets("N",BuyStop,0,0,0);

Buy("Acme LE N") N Shares Next Bar at BuyStop Stop;

End;

 

TradeFilter=True;

If FiltersOn Then

Tradefilter=MedianPrice<MA;

 

if TradeFilter and

AcmeRetraceUp(RetraceBars) and

TradeFilter then begin

{Draw Entry Targets on the Chart}

  If DrawTargets then

Condition1=AcmeEntryTargets("N",0,0,ShortStop,0);

SellShort ("Acme SE N") N Shares Next Bar at ShortStop Stop;

End;

End;

 

*****AcmeNarrowRange Function*****

[LegacyColorValue = TRUE];

 

Inputs:

RangeLength(numeric),

Index(numeric);

 

AcmeNarrowRange=False;

If Range<Lowest(Range,Rangelength-1)[Index+1] Then

AcmeNarrowRange=True;

 

*****AcmeInsideDayNR Function*****

[LegacyColorValue = TRUE];

 

Inputs:

RangeLength(numeric),

Index(numeric);

 

AcmeInsideDayNR=False;

If Range<Lowest(Range,RangeLength-1)[Index+1] and

L>L[1] and H<H[1] Then

AcmeInsideDayNR=True;

 

*****AcmeRangeRatio Function*****

[LegacyColorValue = TRUE];

 

Inputs:

Length1(Numeric),

Length2(numeric);

 

Variables:

Range1(0.0),

Range2(0.0);

 

AcmeRangeRatio=0;

Range1=Average(Range,Length1);

Range2=Average(Range,Length2);

If Range1<>0 and Range2<>0 then

AcmeRangeRatio=Range1/Range2;

 

*****AcmeVolatility Function*****

[LegacyColorValue = TRUE];

 

{*******************************************************************

AcmeVolatility: Calculate the annualized historic volatility

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

 

Inputs:

Length(Numeric);

 

Variables:

DaysInYear(365),

DaysInMonth(30),

DaysInWeek(7),

TimeFactor(0.0);

 

AcmeVolatility = 0;

 

If Close > 0 and Close[1] > 0 Then Begin

If DataCompression >= 2 and DataCompression < 5 Then Begin

If DataCompression = 2 Then {Daily}

TimeFactor = DaysInYear

Else If DataCompression = 3 Then {Weekly}

TimeFactor = DaysInYear / DaysInWeek

Else If DataCompression = 4 Then {Monthly}

TimeFactor = DaysInYear / DaysInMonth;

 

AcmeVolatility = StdDev(Log(Close / Close[1]), Length) *

SquareRoot(TimeFactor);

End;

End;

 

 

*****AcmeGetShares Function*****

[LegacyColorValue = TRUE];

 

{*******************************************************************

Name : AcmeGetShares

Description : Calculate the number of shares

Provided By : Acme Trader (c) Copyright 2001

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

 

Inputs:

Equity(Numeric),

RiskModel(Numeric),

RiskPercent(Numeric),

RiskATR(Numeric),

R(Numeric);

 

Variables:

RiskShares(0),

Length(20);

 

If RiskModel = 1 and Close > 0 Then

RiskShares = MaxList(R, R * IntPortion(Equity / (R * Close)));

 

If RiskModel = 2 and RiskATR > 0 Then

RiskShares = MaxList(R, R * IntPortion((Equity * RiskPercent / 100) / (R * RiskATR)));

 

If RiskModel = 3 and Volatility(Length) > 0 Then

RiskShares = MaxList(R, R * IntPortion((Equity * RiskPercent / 100) / (R * Volatility(Length))));

 

If RiskModel = 4 and Volatility(Length) > 0 Then

RiskShares = MaxList(R, R * IntPortion((Equity * RiskPercent / 100) / (R * SquareRoot(Volatility(Length)))));

 

AcmeGetShares = RiskShares;

 

*****AcmeRetraceDown*****

[LegacyColorValue = TRUE];

 

inputs:

Length(numeric);

 

Variables:

insidedays(0),

lowerbars(0);

 

AcmeRetraceDown=False;

insidedays=countif(l>l[1] and h<h[1],length);

lowerbars = countif(l<l[1] and h<h[1],length);

If(lowerbars = Length or

(insidedays = 1 and lowerbars = Length-1)) Then

AcmeRetraceDown=True;

*****AcmeEntryTargets Function*****
[LegacyColorValue = TRUE];
{*******************************************************************
Name : AcmeEntryTargets
Description : Plot the entry points, both stops and limits
Provided By : Acme Trader (c) Copyright 2001
********************************************************************}
 
Inputs:
SystemID(String),
BuyStop(Numeric),
BuyLimit(Numeric),
ShortStop(Numeric),
ShortLimit(Numeric);
Variables:
PlotColor(Black),
BSLine(-1),
BLLine(-1),
SSLine(-1),
SLLine(-1),
BSString(""),
BLString(""),
SSString(""),
SLString(""),
BSText(-1),
BLText(-1),
SSText(-1),
SLText(-1);
AcmeEntryTargets = False;
If LastBarOnChart Then Begin
If GetBackGroundColor = 1 Then
PlotColor = White;
If BuyStop > 0 Then Begin
BSString = " LE " + SystemID + " Stop ";
BSLine = TL_New(Date[0], Time[0], BuyStop, Date[1], Time[1], BuyStop);
If BSLine >= 0 Then Begin
TL_SetColor(BSLine, PlotColor);
TL_SetSize(BSLine, 1);
TL_SetExtRight(BSLine, True);
BSText = Text_New(Date, Time, BuyStop, BSString);
Text_SetColor(BSText, PlotColor);
End;
End;
If BuyLimit > 0 Then Begin
BLString = " LE " + SystemID + " Limit ";
BLLine = TL_New(Date[0], Time[0], BuyLimit, Date[1], Time[1], BuyLimit);
If BLLine >= 0 Then Begin
TL_SetColor(BLLine, PlotColor);
TL_SetSize(BLLine, 1);
TL_SetExtRight(BLLine, True);
BLText = Text_New(Date, Time, BuyLimit, BLString);
Text_SetColor(BLText, PlotColor);
End;
End;
If ShortStop > 0 Then Begin
SSString = " SE " + SystemID + " Stop ";
SSLine = TL_New(Date[0], Time[0], ShortStop, Date[1], Time[1], ShortStop);
If SSLine >= 0 Then Begin
TL_SetColor(SSLine, PlotColor);
TL_SetSize(SSLine, 1);
TL_SetExtRight(SSLine, True);
SSText = Text_New(Date, Time, ShortStop, SSString);
Text_SetColor(SSText, PlotColor);
End;
End;
If ShortLimit > 0 Then Begin
SLString = " SE " + SystemID + " Limit ";
SLLine = TL_New(Date[0], Time[0], ShortLimit, Date[1], Time[1], ShortLimit);
If SLLine >= 0 Then Begin
TL_SetColor(SLLine, PlotColor);
TL_SetSize(SLLine, 1);
TL_SetExtRight(SLLine, True);
SLText = Text_New(Date, Time, ShortLimit, SLString);
Text_SetColor(SLText, PlotColor);
End;
End;
End;
AcmeEntryTargets = True;
*****AcmeRetraceUp Function*****
[LegacyColorValue = TRUE];
inputs:
Length(numeric);
Variables:
insidedays(0),
higherbars(0);
AcmeRetraceUp=False;
insidedays=countif(l>l[1] and h<h[1],length);
higherbars = countif(l>l[1] and h>h[1],length);
If(higherbars = Length or
(insidedays = 1 and higherbars = Length-1)) Then
AcmeRetraceUp=True;
沒有上一則|日誌首頁|沒有下一則
回應
    沒有新回應!