短期・長期の2種類のRSIを使ったEA
短期・長期の2種類のRSIを使ったEAを作成したいと思います。
- RSI短期3が10以下で長期RSI14が30以下でロングエントリー
- RSI短期3が90以上で長期RSI14が70以上でショートエントリー
という2つのRSIが条件が重なったらエントリーします。
メタエディタ(MetaEditor)を立ち上げる
メタエディタ(MetaEditor)を立ち上げましょう。今回は名前を「double-RSI」で作成します。
パラメーターを記述する
パラメーターを記述しましょう。
input int Fast = 3;//短い期間のRSI input int Slow = 14;//長い期間のRSI input int TakeProfit = 5;//利確 input double Lots = 0.01;//ロット数 input int MagicNumber = 12345;//マジックナンバー
Copy
OnTick()関数を記述する
OnTick()関数を記述しましょう。
まず、それぞれの変数にiRSI関数の値を代入します。
double FastRSI = iRSI(NULL, 0, Fast, PRICE_CLOSE, 0); double SlowRSI = iRSI(NULL, 0, Slow, PRICE_CLOSE, 0);
OrdersTotal()が0でSlowRSIが30以下でFastRSIが10以下の場合に
if(OrdersTotal() == 0 && SlowRSI < 30 && FastRSI < 10)
ロングのポジションを持ちます。
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point*10,"Order Long",MagicNumber,0,Lime);
ショートは逆で、OrdersTotal()が0でSlowRSIが70以上でFastRSIが90以上の場合に
if(OrdersTotal() == 0 && SlowRSI > 70 && FastRSI > 90)
ショートポジションを持ちます。
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point*10,"Order Short",MagicNumber,0,Red);
これでOnTick()関数は完了です。
double FastRSI = iRSI(NULL, 0, Fast, PRICE_CLOSE, 0);//短い期間のRSI
double SlowRSI = iRSI(NULL, 0, Slow, PRICE_CLOSE, 0);//長い期間のRSI
if(OrdersTotal() == 0 && SlowRSI < 30 && FastRSI < 10)//トータルポジションが0でSlowRSIが30より低くFastRSIが10より低い場合
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point*10,"Order Long",MagicNumber,0,Lime);//ロングエントリー
}
if(OrdersTotal() == 0 && SlowRSI > 70 && FastRSI > 90)//トータルポジションが0でSlowRSIが70より大きくFastRSIが90より大きい場合
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point*10,"Order Short",MagicNumber,0,Red);//ショートエントリー
}Copy
コンパイルする
コンパイルしましょう。動きを確認できたら完了です。
ソースコード全体
//+------------------------------------------------------------------+
//| Double-RSI.mq4 |
//| Copyright 2020, FX-EA System Project Creator |
//| https://creator.fx-ea-system-project.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, FX-EA System Project Creator"
#property link "https://creator.fx-ea-system-project.com/"
#property version "1.00"
#property strict
/*パラメーター*/
input int Fast = 3;//短い期間のRSI
input int Slow = 14;//長い期間のRSI
input int TakeProfit = 5;//利確
input double Lots = 0.01;//ロット数
input int MagicNumber = 12345;//マジックナンバー
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
double FastRSI = iRSI(NULL, 0, Fast, PRICE_CLOSE, 0);//短い期間のRSI
double SlowRSI = iRSI(NULL, 0, Slow, PRICE_CLOSE, 0);//長い期間のRSI
if(OrdersTotal() == 0 && SlowRSI < 30 && FastRSI < 10)//トータルポジションが0でSlowRSIが30より低くFastRSIが10より低い場合
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point*10,"Order Long",MagicNumber,0,Lime);//ロングエントリー
}
if(OrdersTotal() == 0 && SlowRSI > 70 && FastRSI > 90)//トータルポジションが0でSlowRSIが70より大きくFastRSIが90より大きい場合
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point*10,"Order Short",MagicNumber,0,Red);//ショートエントリー
}
}
//+------------------------------------------------------------------+Copy






コメント