How to Convert AmiBroker Code to TickZoom C#
Let's jump right in with an example of converting AmiBroker code for the inverse Fisher transform. A trader sent this code as an example of an AmiBroker function he uses a lot.
First, here's the chart that TickZOOM generates after the conversion.
Value1=0.1*(RSI(5)-50); Value2=2*WMA(Value1,9); ifish=(exp(Value2)-1)/(exp(Value2)+1); color = IIf(Ref(ifish,-1)<ifish,colorGreen,IIf(Ref(ifish,-1)>ifish,colorRed,colorBlack)); Plot(ifish,"Inverse Fisher Transform",color); Plot(0.5,"",colorBrightGreen,1); Plot(-0.5,"",colorRed,1);
Next, here's the code as converted for use in TickZOOM C#.
WMA has been implement so the code below works as shown in the chart.
using System;
using System.Drawing;
using TickZoom.Api;
namespace TickZoom
{
public class InverseFisherTransform : Indicator
{
Indicator value1;
Indicator value2;
RSI rsi;
WMA wma;
public override void Initialize()
{
// Display below the price chart
Drawing.PaneType = PaneType.Secondary;
// Display below the price chart
Drawing.IsVisible = true;
// Creates the formula arrays.
value1 = Formula.Indicator();
value2 = Formula.Indicator();
rsi = Formula.RSI(Bars.Close,5);
wma = Formula.WMA(value1, 5);
// Draws the reference lines.
Formula.ReferenceLine(0.5,Color.LightGreen);
Formula.ReferenceLine(-0.5,Color.Red);
}
public override void IntervalClose()
{
value1[0] = 0.1*(rsi[0]-50);
value2[0] = 2*wma[0];
this[0]=(Math.Exp(value2[0])-1)/(Math.Exp(value2[0])+1);
Drawing.Color = this[1]<this[0] ? Color.Green : this[1] > this[0] ? Color.Red : Color.Black;
Log.Trace("rsi="+rsi[0]+",wma="+wma[0]+",Value1="+value1[0]+",Value2="+value2[0]+",ifsh="+this[0]);
}
}
}
Similarities
Let's first focus on the similarities between the these code snippets. Compare the first line of the IntervalClose() method to the first line of code from AFL.
First, AmiBroker:
Value1=0.1*(RSI(5)-50);
Now TickZOOM:
value1[0] = 0.1*(rsi[0]-50);
As you see, they look very similar.
Difference in Array Access
On the first line, TickZoom needs the [0] after Value1 to show that you're setting the value of the most recent item in the array. Before the next time your model runs, this value moves index [1] and so on.
AFL makes the assumption that you want this exact same calculation for every value in the array and not just the latest only. Unfortunately, that means you lose the flexibility to dynamically change the formula for the array bar by bar or tick by tick as in TickZOOM.
NOTE: TickZoom C# arrays operate like EasyLanguage arrays. Index 0 refers to the current bar, index 1 refers to the previous bar. You can read more details on TickZoom C# arrays.
Also, you notice the same for the RSI formula. The "period" 5 of the RSI was already defined during the Initialize() method. So, on this first line, TickZoom needs the [0] after rsi which means to use the most recent RSI calculation.
Math Functions in C# vs. AmiBroker
Now let's examine the main calculation of the inverse Fisher transform.
AmiBroker:
ifish=(exp(Value2)-1)/(exp(Value2)+1);
Now TickZOOM:
this[0]=(Math.Exp(value2[0])-1)/(Math.Exp(value2[0])+1);
Once again, you the difference where !TickZOOM needs the [0] reference while AFL applies your reference to the entire array.
But there's another difference in the exp function for AFL. In TickZOOM you refer to it via Math.Exp instead.
The "Math." refers to a collection of mathematical formulas built into to the C# language and provided by MicroSoft. Go to the documentation for the Math class for C# to see the full list of math functions.
Attachments
-
InvFishChart.png
(26.8 KB) - added by waynewalter
20 months ago.
Inverse Fisher Transform

