「Spreaded_Score_Type1_ver002.mq4」をさらにテストしながら修正していく過程で、それぞれのテクニカルから得た結果と計算結果の動きをインジケータにして表示しながら重み付けなどの調整がしたくなりました。
そこで、EAをインジケーター化することにしました。
EAをインジケーター化する為に、不要なプログラムを取り除いてとりあえず動くようになったのが下記インジケータ「Spreaded_Score_Indi1_ver001.mq4」です。
まだまだなところ多く、 For文などを追加してないため表示はしますが過去のラインは引いてくれません。現在からラインを引き始めるので少々待たないと表示が始まりません。1分足で動かさないと「なんにも動いてない」と勘違いしそうです。まあ、テストに使う分には大丈夫そうなので、このままEAテストの時に表示して使おうと思います。あとで、過去のラインも引けるようにFor文を追加したVer.も作りますがいつになるか・・・。
このインジを動かしていると大体±75ぐらいの値で売り買いすれば良いのではないかと思っています。プログラムには無駄な記載がまだ多いのでシェープしながらキレイにしていきたいところです。
出来上がったインジをiCustom関数化して使えばEAも動かしやすいのではないかと考えて勉強中です。
//+------------------------------------------------------------------+
//| Spreaded_Score_Indi1_ver001.mq4 |
//| Littlecub |
//+------------------------------------------------------------------+
#property copyright "Littlecub Custom Indicator"
#property indicator_separate_window
#property indicator_minimum -100
#property indicator_maximum 100
#property indicator_buffers 8
//---テクニカル荷重配分パラメータ(トータル100%)
extern int P_MA = 20; //初期値:20% トレンド
extern int P_BB = 20; //初期値:20% トレンド
extern int P_PSAR = 20; //初期値:20% トレンド
extern int P_Stoch = 15; //初期値:15% シグナル
extern int P_RSI= 15; //初期値:15% シグナル
extern int P_MACD = 10; //初期値:10% シグナル
//---機能使用スイッチパラメータ
extern bool UseStopLoss = False; //初期値:False
extern bool UseTakeProfit = False; //初期値:False
extern bool UseTrailingStop = True; //初期値:True
extern bool SignalMail = False; //初期値:False
extern bool EachTickMode = True; //初期値:True
extern bool ReverseSignal = False; //初期値:False
extern bool PositionClose = False; //初期値:False
extern bool ManyPosition = False; //初期値:False
//---テクニカル荷重配分バッファ
double Buffer1[]; //Trend1 Point_T1
double Buffer2[]; //Trend2 Point_T2
double Buffer3[]; //Trend3 Point_T3
double Buffer4[]; //Signal1 Point_S1
double Buffer5[]; //Signal2 Point_S2
double Buffer6[]; //Signal3 Point_S3
double Buffer7[]; //Point_TS
double Buffer8[]; //
//---外部宣言
int BarCount;
int Current;
bool TickCheck = False;
double Trend1; //MA
double Trend11; //MA
double Trend12; //MA
double Trend13; //MA
double Trend14; //MA
double Trend2; //BB
double Trend3; //PSAR
double Signal1; //Stoch
double Signal2; //RSI
double Signal3; //MACD
double Point_T1; //Trend1
double Point_T2; //Trend1 + Trend2
double Point_T3; //Trend1 + Trend2 + Trend3
double Point_S1; //Trend1 + Trend2 + Trend3 + Signal1
double Point_S2; //Trend1 + Trend2 + Trend3 + Signal1 + Signal2
double Point_S3; //Trend1 + Trend2 + Trend3 + Signal1 + Signal2 + Signal3
double Point_TS; //Trend1 + Trend2 + Trend3 + Signal1 + Signal2 + Signal3
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
BarCount = Bars;
if (EachTickMode) Current = 0; else Current = 1;
IndicatorBuffers (8);
SetIndexBuffer (0, Buffer1); //Trend1
SetIndexBuffer (1, Buffer2); //Trend2
SetIndexBuffer (2, Buffer3); //Trend3
SetIndexBuffer (3, Buffer4); //Signal1
SetIndexBuffer (4, Buffer5); //Signal2
SetIndexBuffer (5, Buffer6); //Signal3
SetIndexBuffer (6, Buffer7); //Point_TS
SetIndexBuffer (7, Buffer8);
SetIndexStyle (0,DRAW_LINE, EMPTY, 1, White); //Trend1
SetIndexStyle (1,DRAW_LINE, EMPTY, 1, Pink); //Trend2
SetIndexStyle (2,DRAW_LINE, EMPTY, 1, Red); //Trend3
SetIndexStyle (3,DRAW_LINE, EMPTY, 1, Aqua); //Signal1
SetIndexStyle (4,DRAW_LINE, EMPTY, 1, Blue); //Signal2
SetIndexStyle (5,DRAW_LINE, EMPTY, 1, Violet); //Signal3
SetIndexStyle (6,DRAW_LINE, EMPTY, 2, Chartreuse); //Point_TS
SetIndexStyle (7,DRAW_LINE, EMPTY, 1, Magenta);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator start function |
//+------------------------------------------------------------------+
int start() {
int Total, Ticket;
double StopLossLevel, TakeProfitLevel;
if (EachTickMode && Bars != BarCount) TickCheck = False;
Total = OrdersTotal();
//+------------------------------------------------------------------+
//| Variable //テクニカル計算 |
//+------------------------------------------------------------------+
//---Trend1 MA
double MA_05 = iMA(NULL,0, 5,0,MODE_EMA,PRICE_CLOSE,0);
double MA_10 = iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0);
double MA_25 = iMA(NULL,0,25,0,MODE_EMA,PRICE_CLOSE,0);
double MA_50 = iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,0);
double MA_75 = iMA(NULL,0,75,0,MODE_EMA,PRICE_CLOSE,0);
//---Trend2 Bollinger Bands
double BB_Main=iBands(NULL,0,21,0,0,PRICE_CLOSE,MODE_MAIN,0);
double BB_U1=iBands(NULL,0,21,1,0,PRICE_CLOSE,MODE_UPPER,0);
double BB_L1=iBands(NULL,0,21,1,0,PRICE_CLOSE,MODE_LOWER,0);
double BB_U2=iBands(NULL,0,21,2,0,PRICE_CLOSE,MODE_UPPER,0);
double BB_L2=iBands(NULL,0,21,2,0,PRICE_CLOSE,MODE_LOWER,0);
double BB_U3=iBands(NULL,0,21,3,0,PRICE_CLOSE,MODE_UPPER,0);
double BB_L3=iBands(NULL,0,21,3,0,PRICE_CLOSE,MODE_LOWER,0);
//---Trend3 Parabolic SAR
double PSAR=iSAR(NULL,0,0.02,0.2,0);
// double PSAR=iSAR(NULL,TimeFramePSAR,0.02,0.2,0);
//---Signal1 Stochstics
double St_Signal1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,1);
double St_Signal0 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
double St_Main1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,1);
double St_Main0 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0);
//---Signal2 RSI
double RSI0 = iRSI(NULL,0,14,PRICE_CLOSE,0);
//---Signal3 MACD
double Macd_Signal1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
double Macd_Signal0 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
double Macd_Main1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
double Macd_Main0 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
//+------------------------------------------------------------------+
//| Point //テクニカル荷重配分ポイント計算 |
//+------------------------------------------------------------------+
//---Trend1 MA
if (MA_05 > MA_10) Trend11 = P_MA * 1 / 15; else Trend11 = P_MA * (-1) / 15;
if (MA_10 > MA_25) Trend12 = P_MA * 2 / 15; else Trend12 = P_MA * (-2) / 15;
if (MA_25 > MA_50) Trend13 = P_MA * 4 / 15; else Trend13 = P_MA * (-4) / 15;
if (MA_50 > MA_75) Trend14 = P_MA * 8 / 15; else Trend14 = P_MA * (-8) / 15;
Trend1 = Trend11 + Trend12 + Trend13 +Trend14; //Signal
Point_T1 = Trend1;
//---Trend2 Bollinger Bands
if (Close[0] < BB_Main)
Trend2 = P_BB * (BB_L2 - Close[0]) / (BB_L2 - BB_L3); //BuySignal
if (Close[0] > BB_Main)
Trend2 = P_BB * (BB_U2 - Close[0]) / (BB_U3 - BB_U2); //SellSignal
Point_T2 = Point_T1 + Trend2;
//---Trend3 Parabolic SAR
if (Close[0] < PSAR) Trend3 = P_PSAR; //BuySignal
if (Close[0] > PSAR) Trend3 = P_PSAR * (-1); //SellSignal
Point_T3 = Point_T2 + Trend3;
//---Signal1 Stochstics
if (St_Signal1 >= St_Main1 && St_Signal0 < St_Main0)
Signal1 = P_Stoch * 1; //BuySignal
if (St_Signal1 <= St_Main1 && St_Signal0 > St_Main0)
Signal1 = P_Stoch * (-1); //SellSignal
Point_S1 = Point_T3 + Signal1;
//---Signal2 RSI
if (RSI0 < 25) Signal2 = P_RSI * (25 - RSI0) / 25; //BuySignal
if (RSI0 > 75) Signal2 = P_RSI * (75 - RSI0) / 25; //SellSignal
Point_S2 = Point_S1 + Signal2;
//---Signal3 MACD
if (Macd_Signal1 >= Macd_Main1 && Macd_Signal0 < Macd_Main0)
Signal3 = P_MACD * 1; //BuySignal
if (Macd_Signal1 <= Macd_Main1 && Macd_Signal0 > Macd_Main0)
Signal3 = P_MACD * (-1); //SellSignal
Point_S3 = Point_S2 + Signal3;
//---Point_TS
Point_TS = Trend1 + Trend2 + Trend3 + Signal1 + Signal2 + Signal3;
Print ("Trend and Signal Point is ", Point_TS);
//+------------------------------------------------------------------+
//| Point Buffer //テクニカル荷重配分ポイント保管 |
//+------------------------------------------------------------------+
//---Trend1 MA
Buffer1[0]=Point_T1;
//---Trend2 Bollinger Bands
Buffer2[0]=Point_T2;
//---Trend3 Parabolic SAR
Buffer3[0]=Point_T3;
//---Signal1 Stochstics
Buffer4[0]=Point_S1;
//---Signal2 RSI
Buffer5[0]=Point_S2;
//---Signal3 MACD
Buffer6[0]=Point_S3;
//---Point_TS
Buffer7[0]=Point_TS;
}
//+------------------------------------------------------------------+