.NET やってみた

 
結論から言うと できなかった


// F#

namespace MyNameSpace


type public MyClass =

    static member public MyMethod x =

        x + 1


// MQL5

#import "mylib.dll"


void OnStart()

{

    MyClass::MyMethod(2);

}


initializing of my-script (USDJPY,M1) failed with code 0

 

その後 めちゃくちゃ苦労しましたが できました

定番? の単純移動平均線のソースを貼っときます

MoreLINQ (https://morelinq.github.io/) に依存しているので

terminal64.exe と同じディレクトリに MoreLinq.dll を置いてください (正直 これが一番悩まされた)

MoreLinq.dll は nuget.exe で入手できます

ちなみに .NET Standard でつくりました

つかれました


// SMACS.mq5

#import "SMACS.dll"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_label1 "SMA"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
input int PERIOD = 12;
double sma[];
int OnInit()
{
SetIndexBuffer(0, sma, INDICATOR_DATA);
PlotIndexSetString(0, PLOT_LABEL, "SMA(" + IntegerToString(PERIOD) + ")");
return INIT_SUCCEEDED;
}
int OnCalculate(const int TOTAL,
const int PREV,
const datetime &T[],
const double &O[],
const double &H[],
const double &L[],
const double &C[],
const long &TVOL[],
const long &VOL[],
const int &SP[])
{
double c[];
ArrayCopy(c, C);
SMACS::sma(sma, c, PERIOD, TOTAL, PREV);
return TOTAL;

}


// SMACS.cs

using System;
using System.Collections.Generic;
using System.Linq;
using MoreLinq;
// PM> Install-Package morelinq -Version 3.1.0
public static class SMACS
{
public static void sma(double[] sma, double[] c, int period, int total, int prev)
{
if (prev == 0 || total <= period)
{
c.WindowRight(period)
.Select(xs => xs.Average())
.ToArray()
.CopyTo(sma, 0);
}
else
{
Array.Copy(c.WindowRight(period)
.Skip(prev - 1)
.Select(xs => xs.Average())
.ToArray(), 0, sma, prev - 1, total - prev + 1);
// Array.Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length);
}
}
}
理由: