例 EA01

#property copyright “Copyright 2020, ON”
#property link “http://www.oonuma.com”
#property version “15.3”
#property strict
変数の宣言
input string OperationPC = “F2BBOCO(”;
稼働PC Name-Ver
extern int HistryCount=5; 過去足のカウント15分足で10日は560
input int DepositLimit = 200;
最低保証金維持率% 200%
extern int BuySellOnOff =1; 売買 Off=0,On=1,買いのみ=2,売りのみ=3
extern int TakeProfit=80;
T/P利食い(Pips) 練習50、本番150=20Pips、
extern int SaShiNeHaba = 70; 幅
extern int StopLoss =0;
S/L損切り 160

extern double ShiftGak =0.00; レンジ中のTOPorLow
double MA_Diff = 0.01;
移動平均値の差(金額) 15分足=0.015、1時間足=0.001
extern int PeriodPara =0; MA時間軸足,() 60,15,4時間=240
input int BuyMaxHoldPosition=1;
買いポジション最大保有数
input int SellMaxHoldPosition=1; 売りポジション最大保有数
extern double BuyLots =0.02;
BuyLots1回当たり数量 0.01=千通貨,0.1=1万通貨
extern double SellLots =0.02; SelLots1回当たり数量 0.01=千通貨,0.1=1万通貨
extern double Lots =0.01; 1回当たり数量 0.01=千通貨,0.1=1万通貨
extern int Magic = 2001271;
マジックナンバー
extern int MagicB =0 ; マジックナンバー2
extern double Kessai_Gak = 0.03; 決済利益幅(金額)(0.2=20銭)15分足=0.2、1時間足=0.001 
extern int BoBa_Para =0;
BoBa_売買判定Para 1=Buy,2=Sell
extern int RSI_Para =0; RSI_売買判定Para 1=Buy,2=Sell
extern int Slippage = 10;
Slippage
extern string Comments = “”; コメント
extern int BoBa_Shift=0 ;
ボリンジャーバンドバーの左シフト
int Ticket_Buy =0;発注結果リターン
int Ticket_Sel =0;
発注結果リターン
int Count_Buy =0;買いポジション数管理Count_Buy
int Count_Sel =0;
売りポジション数管理Count_Sel
int Count_BUY_RSI =0;RSIのポジション数管理
int Count_SELL_RSI=0;RSIのポジション数管理
int Adjusted_Slippage = 0;
double StopTopGaku=0;
double StopLowGaku=0;
double KeyPointGaku=0;
double Pips=0;
int JiKamKBN=0;注文は1時間単位、決済は30分単位 区分1=実施、0=休み
/*
#include
*/
extern double UsdStopTopGaku=110.0; Usd売買上限額 2020/01/23
extern double UsdStopLowGaku=108.5;
Usd売買下限額
extern double EurStopTopGaku=123.0; Eur売買上限額
extern double EurStopLowGaku=119.8;
Eur売買下限額
extern double AudStopTopGaku=76.2; Aud売買上限額
extern double AudStopLowGaku=74.5;
Aud売買下限額
extern double GBPStopTopGaku=146.0; GBP売買上限額
extern double GBPStopLowGaku=141.0;
GBP売買下限額
2018/07/30
input int Adjust_Stop=2;
input int Stop_Loss=3;
input int Take_Profit=3;
double Buy_Stop_Loss=0;
double Buy_Take_Profit=0;
double Sell_Stop_Loss=0;
double Sell_Take_Profit=0;
bool Modified=false;

2018/08/01
extern int Open_Minute = 0;
extern int Open_Minute2 = 30;
int StopLoss_OnOff=0;
損切りするか?1=する、2=買いはしない、3=売りはしない、0=損切りしない。
double Lots_Value =0;
input int StandardOrSummarTime=1; 標準時間=1,夏時間=2
+——————————————————————+
関数の定義
+——————————————————————+
関数の定義
double AdjustPoint(string Currency)
{
double Calculated_Point=0;
int Symbol_Digits=(int)MarketInfo(Currency,MODE_DIGITS);

if(Symbol_Digits == 2 || Symbol_Digits == 3)
{
Calculated_Point = 0.01;
int Calculated_Slippage = Slippage_Pips;
}
else if(Symbol_Digits == 4 || Symbol_Digits == 5)
{
Calculated_Point = 0.0001;
}
return(Calculated_Point);
}
*
/*
int AdjustSlippage(string Currency,int Slippage_Pips) Currency=通貨
{
int Calculated_Slippage = 0;
int Symbol_Digits = (int)MarketInfo(Symbol(),MODE_DIGITS);
int Symbol_Digits = (int)MarketInfo(Currency,MODE_DIGITS);MODE_DIGITS=提示レートの小数点以下の桁数

if(Symbol_Digits == 2 || Symbol_Digits == 4)
{
Calculated_Slippage = Slippage_Pips;
int Calculated_Slippage = Slippage_Pips;
}
else if(Symbol_Digits == 3 || Symbol_Digits == 5)
{
Calculated_Slippage = Slippage_Pips * 10;
}
return(Calculated_Slippage);
}
2018/07/30
double AdjustPoint(string Currency)
{
double Calculated_Point=0;
int Symbol_Digits=(int)MarketInfo(Currency,MODE_DIGITS);

if(Symbol_Digits == 2 || Symbol_Digits == 3)
{
Calculated_Point = 0.01;
int Calculated_Slippage = Slippage_Pips;
}
else if(Symbol_Digits == 4 || Symbol_Digits == 5)
{
Calculated_Point = 0.0001;
}
return(Calculated_Point);
}
*/

+——————————————————————+
| AlertVisi
+——————————————————————+
int AlertVisi (string Messg1)
{
Alert(Symbol(),Messg1,“, P(”,Period(),“M),RSI=”,DoubleToStr(RSI_Value,2));
Print(Messg1+“, P(”+IntegerToString(Period(),2)+“M),”+“RSI=”+DoubleToStr(RSI_Value,2));

Sleep(600000);10分停止
Sleep(300000);5分停止
Sleep(420000);7分停止
return(0);
}
+——————————————————————+
| expert initialization function |
+——————————————————————+
int OnInit() int init()
{
—-

Pips=AdjustPoint(Symbol());
Adjusted_Slippage = AdjustSlippage(Symbol(),Slippage); Symbol()=通貨ペア名を取得

if(Symbol()==“USDJPY-cd”)
{
ドル円の上下限額をセット
StopTopGaku=UsdStopTopGaku;
StopLowGaku=UsdStopLowGaku;
Kubun=2;1
KeyPointGaku=UsdKeyPointGaku;
StopLoss_OnOff=0;
}
else if(Symbol()==“EURJPY-cd”)
{
ユーロ円の上下限額をセット
StopTopGaku=EurStopTopGaku;
StopLowGaku=EurStopLowGaku;
Kubun=2;
KeyPointGaku=EurKeyPointGaku;
StopLoss_OnOff=0;

}
else if(Symbol()==“AUDJPY-cd”)
{
オーストラリア円の上下限額をセット
StopTopGaku=AudStopTopGaku;
StopLowGaku=AudStopLowGaku;
Kubun=2; 1
KeyPointGaku=AudKeyPointGaku;
StopLoss_OnOff=0;
SaShiNeHaba=SaShiNeHaba+10;
}
else if(Symbol()==“GBPJPY-cd”)
{
ポンド円の上下限額をセット
StopTopGaku=GBPStopTopGaku;
StopLowGaku=GBPStopLowGaku;
Kubun=2;1
KeyPointGaku=GBPKeyPointGaku;
StopLoss_OnOff=1;
SaShiNeHaba=SaShiNeHaba+10;

Alert(“GBPJPY-cd Stop”);
return(0);
}
else
{
StopTopGaku=0;
StopLowGaku=0;
Kubun=1;
KeyPointGaku=0;

}

—-
return(0);
}
+——————————————————————+
| expert deinitialization function |
+——————————————————————+
void OnDeinit(const int reason)
int deinit()
{
—-
—-
return(0);
}
+——————————————————————+
| expert start function |
+——————————————————————+
void OnTick() int start()
{
— go trading only for first tiks of new bar
if(Volume[0]>1) return;
PeriodPara=Period();
double NeHaba_Value2;

string Comments_Value = OperationPC + Comments+“”+IntegerToString(PeriodPara,2)+“M)”;
BoBa_Para=0;
*
時間チェック
*
—————
 時間確認 経済指標時間は変動が大きので発注しない
—————
日本時間6時間プラス、3+6= 9時00分 夏時間
Lots_Value=Lots;
*
2) 発注可能時間のチェック
*
—————
 時間確認 経済指標時間は変動が大きので発注しない
—————
標準時間 日本時間 5時間プラス、3+5= 8時00分
夏時間  日本時間 6時間プラス、3+6= 9時00分

【米国サマータイム(夏時間)】2007年より3月第2日曜日~11月第1日曜日
取引時間:(日本時間)月曜午前7時~土曜午前6時
【米国標準時間(冬時間)】2007年より11月第1日曜日~3月第2日曜日
取引時間:(日本時間)月曜午前7時~土曜午前7時

* AM5時30から6時30分まで停止。Start
– 標準時間 +7時間
/* 2020/01/28 コメント行
if(StandardOrSummarTime==1)
{
if(Hour()==22)
{
if(Minute()> 15 && Minute()⇐59 ) 日本時間7時間プラス、22+7=29-24= 5時00分 標準時間
{
Alert(Symbol()+“ Time Out Hour=”+Hour()) ;
return;
}
}
6時~8時59不分まで停止
if(Hour()==23) 23+7=30-24=6時
{
Alert(Symbol()+“ Time Out Hour=”+Hour()) ;
return;
}
2019/11/18 8時代は発注へ変更
if(Hour()==0)
0+7=7時
{
Alert(Symbol()+“ Time Out Hour=”+Hour()) ;
return;
}
if(Hour()==1) 1+7=8時
{
return;
}
}
– 夏時間 +6時間
if(StandardOrSummarTime==2)
{
if(Hour()==23)
{
if(Minute()> 15 && Minute()⇐59 )
日本時間6時間プラス、23+6=29-24= 5時00分 夏時間
{
Alert(Symbol()+“ Time Out Hour=”+Hour()) ;
return;
}
}
6時~8時59不分まで停止
if(Hour()==0)
0+6=6時
{
Alert(Symbol()+“ Time Out Hour=”+Hour()) ;
return;
}
if(Hour()==1)
1+6=7時
{
Alert(Symbol()+“ Time Out Hour=”+Hour()) ;
return;
}
if(Hour()==2)
2+6=8時
{
Alert(Symbol()+“ Time Out Hour=”+Hour()) ;
return;
}
}
* AM5時30から6時30分まで停止。END
HattyuOnOff=9;
if(Minute()== 0 )
00分は変動が大きので発注しない
{
return;
}
if(Hour()==2 && Minute()== 0 ) 日本時間6時間プラス、 2+6 = 8時00分 夏時間
{
return;
}
if(Hour()==3 && Minute()== 0 )
日本時間6時間プラス、3+6 = 9時00分 夏時間
{
return;
}
if(Hour()==7 && Minute()== 0 ) 日本時間6時間プラス、7+6 = 13時00分 夏時間
{
return;
}
if(Hour()==10 && Minute()== 0 )
日本時間6時間プラス、10+6= 16時00分 夏時間
{
return;
}
if(Hour()==12 && Minute()== 0 ) 日本時間6時間プラス、12+6= 18時00分 夏時間
{
return;
}

if(Hour()==15 && Minute()== 30 )
日本時間6時間プラス、15+6= 21時30分 夏時間
{
return;
}
if(Hour()==17 && Minute()== 00 ) 日本時間6時間プラス、17+6= 23時00分 夏時間
{
return;
}
if(Hour()==19 && Minute()== 00 )
日本時間6時間プラス、19+6= 25時00分 夏時間
{
return;
}

if(Hour()==23)
{
if(Minute()> 15 && Minute()⇐59 )
AM5時30から6時30分まで停止。日本時間6時間プラス、23+6= 5時00分 夏時間
{
return;
}
}
if(Hour()==0)
{
if(Minute()⇐35 ) AM5時30から6時30分まで停止。日本時間6時間プラス、0+6= 6時00分 夏時間
{
return;
}
}
2020/01/28 コメントEND
*/
*
現在時刻取得し、発注有効期限設定
*
int nen,tuki,hi,jikan,fun;
int kasanJIkan;

kasanJIkan=1;
有効時間設定係数 '19/08/02 4→2、'19/06/06 3→4

nen=Year();
tuki=Month();
hi=Day();
jikan=Hour();
fun=Minute();
*有効期限 1=1時間
jikan=jikan+kasanJIkan;
*

if(jikan>23)
{
jikan=0;
hi=hi+1;
}

if(tuki==1 || tuki==3 || tuki==5 || tuki==7 || tuki==8 || tuki==10 || tuki==12)
{
if(hi>31)
{
hi=1;
tuki=tuki+1;

if(tuki==12)
{
tuki=1;
nen=nen+1;
}
}
}
else if(tuki==2)
{

if(hi>28)
{
hi=3;
tuki=tuki+1;
}

}
string HattyuKigen =nen+“.”+tuki+“.”+hi+“ ”+jikan+“:”+fun;
—
*
保有ポジション数確認
*
Count_Buy=0;
Count_Sel=0;

MagicB=Magic;


for(int i=0;i {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MagicB || OrderSymbol()!=Symbol()) continue;
— check order type
if(OrderType()==OP_BUYSTOP)
{
Count_Buy=Count_Buy+1;
}
if(OrderType()==OP_SELLSTOP)
{
Count_Sel=Count_Sel+1;
}
}

if (Count_Buy>BuyMaxHoldPosition-1)
2019/11/26 1件余分にする
{
Alert(Symbol()+“ BUYSTOP Count Over Count=”+Count_Buy+“,”+Comments_Value) ;
return;
}

