externstring s10 = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>";
externstring s11 = ">>> Вход против МА";
externint iMA_Period = 365;
externint iMA_OpenDistance = 60; // как задать диапазон? например 60-85 за его пределами не открывать ордеров
以下はエントリー部分です。
int GetSignal()
{
int Signal = 0;
double iMA_Signal = iMA(Symbol(), 0, iMA_Period, 0, MODE_SMMA, PRICE_CLOSE, 0);
int Ma_Bid_Diff = MathAbs(iMA_Signal - Bid)/vPoint;
if(Ma_Bid_Diff > iMA_OpenDistance && Bid > iMA_Signal) Signal = -1;
if(Ma_Bid_Diff > iMA_OpenDistance && Bid < iMA_Signal) Signal = 1;
return(Signal);
}
//+-------------------------------------------------------------------------------------------------------+ //| エラーコードのデコード機能 string Market_Err_To_Str(int err) { (文字列) /* この関数は、貿易業務のエラーコードのみを対象としています。 switch(err) { case(0): return("エラーなし"); case(1): return("No error, but the result is unknown"); case(2): return("一般的なエラー"); case(3): return("Incorrect parameters"); case(4): return("取引サーバーはビジー状態です"); case(5): return("クライアント端末のバージョンが古い"); case(6): return("No connection to the trade server"); case(7): return("Not enough rights"); case(8): return("Too frequent requests"); case(9): return("Invalid operation disrupting server operation"); case(64): return("Account blocked"); case(65): return("Incorrect account number"); case(128): return("The deadline for the transaction is expired"); case(129): return("Incorrect price"); case(130): return("Incorrect stops"); case(131): return("Incorrect volume"); case(132): return("Market is closed"); case(133): return("取引禁止"); case(134): return("Not enough money to execute the transaction"); case(135): return("The price has changed"); case(136): return("価格なし"); case(137): return("The broker is busy"); case(138): return("新価格"); case(139): return("The order is blocked and is already being processed"); case(140): return("買いのみ許可"); case(141): return("Too many requests"); case(145): return("Modification is not allowed, because the order is too close to the market"); case(146): return("The trading subsystem is busy"); case(147): return("Use of expiry date is prohibited by broker"); case(148): return("未決済注文と保留注文の数がブローカーによって設定された上限に達しました。") case(149): return("ヘッジが禁止されている場合に既存のポジションと反対のポジションを開こうとしました"); case(150): return("Attempting to close position on the symbol in contrary of the FIFO rule");
bool cbm(int magic, int slipage, int type) {。 /* 魔法で閉じる(指定されたタイプの注文を指定されたMagicNumberですべて閉じる) 最大許容スリッページを考慮しています。 close_by_ticket関数を使用します。 */ int n = 0; while (find_orders(magic, type)) for (int i2=OrdersTotal()-1; i2>=0; i2--){ if (!OrderSelect(i2,SELECT_BY_POS,MODE_TRADES)) break;
if ((OrderType()==type) && (OrderMagicNumber()==magic)){ close_by_ticket(オーダーチケット(), slip;) n++; } //end if (((オーダータイプ()==OP_BUY) || (オーダータイプ()==OP_SELL)))&& (OrderMagicNumber()==magic)) } //end for (int i2=OrdersTotal()-1; i2>=0; i2--)
if(n>0) return(true)です。
return(false)です。 } //終了 bool cbm(int magic, int slipage, int type) //| 決算業務について //+-------------------------------------------------------------------------------------------------------+
ありがとうございました。うまくいって、子供のように喜んでいたのですが、アドバイザーが「new」と表示されなくなりました。どこで間違えたのか、教えてください。
はて、元々探していた場所ではなく、間違いを発見。自分では次の仕事に対応できない。
乖離幅(MAからの価格距離)の設定方法を教えてください。
以下はエントリー部分です。
はて、元々探していた場所ではなく、エラーを発見。次の仕事は自分一人ではこなせない。
乖離幅(MAからの価格の距離)を設定する方法を教えてください。
以下、エントリー部分
そして、それに応じて、条件
アドバイザーの生データを正しく(1買い、-1売り)に変更する必要があります。
//+------------------------------------------------------------------+
//| SimpleBars_rob.mq4//| 著作権 © 2010, ENSED Team|電子書籍ストア「BookLive!
//| http://www.ensed.org |
//+------------------------------------------------------------------+
#property copyright"著作権 © 2010, ENSED Team"
#プロパティリンク "http://www.ensed.org"
extern int SL = 50; // ストップロス値(単位:ピップス)
TP = 150; // テイクプロフィット値(ポイント)
extern double Lots = 0.1; // 作業ロット(マイクロロット - 0.01、ミニロット - 0.1、ノーマルロット - 1.0)
extern string Order_Comment = "robot"; // 注文に適用されるコメント
extern int Slipage = 5; // 最大許容スリップレベル(単位:ポイント)
extern int int Magic_Number = 777; // ロボットのマジックオーダー数(「友好的」な取引を区別するため)
extern bool Play_Sound = false; // オープニング時のサウンドの再生:true - 許可、false - 禁止
//--------------------------------------------------------------------------------------------------------------------+
//+ SimpleBarsインジケータのタイムフレームとパラメータの設定
外部 int period = 6;
extern bool useClose = true;
extern int width = 3;
//+ SimpleBarsのタイムフレームとパラメータを調整します。
//--------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//+ トレーリングストップ
extern bool UseTrailing = true; // トレーリングストップのオン/オフ
extern int TrailingStop = 50; // 固定トレーリングストップ・サイズ(pips単位)。
extern int TrailingStep = 1; // トレーリングストップのステップ(ポイント数)
//+ トレーリングストップ
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| プログラムの初期化時に実行されます。
void init() {
if(GlobalVariableCheck("this_bar "+Symbol()+Period())))
GlobalVariableDel("this_bar "+Symbol()+Period())。
を返します。
}
//| プログラムの初期化時に実行される関数です。
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| プログラムの初期化時に実行される関数です。
void deinit() {
if(GlobalVariableCheck("this_bar "+Symbol()+Period())))
GlobalVariableDel("this_bar "+Symbol()+Period())。
を返します。
}
//| プログラムの非初期化時に実行される関数です。
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| 売買シグナルを検索する機能
int fsignals() {
double signal = iCustom(NULL, 0, "SimpleBars", period, 0, 1, 4, 0);
return(0); // 「買い」開始のシグナル
return(1); //オープンセル・シグナル
return(-1); // シグナルなし
} //end int fsignals()
//| 売買シグナルを検索する機能
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| 与えられたバーに対するロボットの作業を追跡する機能
bool this_bar() {
if(
(!GlobalVariableCheck("this_bar "+Symbol()+Period()))
|| (GlobalVariableGet("this_bar "+Symbol()+Period()!=Time[0]))
){
GlobalVariableSet("this_bar "+Symbol()+Period(),Time[0]);
return(false)です。
} else {
return(true)です。
} //end if (.(!GlobalVariableCheck("this_bar "+Symbol()+Period()))
} //end bool this_bar()
//| 与えられたバーに対するロボットの動作の事実を追跡する機能
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| このタイプの注文を検索する機能です。
bool find_orders(int magic=-1, int type=-1, string symb="NULL") {.
/* 与えられたマジックナンバーを持つ、与えられた型のオーダーが、与えられたシンボルで少なくとも1つ見つかれば、trueを返す */。
for (int i=OrdersTotal()-1; i>=0; i--){
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if(((OrderType()==type) || (type==-1)))
&& ((OrderMagicNumber()==magic) || (magic==-1))
&& ((OrderSymbol()==Symbol() || (symb=="NONE")))){
//注文があれば return(true)してループを抜ける
return(true)です。
が壊れる。
} //end if((OrderType()==type) && (OrderMagicNumber()==magic) && (OrderSymbol()==Symbol()))
} //end for (int i2=OrdersTotal()-1; i2>=0; i2--)
return(false); //return false
} //end bool find_orders(int magic, int type)
//| 指定されたタイプの注文を検索する機能 |...
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| 注文のストップロス値を計算する機能です。
double sl(int sl_value, int type, double price=0.0, string symb="NONE", int rmode=1) {。
//type=0→市場購入
//type=1→市場売上
if(symb=="NONE") symb=Symbol();
if(type==0) price=NormalizeDouble(MarketInfo(symb,MODE_ASK),MarketInfo(symb,MODE_DIGITS))です。
if(type==1) price=Normalize Double(MarketInfo(symb,MODE_BID),MarketInfo(symb,MODE_DIGITS));
if(sl_value<=0) return(0);
if(rmode==1){。
if((type==0) || (type==2) || (type==4)) return(MarketInfo(symb,MODE_ASK)-sl_value*MarketInfo(symb,MODE_POINT)); //購入の場合
if((type==1) || (type==3) || (type==5)) return(MarketInfo(symb,MODE_BID)+sl_value*MarketInfo(symb,MODE_POINT)); //販売用
}
if(rmode==2){。
if((type==0) || (type==2) || (type==4)) return(MarketInfo(symb,MODE_BID)-sl_value*MarketInfo(symb,MODE_POINT)); //買いの場合
if((type==1) || (type==3) || (type==5)) return(MarketInfo(symb,MODE_ASK)+sl_value*MarketInfo(symb,MODE_POINT)); //売り出しの場合
}
} //end double sl(int sl_value, int type, double price=0.0, string symb="NONE", int rmode=1)
//| 注文のストップロス値を計算する関数です。
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//|注文の利食い値を計算する関数
double tp(int tp_value, int type, double price=0.0, string symb="NONE") {。
//type=0→成り行き買い
//type=1→市場売上
if(symb=="NONE") symb=Symbol();
if(type==0) price=Normalize Double(MarketInfo(symb,MODE_ASK),MarketInfo(symb,MODE_DIGITS));
if(type==1) price=Normalize Double(MarketInfo(symb,MODE_BID),MarketInfo(symb,MODE_DIGITS));
if(tp_value<=0) return(0);
if((type==0) || (type==2) || (type==4)) return(price+tp_value*MarketInfo(symb,MODE_POINT)); //購入の場合
if((type==1) || (type==3) || (type==5)) return(MarketInfo(symb,MODE_BID)-tp_value*MarketInfo(symb,MODE_POINT)); //販売用
} //end double tp(int tp_value, int type, double price=0.0, string symb="NONE")
//| 注文のテイクプロフィット値を計算する関数です。
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| 注文を開始する機能
void open_positions(int signal, double lot, double price=0.0, string symb="NONE") { .
//シグナル=0→買いのオープンシグナル
//signal=1→売りのオープンシグナル
/* extern */ int Count_Of_Trade_Try=5, Pause_Of_Trade_Try=5;
int i = 0; //ループカウンタ用変数
int err = 0;
if(symb=="NONE") symb=Symbol();
if(signal==0)
price=Normalize Double(MarketInfo(symb,MODE_ASK),MarketInfo(symb,MODE_DIGITS)); //買いの開始価格
if(signal==1)
price=Normalize Double(MarketInfo(symb,MODE_BID),MarketInfo(symb,MODE_DIGITS)); //売りの開始価格
while(i<=Count_Of_Trade_Try) { [1]をクリックします。
注文を開くための // 関数(組み込み)。知覚の便宜のために、パラメータは別の行に配置されています。
int ticket = OrderSend(Symbol(), //symbol)
signal, //オーダータイプ
ロット、//ボリューム
価格, //オープン価格
Slipage, //リクオートの許容レベル
sl(SL,signal), // ストップロスの値
tp(TP,シグナル), //利益確定値取得
Order_Comment, //オーダーコメント
Magic_Number, //マジックナンバー
0, //有効期限(保留中の注文に使用)
CLR_NONE); //チャートに表示される矢印の色 (CLR_NONE - 矢印は描かれません)
if(ticket!=-1) //開封に成功した場合、グラフィックオブジェクトを描画してループを抜ける
が壊れる。
err=GetLastError()です。
if(err!=0) Print("エラー: "+Market_Err_To_Str(err));
i++;
Sleep(Pause_Of_Trade_Try*1000); //エラー発生時、再試行前に一時停止する。
} //end while(i<=count)
} //end void open_positions(int signal, double lot, double price=0.0, string symb="NONE")
//| 注文を開始する機能
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------+
//| エラーコードのデコード機能
string Market_Err_To_Str(int err) { (文字列)
/* この関数は、貿易業務のエラーコードのみを対象としています。
switch(err) {
case(0): return("エラーなし");
case(1): return("No error, but the result is unknown");
case(2): return("一般的なエラー");
case(3): return("Incorrect parameters");
case(4): return("取引サーバーはビジー状態です");
case(5): return("クライアント端末のバージョンが古い");
case(6): return("No connection to the trade server");
case(7): return("Not enough rights");
case(8): return("Too frequent requests");
case(9): return("Invalid operation disrupting server operation");
case(64): return("Account blocked");
case(65): return("Incorrect account number");
case(128): return("The deadline for the transaction is expired");
case(129): return("Incorrect price");
case(130): return("Incorrect stops");
case(131): return("Incorrect volume");
case(132): return("Market is closed");
case(133): return("取引禁止");
case(134): return("Not enough money to execute the transaction");
case(135): return("The price has changed");
case(136): return("価格なし");
case(137): return("The broker is busy");
case(138): return("新価格");
case(139): return("The order is blocked and is already being processed");
case(140): return("買いのみ許可");
case(141): return("Too many requests");
case(145): return("Modification is not allowed, because the order is too close to the market");
case(146): return("The trading subsystem is busy");
case(147): return("Use of expiry date is prohibited by broker");
case(148): return("未決済注文と保留注文の数がブローカーによって設定された上限に達しました。")
case(149): return("ヘッジが禁止されている場合に既存のポジションと反対のポジションを開こうとしました");
case(150): return("Attempting to close position on the symbol in contrary of the FIFO rule");
デフォルト:return("");
} //end switch(err)
} //end string Err_To_Str(int err)
//| エラーコードをデコードする関数
//+-------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------+
//| トランザクションの終了作業
//+----------------------------------------------------------------------------------------------------+
//| 注文番号(チケット)で注文を確定させる機能
bool close_by_ticket(int c_ticket, int slipage) {。
/*
取引番号(チケット)で決済する機能。
成行注文を決済する際に、最大許容スリッページのレベルを考慮する(スリッページ)
*/
/* extern */ int Count_Of_Trade_Try=5, Pause_Of_Trade_Try=5;
int i = 0; //ループカウンタ用変数
int err = 0;
bool ticket = false; //取引終了(不成立)時の変数
double price = 0.0; //取引終了時の価格(成行注文の場合)
if(OrderSelect(c_ticket,SELECT_BY_TICKET,MODE_TRADES)){ //チケットの並び順を選択
if(OrderType()==OP_BUY) price = NormalizeDouble(Bid,Digits); //買いの場合の価格
if(OrderType()==OP_SELL) price = NormalizeDouble(Ask,Digits); //売りの場合の価格
for(i=0;i<=Count_Of_Trade_Try;i++) {
if(OrderType()<=1) //成行注文であれば決済、保留注文であれば削除
ticket=OrderClose(OrderTicket(),OrderLots(),price,slipage,CLR_NONE)とする。
さもなくば
ticket=OrderDelete(OrderTicket())とする。
if(ticket) { //クローズまたは削除が成功した場合 - trueを返してループを抜ける
return(true)です。
が壊れる。
} //終了 if(チケット)
err=GetLastError()です。
if(err!=0) Print("エラー: "+Market_Err_To_Str(err));
Sleep(Pause_Of_Trade_Try*1000); //エラー発生時、再試行前に一時停止する。
} //終了 for(i=0;i<=Count_Of_Trade_Try;i++)
} //終了 if(OrderSelect(c_ticket,SELECT_BY_TICKET,MODE_TRADES))
return(false); //return false
} //end bool close_by_ticket(int c_ticket)
//| 注文番号(チケット)で注文を確定させる機能
//+----------------------------------------------------------------------------------------------------+
bool cbm(int magic, int slipage, int type) {。
/*
魔法で閉じる(指定されたタイプの注文を指定されたMagicNumberですべて閉じる)
最大許容スリッページを考慮しています。
close_by_ticket関数を使用します。
*/
int n = 0;
while (find_orders(magic, type))
for (int i2=OrdersTotal()-1; i2>=0; i2--){
if (!OrderSelect(i2,SELECT_BY_POS,MODE_TRADES)) break;
if ((OrderType()==type) && (OrderMagicNumber()==magic)){
close_by_ticket(オーダーチケット(), slip;)
n++;
} //end if (((オーダータイプ()==OP_BUY) || (オーダータイプ()==OP_SELL)))&& (OrderMagicNumber()==magic))
} //end for (int i2=OrdersTotal()-1; i2>=0; i2--)
if(n>0)
return(true)です。
return(false)です。
} //終了 bool cbm(int magic, int slipage, int type)
//| 決算業務について
//+-------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| トレーリング・ストップ・ロス
void T_SL() {
if(!UseTrailing) return;
int i = 0;
for(i=0; i<OrdersTotal(); i++){
if(!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if(OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic_Number) continue;
if(OrderType()==OP_BUY){
if(NormalizeDouble(Bid-OrderOpenPrice(,Digits))>NormalizeDouble(TrailingStop*Point,Digits))。{
if(NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-(TrailingStop+TrailingStep-1)*Point,Digits))。
OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*Point,Digits), OrderTakeProfit(), 0, CLR_NONE)
} //end if(NormalizeDouble(Bid-OrderOpenPrice(,Digits))>NormalizeDouble(TrailingStop*Point,Digits))とする。
} //end if(OrderType()==OP_BUY)の場合
if(OrderType()==OP_SELL)の場合{。
if(NormalizeDouble(OrderOpenPrice()-Ask,Digits)>NormalizeDouble(TrailingStop*Point,Digits))。{
if(NormalizeDouble(OrderStopLoss(,Digits))>NormalizeDouble(Ask+(TrailingStop+TrailingStep-1)*ポイント,Digits))
OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*Point,Digits), OrderTakeProfit(), 0, CLR_NONE)
} //end if(NormalizeDouble(OrderOpenPrice()-Ask,Digits)>NormalizeDouble(TrailingStop*Point,Digits))とする。
} //end if(オーダータイプ()==OP_SELL)
} //終了 for(i=0; i<OrdersTotal(); i++)
} //end void T_SL()
//| トレーリング・ストップ・ロス
//+-------------------------------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------------------------------+
//| メイン関数
void start() {
int sig = fsignals();
if(!find_orders(Magic_Number)){
if((sig!=-1)){
if(!this_bar()){
open_positions(sig, Lots);
if(Play_Sound)
PlaySound("alert.wav")。
}
} //end if((sig!=-1) && (!this_bar())
} else {
if(sig==0){とする。
if(cbm(Magic_Number, Slipage, 1)){
open_positions(sig, Lots);
if(Play_Sound)
PlaySound("alert.wav")。
} //終了 if(cbm(Magic_Number, Slipage, 1))
} //終了 if(sig==0)
if(sig==1) {
if(cbm(Magic_Number, Slipage, 0)){
open_positions(sig, Lots);
if(Play_Sound)
PlaySound("alert.wav")。
} //終了 if(cbm(Magic_Number, Slipage, 0))
} //end if(sig==1)
T_SL()です。
} //終了 if(!find_orders(Magic_Number))ほか
を返します。
}
//| メイン関数
//+-------------------------------------------------------------------------------------------------------------------+
愛好家の皆さん、こんにちは。ヘルプ-動作していません。 変数の初期化に戸惑ったと思います。頭が回転していますが、間違いは見つかりません。
EAは、ポジションを開く代わりに、Klose(0)の価格で矢印を描画し、閉じる代わりに、クロスを描画して、データ( fExpiration_func(Expiration)、fop_time、cl_time、fop_price、cl_price、ftype)を新しい行に出力する必要があります。
ここでは、確率論は例としてのみ取り上げられています。
そこで問題は、2つの値をどのように返すかである。試してみましたが、エラー
そこで問題は、2つの値をどのように返すかである。試してみましたが、エラー
そこで問題は、2つの値をどのように返すかである。試してみましたが、エラー
変数の使用は試されましたか?もしかしたら、それが役に立つかもしれません。
もしよろしければ、お手伝いください
Expert Advisorにインジケータを使ったトレードを教えるために
BS_Living Now ver #1.mq4 https://www.mql5.com/ru/code/11014#50910
UP= iCustom(Symbol(),NULL, "Now",BQuant,0,0);
DOW= iCustom(Symbol(),NULL, "Now",BQuant,1,0);
if(DOW){OrderSend(Symbol(), OP_SELL, Lot, Bid, Slip, 0, 0, "Forex-Robots.ru SELL", Magic, 0,Red);}{OrderSend(Symbol(), OP_SELL, Lot, Bid, Slip, 0, 0, "Forex-Robots.ru SELL", Magic, 0,Red)
if(UP ){OrderSend(Symbol(), OP_BUY, Lot, Ask, Slip, 0, 0, "Forex-Robots.ru BUY", Magic, 0,Blue);}{OrderSend(Symbol(), OP_BUY, Lot, Ask, Slip, 0, 0, "Forex-Robots.ru BUY", Magic, 0,Blue)
コメント
(
"ⅳプロフィット"。", UP,
"ⅳプロフィット"。", DOW
);
コメントで値を読もうとしたが、常に静的な値になっている。
変数の使用は試されましたか?役に立つかもしれません。
ありがとうございます、うまくいきました。
もしよろしければ、お手伝いください
Expert Advisorにインジケータを使ったトレードを教えるために
BS_Living Now ver #1.mq4 https://www.mql5.com/ru/code/11014#50910