Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

EMA crossover for Amibroker (AFL)
Ketan-0
about 14 years ago
Amibroker (AFL)

Rating:
4 / 5 (Votes 5)
Tags:
trading system, amibroker

I am new to this but this formula seams nice, please try it out and give feedback.

Similar Indicators / Formulas

weighted moving average scan
Submitted by naninn about 14 years ago
Kase Peak Osc. V2 batu
Submitted by batu1453 over 10 years ago
Kase CD V2batu
Submitted by batu1453 over 10 years ago
Ichimoku
Submitted by prashantrdx over 10 years ago
EMA System Ribbon
Submitted by yo123 about 14 years ago
Three-Bar Inside Bar Pattern
Submitted by EliStern about 14 years ago

Indicator / Formula

Copy & Paste Friendly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*==============================================================================
    Global Settings
==============================================================================*/
SetOption("InitialEquity", 1000000);
SetOption("MinShares", 50);
SetOption("NoDefaultColumns", True );
SetOption("CommissionMode", 2); //$$ per trade
SetOption("CommissionAmount", 0); // commission is accounted for in skid
SetOption("MarginRequirement", 100);
SetOption("UsePrevBarEquityForPosSizing", True);
SetOption("UseCustomBacktestProc", True );
 
SetTradeDelays( 1, 1, 1, 1 );
 
/*==============================================================================
    User-defined Functions
==============================================================================*/
function EMA0(A, p)
{
    r[0] = a[0];
    ep = 2/(p+1);
    for(i = 1; i < BarCount; i++)
    {
        r[i] = r[i-1] + (a[i] - r[i-1]) * ep;
    }
    return r;
}
 
function OptimizeNot(a1, a2, a3, a4, a5)
{
    return a2;
}
 
/*==============================================================================
    Entry and Exit Rules
==============================================================================*/
tr = Max(H-L, Max(abs(H-Ref(C, -1)), abs(Ref(C, -1)-L)));
tr[0] = H[0] - L[0];
 
fast = EMA0(C, Optimize("FastEMA", 5, 10, 40, 5));
slow = EMA0(C, Optimize("SlowEMA", 15, 15, 100, 10));
Buy = Cross(fast, slow);
Sell = Cross(slow, fast);
Buy[1] = 0; // to avoid false signal at the beginning
//ApplyStop(stopTypeLoss, stopModePoint, ATR_multi*Ref(ATR0, -1), True, True)
;
/*==============================================================================
    Skid of Executions
==============================================================================*/
BuyPrice = (H+O)/2;
SellPrice = (L+O)/2;
 
/*==============================================================================
    Position Sizing
==============================================================================*/
ATR_multi = OptimizeNot("ATP Multi", 5, 1, 9, 1);
ATR0 = EMA0(tr, 20);
 
Risk_Per_Share = Ref(ATR0, -1) * ATR_multi;
Heat = OptimizeNot("Heat", 0.10, 0.01, 0.50, 0.01);
 
PosSizeFactor = Heat / Risk_Per_Share;
SetPositionSize(PosSizeFactor, spsValue);
 
/*==============================================================================
    Automatic Analysis Action Options
==============================================================================*/
AAAction = Status("action");
if(AAAction == actionIndicator)
{
    Plot(fast, "FastEMA", colorRed);
    Plot(slow, "SlowEMA", colorYellow);
}
else if(AAAction == actionExplore)
{
    Filter = 1;
    AddColumn( DateTime(), "Date", formatDateTime );
    //AddColumn(DayOfWeek(), "DayOfWeek", 1);
    AddColumn(O, "Open");
    AddColumn(H, "High");
    AddColumn(L, "Low");
    AddColumn(C, "Close");
    //AddColumn(Avg, "AVG");
    AddColumn(fast, "FastEMA", 1.3);
    AddColumn(slow, "SlowEMA", 1.3);
    AddColumn(ATR0, "ATR", 1.3);
    //AddColumn(Risk_Per_Share, "Risk/Share");
    AddColumn(IIf(Buy, 111, IIf(Sell, 222, 0)) , "Buy1Sell2", 1);
    //AddColumn(PosSize, "EquityForPosSizing");
    AddColumn(Equity() , "Equity");
}  
else if(AAAction == actionPortfolio)
{
    bo = GetBacktesterObject();
    bo.PreProcess(); // Initialize backtester
    for( bar=0; bar < BarCount; bar++)
    {
        eq =  bo.Equity;
        for ( sig=bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar) )
        {
            if (sig.isExit())
            {
                if(bo.ExitTrade(bar,sig.symbol,sig.Price))
                {
                    _TRACE("EXIT: " + sig.symbol + "@" + sig.Price);
                }
            }
        }
 
        // update stats after closing trades
        bo.UpdateStats(bar, 1 );
        
        for ( sig=bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar))
        {
            if (sig.isEntry())
            {
                // sig.PosSize is passed from Phase I.
                ps = round(( eq * sig.PosSize)/250)*250 * sig.Price;
 
                if(bo.EnterTrade(bar, sig.symbol, True, sig.Price, ps,
sig.PosScore,sig.RoundLotSize))
                {
                    _TRACE("ENTRY: " + sig.symbol + " @" + sig.Price + " PosScore=" +
sig.PosScore + " PosSize=" + ps);
                }
            }
        }
 
        //bo.HandleStops(bar); // MUST BE PLACED HERE TO WORK FOR N-BAR STOPS. (not before enter/exit trades).
             
        bo.UpdateStats(bar,1); // MAE/MFE is updated when timeinbar is set to 1.
        bo.UpdateStats(bar,2);
    }
    bo.PostProcess(); // Finalize backtester
         
}
/*==============================================================================
    End of Formula
==============================================================================*/

3 comments

1. yo123

Dear Administrator ,
I have contributed afl codes out of which 1 has been published on your site , but i m not able to view hidden codes that are meant for contributors. Please help.

2. administrator

The other formulas you submitted are already on this site.

3. tsunamizawa

scan…….error

Leave Comment

Please login here to leave a comment.

Back