if(Count_Sel>SellMaxHoldPosition-1 )
{
Alert(Symbol()+ “ SELLSTOP Count Over Count=”+Count_Sel+“,”+Comments_Value) ;
return;
}

No1 証拠金維持率チェック

if1)*100) {
Alert(Symbol()+“ Deposit Minimum %=”,DoubleToStr(AccountEquity()/(AccountEquity()-AccountFreeMargin())*100,2));
Alert(“警告 証拠金少:証拠金維持率=”,DoubleToStr(AccountEquity()/(AccountEquity()-AccountFreeMargin())*100,2));
Print(“警告 証拠金少: 有効証拠金=”+DoubleToStr(AccountEquity(),2)+“,余剰証拠金額=”+DoubleToStr(AccountFreeMargin(),2)+
“,証拠金維持率=”+DoubleToStr(AccountEquity()/(AccountEquity()-AccountFreeMargin())*100,2));
return;
}
======================
 No7 BB OCO 2020/01/27
======================
MagicB=Magic+0;

int ShortMA_PeriodC = 5;
MA短期移動平均線の期間 標準3
PeriodPara=Period();

Comments_Value = OperationPC + Comments+“”+IntegerToString(PeriodPara,2)+“M)”;
BoBa_Para=0;
switch(PeriodPara) {
case 5:
MA_Diff=0.016;
break;
case 15:
MA_Diff=0.026;
break;
case 30:
MA_Diff=0.036;
break;
case 60:
MA_Diff=0.06;
break;
default:
MA_Diff=0.005;
break;
}
2020/01/27 ボリンジャーバンドでOCO
/*
double iBands(
string symbol, 通貨ペア
int timeframe,
時間軸
int period, 平均期間
double deviation,
標準偏差
int bands_shift, バンドシフト
int applied_price,
適用価格
int mode, ラインインデックス
int shift
シフト
);
*/
double Short1= NormalizeDouble(iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,1),4);
double Short2= NormalizeDouble(iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,1),4);
double UeGAK=NormalizeDouble(MathAbs2),4);
double SitaGAK=NormalizeDouble(MathAbs3),4);


Alert(Symbol()+“ Short1=”+Short1+“, Ask=”+Ask+“, UeGAK=”+UeGAK+“,Short2=”+Short2+“,Bid=”+Bid+“, SitaGAK=”+SitaGAK);

