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

Manual Tester in English for Amibroker (AFL)
crave
almost 9 years ago
Amibroker (AFL)

Rating:
5 / 5 (Votes 1)
Tags:
amibroker

Manual Tester formula – English translation from Russian
Not tested as yet … The results do not show up in the file.

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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
_SECTION_BEGIN("Manual Tester");
//  Manual Tester.afl - created by maxign
//  Manual Tester for AmiBroker
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
Plot(C,"",colorBlack,styleCandle);
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
if(TickSize == 0)
{
    PopupWindow("\n(Symbol -> Information) parameter TickSize!", "Error");
}
else
{
    // Parameters
    StartX = Param("Buttons X", 240, 0, 1000, 5);
    StartY = Param("Buttons Y", 20, 0, 1000, 5);
    Spread = Param("Spread (pips)", 0, 0, 1000) * TickSize;
    ScanMode = ParamList("Scan Mode", "Test|Clear all signals|Save to file|Load from file", 0);
    fileName = ParamStr("File path", "D://AmiBroker/Tester/Trades.txt");
  
    // Initialisation
    BarDateTime = DateTime();
    Buy = Sell = Short = Cover = 0;
    BuyPrice = SellPrice = ShortPrice = CoverPrice = C;
  
    // Code Execution Mode
    formulaAction = Status("ActionEx");
  
    // -------------- INDICATOR ---------------
  
    if(formulaAction == actionIndicator)
    {
        // Graphics parameters
        RequestTimedRefresh(1);
        GfxSetOverlayMode(0);
        GfxSetBkMode(1);
  
        // Buttons Size and the Distance between them
        CellHeight = 24;
        CellWidth = 70;
        CellXSpace = 10;
  
        // Buttons Color
        BorderColor = colorBlack;
        InactiveButtonColor = colorCustom6;
        ActiveButtonColor = colorRed;
  
        // Number of Active Button
        ActiveButton = StaticVarGet("ActiveButton");
  
        // Button Drawing Parameters
        GfxSelectPen(BorderColor, 2);
        GfxSelectFont( "Tahoma", 11 , 700);
  
        // Button Execution
        for(btn = 1; btn <= 6; btn++)
        {
            if(ActiveButton == btn)
            {
                GfxSelectSolidBrush(ActiveButtonColor);
                GfxSetTextColor(colorWhite);
            }
            else
            {
                GfxSelectSolidBrush(InactiveButtonColor);
                GfxSetTextColor(ColorRGB(40,40,40));
            }
  
            CellX = StartX + (btn - 1) * (CellWidth + CellXSpace);
            GfxRectangle(CellX, StartY, CellX + CellWidth, StartY + CellHeight);
  
            switch(btn)
            {
            case 1:
                BtnText = "Buy";
                break;
            case 2:
                BtnText = "Sell";
                break;
            case 3:
                BtnText = "Short";
                break;
            case 4:
                BtnText = "Cover";
                break;
            case 5:
                BtnText = "Clear";
                break;
            case 6:
                BtnText = "Clear All";
                break;
            }
  
            GfxDrawText(BtnText, CellX, StartY, CellX + CellWidth, StartY + CellHeight, 32+1+4);
        }
  
        // Left Button Press Execution
        if(GetCursorMouseButtons() & 8)
        {
            // Button Coordinates in Pixels
            px = GetCursorXPosition(1);
            py = GetCursorYPosition(1);
  
            buttonPressed = False;
  
            if(py >= StartY AND py <= StartY + CellHeight)
            {
                for(btn = 1; btn <= 6; btn++)
                {
                    CellX = StartX + (btn - 1) * (CellWidth + CellXSpace);
                    if(px >= CellX AND px <= CellX + CellWidth)
                    {
                        // Button Activation or Deactivation
                        if(ActiveButton == btn)
                            StaticVarSet("ActiveButton", 0);
                        else
                            StaticVarSet("ActiveButton", btn);
  
                        buttonPressed = True;
  
                        break;
                    }
                }
            }
  
            // Button Press "Clear All"
            if(buttonPressed == True AND StaticVarGet("ActiveButton") == 6)
            {
                for(i = 0; i < BarCount; i++)
                {
                    StaticVarRemove(Name() + "Buy"   + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "Sell"  + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "Short" + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "Cover" + DateTimeToStr(BarDateTime[i]));
  
                    StaticVarRemove(Name() + "BuyPrice"   + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "SellPrice"  + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "ShortPrice" + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "CoverPrice" + DateTimeToStr(BarDateTime[i]));
                }
  
                StaticVarSet("ActiveButton", 0);
            }
  
            // Transaction Record in Static Variable
            if(buttonPressed == False)
            {
                // Cursor Coordinates Price/Date
                x = GetCursorXPosition(0);
                y = GetCursorYPosition(0);
                y = round(y / TickSize) * TickSize;    // Rounding to TickSize
  
                // Buy
                if(ActiveButton == 1)
                {
                    VarBuy = Name() + "Buy" + DateTimeToStr(x);
                    VarBuyPrice = Name() + "BuyPrice" + DateTimeToStr(x);
  
                    StaticVarSet(VarBuy, 1);
                    StaticVarSet(VarBuyPrice, y);
                }
  
                // Sell
                if(ActiveButton == 2)
                {
                    VarSell = Name() + "Sell" + DateTimeToStr(x);
                    VarSellPrice   = Name() + "SellPrice" + DateTimeToStr(x);
  
                    StaticVarSet(VarSell, 1);
                    StaticVarSet(VarSellPrice, y);
                }
  
                // Short
                if(ActiveButton == 3)
                {
                    VarShort = Name() + "Short" + DateTimeToStr(x);
                    VarShortPrice = Name() + "ShortPrice" + DateTimeToStr(x);
  
                    StaticVarSet(VarShort, 1);
                    StaticVarSet(VarShortPrice, y);
                }
  
                // Cover
                if(ActiveButton == 4)
                {
                    VarCover   = Name() + "Cover" + DateTimeToStr(x);
                    VarCoverPrice = Name() + "CoverPrice" + DateTimeToStr(x);
  
                    StaticVarSet(VarCover, 1);
                    StaticVarSet(VarCoverPrice, y);
                }
  
                // Clear
                if(ActiveButton == 5)
                {
                    VarBuy = Name() + "Buy" + DateTimeToStr(x);
                    VarBuyPrice = Name() + "BuyPrice" + DateTimeToStr(x);
  
                    VarSell = Name() + "Sell" + DateTimeToStr(x);
                    VarSellPrice = Name() + "SellPrice" + DateTimeToStr(x);
  
                    VarShort = Name() + "Short" + DateTimeToStr(x);
                    VarShortPrice = Name() + "ShortPrice" + DateTimeToStr(x);
  
                    VarCover = Name() + "Cover" + DateTimeToStr(x);
                    VarCoverPrice = Name() + "CoverPrice" + DateTimeToStr(x);
  
                    StaticVarRemove(VarBuy);
                    StaticVarRemove(VarSell);
                    StaticVarRemove(VarShort);
                    StaticVarRemove(VarCover);
  
                    StaticVarRemove(VarBuyPrice);
                    StaticVarRemove(VarSellPrice);
                    StaticVarRemove(VarShortPrice);
                    StaticVarRemove(VarCoverPrice);      
                }
  
                StaticVarSet("ActiveButton", 0);    // Deactivation of the Button after Action Execution
            }
        }
  
        // Copying of Transactions from Static Variables into Trading Matrix
        for(i = 0; i < BarCount; i++)
        {
            BuySig   = StaticVarGet(Name() + "Buy"   + DateTimeToStr(BarDateTime[i]));
            SellSig  = StaticVarGet(Name() + "Sell"  + DateTimeToStr(BarDateTime[i]));
            ShortSig = StaticVarGet(Name() + "Short" + DateTimeToStr(BarDateTime[i]));
            CoverSig = StaticVarGet(Name() + "Cover" + DateTimeToStr(BarDateTime[i]));
  
            if(BuySig)
            {
                Buy[i] = 1;
                BuyPrice[i] = StaticVarGet(Name() + "BuyPrice" + DateTimeToStr(BarDateTime[i])) + spread;
            }
  
            if(SellSig)
            {
                Sell[i] = 1;
                SellPrice[i]  = StaticVarGet(Name() + "SellPrice"  + DateTimeToStr(BarDateTime[i]));
            }
  
            if(ShortSig)
            {
                Short[i] = 1;
                ShortPrice[i] = StaticVarGet(Name() + "ShortPrice" + DateTimeToStr(BarDateTime[i]));
            }
  
            if(CoverSig)
            {
                Cover[i] = 1;
                CoverPrice[i] = StaticVarGet(Name() + "CoverPrice" + DateTimeToStr(BarDateTime[i])) + spread;
            }
        }
  
        // ------ Arrows Drawing
        PlotShapes(Buy * shapeUpArrow, colorLime, 0, BuyPrice, -8);
        PlotShapes(Sell * shapeDownArrow, colorCustom12, 0, SellPrice, -8);
        PlotShapes(Short * shapeHollowDownArrow, colorCustom12, 0, ShortPrice, -8);
        PlotShapes(Cover * shapeHollowUpArrow, colorLime, 0, CoverPrice, -8);
    }
  
    // -------------- TEST MODE or SCAN ---------------
  
    if(formulaAction == actionScan OR formulaAction == actionBacktest)
    {
        // Testing
        if(ScanMode == "Test")
        {
            // Tester settings
            SetOption("InitialEquity", 10000);
            SetOption("AllowPositionShrinking", False);
            SetOption("ReverseSignalForcesExit", True);
            SetOption("AllowSameBarExit", True);
            SetOption("ActivateStopsImmediately", True);
            SetOption("MaxOpenPositions", 100);
            SetOption("PriceBoundChecking", False);
            SetOption("FuturesMode", True);
            SetOption("CommissionMode", 2);
            SetOption("CommissionAmount", 0);
            SetTradeDelays(0, 0, 0, 0);
  
            PositionSize = 100;
            MarginDeposit = 100;
            RoundLotSize = 1;
            PointValue = 1/TickSize;
  
            // Reading Transactions from Static Variables
            for(i = 0; i < BarCount; i++)
            {
                BuySig   = StaticVarGet(Name() + "Buy"   + DateTimeToStr(BarDateTime[i]));
                SellSig  = StaticVarGet(Name() + "Sell"  + DateTimeToStr(BarDateTime[i]));
                ShortSig = StaticVarGet(Name() + "Short" + DateTimeToStr(BarDateTime[i]));
                CoverSig = StaticVarGet(Name() + "Cover" + DateTimeToStr(BarDateTime[i]));
  
                if(BuySig)
                {
                    Buy[i] = 1;
                    BuyPrice[i] = StaticVarGet(Name() + "BuyPrice" + DateTimeToStr(BarDateTime[i])) + spread;
                }
  
                if(SellSig)
                {
                    Sell[i] = 1;
                    SellPrice[i]  = StaticVarGet(Name() + "SellPrice"  + DateTimeToStr(BarDateTime[i]));
                }
  
                if(ShortSig)
                {
                    Short[i] = 1;
                    ShortPrice[i] = StaticVarGet(Name() + "ShortPrice" + DateTimeToStr(BarDateTime[i]));
                }
  
                if(CoverSig)
                {
                    Cover[i] = 1;
                    CoverPrice[i] = StaticVarGet(Name() + "CoverPrice" + DateTimeToStr(BarDateTime[i])) + spread;
                }
            }
        }
  
        //  Static Variables Cleaning
        if(ScanMode == "Clear all signals")
        {
            for(i = 0; i < BarCount; i++)
            {
                StaticVarRemove(Name() + "Buy"   + DateTimeToStr(BarDateTime[i]));
                StaticVarRemove(Name() + "Sell"  + DateTimeToStr(BarDateTime[i]));
                StaticVarRemove(Name() + "Short" + DateTimeToStr(BarDateTime[i]));
                StaticVarRemove(Name() + "Cover" + DateTimeToStr(BarDateTime[i]));
  
                StaticVarRemove(Name() + "BuyPrice"   + DateTimeToStr(BarDateTime[i]));
                StaticVarRemove(Name() + "SellPrice"  + DateTimeToStr(BarDateTime[i]));
                StaticVarRemove(Name() + "ShortPrice" + DateTimeToStr(BarDateTime[i]));
                StaticVarRemove(Name() + "CoverPrice" + DateTimeToStr(BarDateTime[i]));
            }
  
            StaticVarSet("ActiveButton", 0);
        }
  
        // Recording Transactions to the File
        if(ScanMode == "Save to file")
        {
            // The number of digits after the decimal point
            digits = Max(log10(1/TickSize), 0);
  
            // Opening File to Write
            fh = fopen(fileName, "w");
          
            if(fh)
            {
                for(i = 0; i < BarCount; i++)
                {
                    BuySig   = StaticVarGet(Name() + "Buy"   + DateTimeToStr(BarDateTime[i]));
                    SellSig  = StaticVarGet(Name() + "Sell"  + DateTimeToStr(BarDateTime[i]));
                    ShortSig = StaticVarGet(Name() + "Short" + DateTimeToStr(BarDateTime[i]));
                    CoverSig = StaticVarGet(Name() + "Cover" + DateTimeToStr(BarDateTime[i]));
  
                    if(BuySig)
                    {
                        Price  = StaticVarGet(Name() + "BuyPrice"  + DateTimeToStr(BarDateTime[i]));
                        fputs(Name() + "Buy," + DateTimeToStr(BarDateTime[i]) + "," + NumToStr(Price, digits/10, False) + "\n", fh);
                    }
  
                    if(SellSig)
                    {
                        Price  = StaticVarGet(Name() + "SellPrice"  + DateTimeToStr(BarDateTime[i]));
                        fputs(Name() + "Sell," + DateTimeToStr(BarDateTime[i]) + "," + NumToStr(Price, digits/10, False) + "\n", fh);
                    }
  
                    if(ShortSig)
                    {
                        Price = StaticVarGet(Name() + "ShortPrice" + DateTimeToStr(BarDateTime[i]));
                        fputs(Name() + "Short," + DateTimeToStr(BarDateTime[i]) + "," + NumToStr(Price, digits/10, False) + "\n", fh);
                    }
  
                    if(CoverSig)
                    {
                        Price = StaticVarGet(Name() + "CoverPrice" + DateTimeToStr(BarDateTime[i]));
                        fputs(Name() + "Cover," + DateTimeToStr(BarDateTime[i]) + "," + NumToStr(Price, digits/10, False) + "\n", fh);
                    }
                }
  
                fclose(fh);
            }
            else
                PopupWindow("\n\nFile Opening or Creating Error" + fileName + "\n\nCreate a Specified Folder", "Export Error", 60);
        }
  
        // Downloading transactions from a file
        if(ScanMode == "Load from file")
        {
            // Opening File for reading
            fh = fopen(fileName, "r");
  
            if(fh)
            {
                // Cleaning Signals from Graphics
                for(i = 0; i < BarCount; i++)
                {
                    StaticVarRemove(Name() + "Buy"   + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "Sell"  + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "Short" + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "Cover" + DateTimeToStr(BarDateTime[i]));
  
                    StaticVarRemove(Name() + "BuyPrice"   + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "SellPrice"  + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "ShortPrice" + DateTimeToStr(BarDateTime[i]));
                    StaticVarRemove(Name() + "CoverPrice" + DateTimeToStr(BarDateTime[i]));
                }
  
                StaticVarSet("ActiveButton", 0);
  
                // Reading signals from the file
                while(! feof(fh))
                {
                    // Reading lines from the file
                    stringTrade = fgets(fh);
                      
                    // parsing
                    sName = StrExtract(stringTrade, 0);
                    sSig = StrExtract(stringTrade, 1);
                    sDate = StrExtract(stringTrade, 2);
                    sPrice = StrExtract(stringTrade, 3);
  
                    VarSig = sName + sSig + sDate;
                    VarPrice = sName + sSig + "Price" + sDate;
  
                    // Static Variables Writing
                    StaticVarSet(VarSig, 1);
                    StaticVarSet(VarPrice, StrToNum(sPrice));
                }
  
                fclose(fh);
            }
            else
                PopupWindow("\n\nError opening file " + fileName + "\n\nThis file does not exist.", "Import error", 60);
        }
    }
}
_SECTION_END();

0 comments

Leave Comment

Please login here to leave a comment.

Back