PureBytes Links
Trading Reference Links
|
Very interesting -- please share it.
--- In amibroker@xxxxxxxxxxxxxxx, "netsdkforab" <netsdkforab@xxx> wrote:
>
> Hi,
>
> I have been working on .Net SDK. A have sent a post before
>
> http://finance.groups.yahoo.com/group/amibroker/message/142119
>
> but I got only 3 replies.
>
> If anyone is interested please reply to me directly. (If there is not enough interest I will not make it available. I do it, bacause I do intraday autotrading.)
>
> Here are two sample code fragments. The first is an indicator class with three indicator panels. The third function demos how to pass AFL variables between .Net and AFL.
>
> The second code fragment starting with the [ABMethod] attribute is a real plug in function that is directly accessable from AFL. (But this is for more advanced developers.) There are three parameters (array, string and float) passed from AFL to the .Net function.
>
> Regards,
>
> NetSDKforAB
>
> using System;
> using System.Diagnostics;
> using AmiBroker;
> using AmiBroker.PlugIn;
> using YUtils;
>
> namespace SamplePlugIn
> {
> unsafe public class Samples : IndicatorBase
> {
> /// <summary>
> /// This function demos how to create a simple
> /// "average crossing" indicator in .Net.
> /// ATArray objects (Open, High, etc.) hold time series data.
> /// AFxxx classes have static members to execute AFL functions.
> /// </summary>
> public void Sample1()
> {
> // calculate typical price from bar price data
> ATArray MyTypicalPrice = (High + Low + 2 * Close) / 4;
>
> // calculate slow average of typical price
> ATArray SlowMa = AFAvg.Ma(MyTypicalPrice, 20);
>
> // plotting average typical price
> AFGraph.Plot(SlowMa, "Ma20", Color.Black, Style.Thick);
>
> // calculate fast average of close price
> ATArray FastEma = AFAvg.Ema(Close, 5);
>
> // plotting fast average close price with alternating color
> AFGraph.Plot(FastEma, "Ema5",
> AFTools.Iif(SlowMa < FastEma, (float)Color.DarkGreen, (float)Color.Brown),
> Style.Line);
>
> // calculate the difference of the two averages
> ATArray Diff = (FastEma - SlowMa) / SlowMa * 100;
>
> // plotting difference as a histogram
> AFGraph.Plot(Diff, "Diff", Color.Red, Style.Histogram | Style.OwnScale, -0.2f, 0.2f);
> }
>
> /// <summary>
> /// Demos how to do fast loops
> /// Because of compiled code and integer index arithmetric
> /// loops are 2-10 times faster than AFL script loops
> /// </summary>
> public void Sample2()
> {
> try
> {
> int maPeriod = 20;
> float tempSum;
>
> // declaration of result array
> ATArray MyMa;
>
> // allocation of memory for result array
> MyMa = new ATArray();
>
> // set null values to the beginning of the array
> for (int i = 0; i < maPeriod - 1 && i < MyMa.Length; i++)
> MyMa[i] = ATFloat.Null;
>
> // calculate the average for each bar
> for (int i = maPeriod - 1; i < MyMa.Length; i++)
> {
> // clear temporary result
> tempSum = 0.0f;
>
> // inner loop to sum bar data
> for (int j = 0; j < maPeriod; j++)
> tempSum = tempSum + Close[i - j];
>
> // saving calculated value to array
> MyMa[i] = tempSum / maPeriod;
> }
>
> // plot the calculated average
> AFGraph.Plot(MyMa, "MyMa", Color.Black, Style.Line);
> }
> catch (Exception e)
> {
> YException.Show("Error while executing indicator.", e);
> }
> }
>
> /// <summary>
> /// Reading and writing AFL global variables
> /// </summary>
> public void Sample3()
> {
> try
> {
> // defining AFL variable object
> ATAfl EmaPeriodAfl = new ATAfl("Period");
>
> // reading value from AFL variable
> // AFL variable MUST be initialized with a float value
> // uninitialized variable or other data types will cause exception
> float emaPeriod = EmaPeriodAfl.GetFloat();
>
> // do the calculation of the average
> ATArray MyEma = AFAvg.Ema(Close, emaPeriod);
>
> // plot the average
> AFGraph.Plot(MyEma, "MyEma", Color.Black, Style.Line);
>
> // defining AFL variable "MyEma" to store result
> ATAfl EmaAfl = new ATAfl("MyEma");
>
> // setting calculated array value to AFL variable
> // following AFL scripts can use this calculated array
> EmaAfl.Set(MyEma);
> }
> catch (Exception e)
> {
> YException.Show("Error while executing indicator.", e);
> }
> }
> }
> }
>
>
> [ABMethod]
> [ABParameter(0, Type = ABParameterType.Array, Decription = "color")]
> [ABParameter(1, Type = ABParameterType.String, Decription = "plotName")]
> [ABParameter(2, Type = ABParameterType.Float, Decription = "level")]
> unsafe public static ATVar XDebugRibbon(int argNum, ATVar* argList)
> {
> YDebug.DebugRibbon(argList[0].GetArray(), argList[1].GetString(), (int)argList[2].GetFloat());
> return ATVar.CreateNone();
> }
>
------------------------------------
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|