if(UeGAK {
BoBa_Para=1;
}
if(SitaGAK {
BoBa_Para=2;
}
Alert(Symbol()+“ Short1=”+Short1+“, Ask=”+Ask+“, UeGAK=”+UeGAK+“,Short2=”+Short2+“,Bid=”+Bid+“, SitaGAK=”+SitaGAK+“, BoBa_Para=”+BoBa_Para);
if( BoBa_Para==0)
{
return;
}


レンジ幅チェック 狭ければ発注2020/01/28


double MA_Array1[5];
double MA_Array2[5];

int HabaWide=0; 0=幅狭い、1=幅広い

2019/11/17 時間足毎に幅変更
switch(PeriodPara) {
case 5:
MA_Diff=0.03;
break;
case 15:
MA_Diff=0.07;
HistryCount=5;
break;
case 30:
MA_Diff=0.08;
break;
case 60:
MA_Diff=0.1;
break;
default:
MA_Diff=0.005;
break;
}

double TopGaku=0;
double LowGaku=999;
for(int i = 0; i
if( High[i] >TopGaku)
{
TopGaku=High[i];
}
if( Low[i] {
LowGaku=Low[i];
}
}
if(MathAbs(TopGaku-LowGaku) {
BoBa_Para=1;
Comments_Value=Comments_Value+“Z”
Alert(Symbol()+“ Narrow=”);

}

—
—————————
保有ポジション数確認
—————————
Count_Buy=0;
Count_Sel=0;

for(int i=0;i {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MagicB || OrderSymbol()!=Symbol()) continue;
— check order type
if(OrderType()==OP_BUYSTOP)
if(OrderType()==OP_BUY)
{
Count_Buy=Count_Buy+1;
}
if(OrderType()==OP_SELLSTOP)
if(OrderType()==OP_SELL)
{
Count_Sel=Count_Sel+1;
}
}
Print(“保有ポジション Count_Buy=”+IntegerToString(Count_Buy,3)+“,Count_Sel=”+IntegerToString(Count_Sel,3));
*
発注 最上限、最下限額チェック
*
売り判定の時、最低設定額を下げたら発注中止。買いは継続。
if(BoBa_Para==2)
{
if(StopLowGaku > Bid)
{
Alert( Symbol()+“ Stop: Low Gaku=”+DoubleToStr(StopLowGaku,2)+“ > Under Bid=”+DoubleToStr(Bid,2));
Print(Symbol()+“No3 Stop 最低設定額を下回った。StopLowGaku=”+DoubleToStr(StopLowGaku,2)+“,Bid=”+DoubleToStr(Bid,2));
return;
}
}
買い判定の時、最高設定額を超えたら発注中止。売りは継続。
if(BoBa_Para==1)
{
if(StopTopGaku < Ask)
{
Alert(Symbol()+“ Stop: Top Gaku=”+DoubleToStr(StopTopGaku,2)+“ < Over Ask=”+DoubleToStr(Ask,2));
Print(Symbol()+“No3 Stop 最高設定額を上回った。StopTopGaku=”+DoubleToStr(StopTopGaku,2)+“,Ask=”+DoubleToStr(Ask,2));
return;
}
}

*
発注処理
*
**
double Ask_B=0,Bid_B=0;
Alert(Symbol()+“ SIGNAL ”+“,BoBa_Para=”+BoBa_Para+“,”+Comments_Value) ;
if(BoBa_Para!=0)
{
if (Count_Buy {
損切りなし
Ask_B=Ask+ShiftGak;
StopLoss=0;
int ticket11=OrderSend(Symbol(),OP_BUYSTOP,BuyLots,Ask_B+(SaShiNeHaba/10)*Pips,Adjusted_Slippage,StopLoss,Ask_B+((TakeProfit+SaShiNeHaba)/10)*Pips,Comments_Value,Magic,StrToTime(HattyuKigen),CLR_NONE);
}

if(Count_Sel {
Bid_B=Bid+ShiftGak;
StopLoss=0;
int ticket12=OrderSend(Symbol(),OP_SELLSTOP,SellLots,Bid_B-(SaShiNeHaba/10)*Pips,3,StopLoss,Bid_B-((TakeProfit+SaShiNeHaba)/10)*Pips,Comments_Value,Magic,StrToTime(HattyuKigen),CLR_NONE);
}

}
}

1)
AccountEquity()/(AccountEquity()-AccountFreeMargin(
2)
Short1-Ask
3)
Short2-Bid