🌊
MT5EAプロトタイプ
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2020, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void position_all_close(ENUM_ORDER_TYPE side)
{
for(int i=PositionsTotal()-1; i>=0; i--)
{
if("" != PositionGetSymbol(i))
{
if(PositionGetInteger(POSITION_TYPE)==side)
{
if(Symbol()==PositionGetString(POSITION_SYMBOL))
{
if(PositionGetInteger(POSITION_MAGIC)==MagicNumber)
{
position_close(side,PositionGetInteger(POSITION_TICKET));
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void position_close(ENUM_ORDER_TYPE order_type,ulong position_ticket)
{
MqlTradeRequest req = {};
MqlTradeResult res = {};
order_type = order_type==ORDER_TYPE_BUY?ORDER_TYPE_SELL:ORDER_TYPE_BUY;
req.action = TRADE_ACTION_DEAL; // 成行注文
req.symbol = Symbol();
req.volume = lots; // 注文数量
req.type = order_type; // 売買方向 ORDER_TYPE_BUY or ORDER_TYPE_SELL
req.deviation = slippage; // スリップページ
req.magic = MagicNumber; // マジックナンバー
req.comment = ""; // コメント
req.position = position_ticket; //決済するポジションを指定する
bool order_result = OrderSend(req, res);
if(order_result == false)
{
Print(res.retcode);
}
}
int MagicNumber = 123; // マジックナンバー
double lots = 0.01; // ロットサイズ
int slippage = 10; // スリッページ
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void position_entry(ENUM_ORDER_TYPE order_type)
{
MqlTradeRequest req = {};
MqlTradeResult res = {};
req.action = TRADE_ACTION_DEAL; // 成行注文
req.symbol = Symbol();
req.volume = lots; // 注文数量
req.type = order_type; // 売買方向 ORDER_TYPE_BUY or ORDER_TYPE_SELL
req.deviation = slippage; // スリップページ
req.magic = MagicNumber; // マジックナンバー
req.comment = ""; // コメント
bool order_result = OrderSend(req, res);
if(order_result == false)
{
Print(res.retcode);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int order_count()
{
int count =0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(OrderGetTicket(i)))
{
if(Symbol()==OrderGetString(ORDER_SYMBOL))
{
if(OrderGetInteger(ORDER_MAGIC)==MagicNumber)
{
count++;
}
}
}
}
return count ;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int position_count(ENUM_ORDER_TYPE order_type)
{
int count =0;
for(int i=PositionsTotal()-1; i>=0; i--)
{
if("" != PositionGetSymbol(i))
{
if(PositionGetInteger(POSITION_TYPE)==order_type)
{
if(Symbol()==PositionGetString(POSITION_SYMBOL))
{
if(PositionGetInteger(POSITION_MAGIC)==MagicNumber)
{
count++;
}
}
}
}
}
return count ;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double getMAValue(int shift)
{
static int ma_handle = -1; // グローバルハンドル
// 移動平均線のハンドルが未取得の場合
if(ma_handle == -1)
{
ma_handle = iMA(_Symbol, PERIOD_H1, 14, 0, MODE_SMA, PRICE_CLOSE); // 例として、14期間の単純移動平均を取得
}
double maValue[]; // 値を格納する配列
// バッファをコピーして移動平均の値を取得
CopyBuffer(ma_handle, 0, shift, 1, maValue);
return maValue[0]; // 最新の移動平均線の値を返す
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double getBollingerBand(int mode,int shift)
{
//mode == 0 Base Line
//mode == 1 Upper Band
//mode == 2 Lower Band
static int handle = -1;
// ボリンジャーバンド指標のハンドルを取得
if(handle == -1)
{
handle = iBands(_Symbol, PERIOD_H1, 20, 0, 2.0, PRICE_CLOSE);
}
double Band[];
// バッファをコピーしてラインの値を取得
CopyBuffer(handle, mode, shift, 1, Band); // 基本線
return Band[0];
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double getRSIValue(int shift)
{
static int handle = -1;
// RSI指標のハンドルを取得
if(handle == -1)
{
handle = iRSI(_Symbol, PERIOD_H1, 14, PRICE_CLOSE);
}
double rsiValue[];
// バッファをコピーしてRSIの値を取得
CopyBuffer(handle, 0, shift, 1, rsiValue);
return rsiValue[0];
}
//+------------------------------------------------------------------+
Discussion