エキスパート: 2MA バニークロスエキスパート - ページ 2 12 新しいコメント Александр Князев 2020.10.01 10:26 #11 うーん、281行目と287行目でコンパイルエラーのinitが失敗しています。その結果、何も実行できない=( Vladimir Karputov 2020.10.01 10:31 #12 Александр Князев:うーん、281行目と287行目でコンパイルエラーのinitが失敗しています。その結果、何も実行できない=( どこで何をダウンロードするか注意してください。今のところ、バージョン1.003は KodoBaseのロシア・パートからダウンロードし、エラーなくコンパイルできている。 取引、自動取引システム、取引戦略のテストに関するフォーラム。 エキスパートアドバイザー:2MAバニークロスエキスパート ウラジーミル・カルプトフ, 2019.05.01 15:17 ヒント:https://www.mql5.com/ja/code/16783 Le Nam 2020.12.06 12:53 #13 cảm ơn bạn về code nhưng nó không hoạt động khi nén lại n ó báo lỗi bạn có thể chỉ tôi cách khắc phục không ? xin cảm ơn Experts: 2MA Bunny Cross Indicators with alerts/signal 記事「初心者からエキスパートへ:ローソク足のプログラミング」についてのディスカッション Vladimir Karputov 2020.12.06 13:07 #14 Le Nam : cảm ơn bạn về code nhưng nó không hoạt động khi nén lại n ó báo lỗi bạn có thể chỉ tôi cách khắc phục không ? xin cảm ơn バージョン1.003は、ロシアのフォーラムから入手できます:https://www.mql5.com/ru/code/16783 Sebastien Pierre Valla 2021.02.06 17:53 #15 こんにちは、 MAの期間を変更するように修正しました。 以下に修正したコードを示します。 //+------------------------------------------------------------------+ //| 2MAバニークロスエキスパート(barabashkakvn版).mq5||バニークロスエキスパート //|著作権 © ロン・トンプソン //|http://ライトパッチ・ドット・コムlightpatch.com/forex/ || ライトパッチ //+------------------------------------------------------------------+ #property copyright "Ron Thompson" #property link "http://www.lightpatch.com/forex" #property version "1.003" //--- #include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> #include <Trade\AccountInfo.mqh> #include <Expert\Money\MoneyFixedMargin.mqh> CPositionInfo m_position; // トレード・ポジション・オブジェクト CTrade m_trade; // 取引オブジェクト CSymbolInfo m_symbol; // シンボル情報オブジェクト CAccountInfo m_account; // アカウント情報ラッパー CMoneyFixedMargin *m_money; //--- 入力パラメータ input double InpLots = 0; // ロット(または "ロット">0かつ "リスク"==0、または "ロット"==0かつ "リスク">0)。 input double Risk = 5; // リスク(または "ロット">0かつ "リスク"==0、または "ロット"==0かつ "リスク">0) input int PeriodMAS=20; // Period of the fast MA input int PeriodMAF=5; input ulong m_magic=319906800; // マジックナンバー //--- ulong m_slippage=10; // スリップ int handle_iMA_5; // iMAインジケータのハンドルを格納する変数。 int handle_iMA_20; // iMAインジケータのハンドルを格納する変数。 //+------------------------------------------------------------------+ //| エキスパート初期化関数| //+------------------------------------------------------------------+ int OnInit() { if(!m_symbol.Name(Symbol())) // シンボル名を設定する return(INIT_FAILED); RefreshRates(); //--- m_trade.SetExpertMagicNumber(m_magic); m_trade.SetMarginMode(); m_trade.SetTypeFillingBySymbol(m_symbol.Name()); m_trade.SetDeviationInPoints(m_slippage); //--- 3桁または5桁のチューニング int digits_adjust=1; if(m_symbol.Digits()==3 || m_symbol.Digits()==5) digits_adjust=10; //--- if(!LotsOrRisk(InpLots,Risk,digits_adjust)) return(INIT_PARAMETERS_INCORRECT); //--- if(m_money!=NULL) delete m_money; m_money=new CMoneyFixedMargin; if(m_money!=NULL) { if(!m_money.Init(GetPointer(m_symbol),Period(),m_symbol.Point()*digits_adjust)) return(INIT_FAILED); m_money.Percent(Risk); } else { Print(__FUNCTION__,", ERROR: Object CMoneyFixedMargin is NULL"); return(INIT_FAILED); } //--- インジケーターiMAのハンドルを作成 handle_iMA_5=iMA(m_symbol.Name(),Period(),PeriodMAF,0,MODE_SMA,PRICE_WEIGHTED); //--- ハンドルが作成されていない場合 if(handle_iMA_5==INVALID_HANDLE) { //--- 失敗を伝え、エラーコードを出力する。 PrintFormat("Failed to create handle of the iMA indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(Period()), GetLastError()); //--- インジケーターは早期に停止する return(INIT_FAILED); } //--- インジケーターiMAのハンドルを作成 handle_iMA_20=iMA(m_symbol.Name(),Period(),PeriodMAS,3,MODE_SMA,PRICE_WEIGHTED); //--- ハンドルが作成されていない場合 if(handle_iMA_20==INVALID_HANDLE) { //--- 失敗を伝え、エラーコードを出力する。 PrintFormat("Failed to create handle of the iMA indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(Period()), GetLastError()); //--- インジケーターは早期に停止する return(INIT_FAILED); } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ |エキスパート初期化関数| //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- if(m_money!=NULL) delete m_money; } //+------------------------------------------------------------------+ //| エキスパート・ティック機能| //+------------------------------------------------------------------+ void OnTick() { //--- 新しいバーが誕生した時だけ働く。 static datetime PrevBars=0; datetime time_0=iTime(m_symbol.Name(),Period(),0); if(time_0==PrevBars) return; PrevBars=time_0; //--- double ArrayMA5[]; ArraySetAsSeries(ArrayMA5,true); double ArrayMA20[]; ArraySetAsSeries(ArrayMA20,true); if(!iMAGetArray(handle_iMA_5,0,3,ArrayMA5) || !iMAGetArray(handle_iMA_20,0,3,ArrayMA20) || !RefreshRates()) { PrevBars=0; return; } //--- bool signal_buy=(ArrayMA5[2]<ArrayMA20[2] && ArrayMA5[1]>ArrayMA20[1]); bool signal_sell=(ArrayMA5[2]>ArrayMA20[2] && ArrayMA5[1]<ArrayMA20[1]); //--- if(signal_buy) { ClosePositions(POSITION_TYPE_SELL); OpenBuy(0.0,0.0); } if(signal_sell) { ClosePositions(POSITION_TYPE_BUY); OpenSell(0.0,0.0); } //--- } //+------------------------------------------------------------------+ | トレード・トランザクション機能| //+------------------------------------------------------------------+ void OnTradeTransaction(const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result) { //--- } //+------------------------------------------------------------------+ //| iMAのバッファの値を配列で取得する。 //+------------------------------------------------------------------+ bool iMAGetArray(const int handle_iMA,const int start_pos,const int count,double &arr_buffer[]) { //--- bool result=true; if(!ArrayIsDynamic(arr_buffer)) { Print("This a no dynamic array!"); return(false); } ArrayFree(arr_buffer); int buffer_num=0; // インジケータ・バッファ番号 //--- エラーコードをリセットする ResetLastError(); //--- iMABuffer配列の一部を、インデックスが0のインジケータ・バッファの値で埋める。 int copied=CopyBuffer(handle_iMA,buffer_num,start_pos,count,arr_buffer); if(copied<0) { //--- コピーに失敗したら、エラーコードを伝える。 PrintFormat("Failed to copy data from the iMA indicator, error code %d",GetLastError()); //--- これは、インジケータが計算されていないとみなされることを意味する。 return(false); } else if(copied<count) { PrintFormat("Moving Average indicator: %d elements from %d were copied",copied,count); DebugBreak(); return(false); } //--- return(result); } //+------------------------------------------------------------------+ //| クローズポジション| //+------------------------------------------------------------------+ void ClosePositions(const ENUM_POSITION_TYPE pos_type) { for(int i=PositionsTotal()-1;i>=0;i--) // 現在のポジションの数を返す if(m_position.SelectByIndex(i)) // プロパティにさらにアクセスするために、インデックスによって位置を選択する。 if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic) if(m_position.PositionType()==pos_type) // ポジションタイプを取得 m_trade.PositionClose(m_position.Ticket()); // 指定したシンボルでポジションを閉じる } //+------------------------------------------------------------------+ //| シンボルのクォートデータを更新する。| //+------------------------------------------------------------------+ bool RefreshRates(void) { //--- リフレッシュ・レート if(!m_symbol.RefreshRates()) { Print("RefreshRates error"); return(false); } //--- "ゼロ "の戻り値からの保護 if(m_symbol.Ask()==0 || m_symbol.Bid()==0) return(false); //--- return(true); } //+------------------------------------------------------------------+ //| ポジションボリュームの正しさをチェックする。 //+------------------------------------------------------------------+ bool CheckVolumeValue(double volume,string &error_description) { //--- 貿易業務の最小許容量 double min_volume=m_symbol.LotsMin(); if(volume<min_volume) { error_description=StringFormat("Volume is less than the minimal allowed SYMBOL_VOLUME_MIN=%.2f",min_volume); return(false); } //--- 取引操作の最大許容量 double max_volume=m_symbol.LotsMax(); if(volume>max_volume) { error_description=StringFormat("Volume is greater than the maximal allowed SYMBOL_VOLUME_MAX=%.2f",max_volume); return(false); } //--- 体積変化の最小ステップを得る double volume_step=m_symbol.LotsStep(); int ratio=(int)MathRound(volume/volume_step); if(MathAbs(ratio*volume_step-volume)>0.0000001) { error_description=StringFormat("Volume is not a multiple of the minimal step SYMBOL_VOLUME_STEP=%.2f, the closest correct volume is %.2f", volume_step,ratio*volume_step); return(false); } error_description="Correct volume value"; return(true); } //+------------------------------------------------------------------+ //| フリー・マージンからの取引に対するロットまたはリスクのパーセンテージ。 //+------------------------------------------------------------------+ bool LotsOrRisk(const double lots,const double risk,const int digits_adjust) { if(lots<0.0 && risk<0.0) { Print(__FUNCTION__,", ERROR: Parameter (\"lots\" or \"risk\") can't be less than zero"); return(false); } if(lots==0.0 && risk==0.0) { Print(__FUNCTION__,", ERROR: Trade is impossible: You have set \"lots\" == 0.0 and \"risk\" == 0.0"); return(false); } if(lots>0.0 && risk>0.0) { Print(__FUNCTION__,", ERROR: Trade is impossible: You have set \"lots\" > 0.0 and \"risk\" > 0.0"); return(false); } if(lots>0.0) { string err_text=""; if(!CheckVolumeValue(lots,err_text)) { Print(__FUNCTION__,", ERROR: ",err_text); return(false); } } else if(risk>0.0) { if(m_money!=NULL) delete m_money; m_money=new CMoneyFixedMargin; if(m_money!=NULL) { if(!m_money.Init(GetPointer(m_symbol),Period(),m_symbol.Point()*digits_adjust)) return(false); m_money.Percent(risk); } else { Print(__FUNCTION__,", ERROR: Object CMoneyFixedMargin is NULL"); return(false); } } //--- return(true); } //+------------------------------------------------------------------+ //| 買いポジション| //+------------------------------------------------------------------+ void OpenBuy(double sl,double tp) { sl=m_symbol.NormalizePrice(sl); tp=m_symbol.NormalizePrice(tp); double check_open_long_lot=0.0; if(Risk>0.0) { check_open_long_lot=m_money.CheckOpenLong(m_symbol.Ask(),sl); Print("sl=",DoubleToString(sl,m_symbol.Digits()), ", CheckOpenLong: ",DoubleToString(check_open_long_lot,2), ", Balance: ", DoubleToString(m_account.Balance(),2), ", Equity: ", DoubleToString(m_account.Equity(),2), ", FreeMargin: ", DoubleToString(m_account.FreeMargin(),2)); if(check_open_long_lot==0.0) { Print(__FUNCTION__,", ERROR: method CheckOpenLong returned the value of \"0.0\""); return; } } else check_open_long_lot=InpLots; //--- 資金不足」エラーを避けるため、OrderSendの前に出来高をチェックする。 double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),check_open_long_lot,m_symbol.Ask(),ORDER_TYPE_BUY); if(check_volume_lot!=0.0) { if(check_volume_lot>=check_open_long_lot) { if(m_trade.Buy(check_open_long_lot,NULL,m_symbol.Ask(),sl,tp)) { if(m_trade.ResultDeal()==0) { Print("#1 Buy -> false. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); PrintResult(m_trade,m_symbol); } else { Print("#2 Buy -> true. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); PrintResult(m_trade,m_symbol); } } else { Print("#3 Buy -> false. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); PrintResult(m_trade,m_symbol); } } else { string text=""; if(Risk>0.0) text="< method CheckOpenLong ("+DoubleToString(check_open_long_lot,2)+")"; else text="< Lots ("+DoubleToString(InpLots,2)+")"; Print(__FUNCTION__,", ERROR: method CheckVolume (",DoubleToString(check_volume_lot,2),") ", text); return; } } else { Print(__FUNCTION__,", ERROR: method CheckVolume returned the value of \"0.0\""); return; } //--- } //+------------------------------------------------------------------+ //| 売りポジションを開く| //+------------------------------------------------------------------+ void OpenSell(double sl,double tp) { sl=m_symbol.NormalizePrice(sl); tp=m_symbol.NormalizePrice(tp); double check_open_short_lot=0.0; if(Risk>0.0) { check_open_short_lot=m_money.CheckOpenShort(m_symbol.Bid(),sl); Print("sl=",DoubleToString(sl,m_symbol.Digits()), ", CheckOpenLong: ",DoubleToString(check_open_short_lot,2), ", Balance: ", DoubleToString(m_account.Balance(),2), ", Equity: ", DoubleToString(m_account.Equity(),2), ", FreeMargin: ", DoubleToString(m_account.FreeMargin(),2)); if(check_open_short_lot==0.0) { Print(__FUNCTION__,", ERROR: method CheckOpenShort returned the value of \"0.0\""); return; } } else check_open_short_lot=InpLots; //--- 資金不足」エラーを避けるため、OrderSendの前に出来高をチェックする。 double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),check_open_short_lot,m_symbol.Bid(),ORDER_TYPE_SELL); if(check_volume_lot!=0.0) { if(check_volume_lot>=check_open_short_lot) { if(m_trade.Sell(check_open_short_lot,NULL,m_symbol.Bid(),sl,tp)) { if(m_trade.ResultDeal()==0) { Print("#1 Sell -> false. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); PrintResult(m_trade,m_symbol); } else { Print("#2 Sell -> true. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); PrintResult(m_trade,m_symbol); } } else { Print("#3 Sell -> false. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); PrintResult(m_trade,m_symbol); } } else { string text=""; if(Risk>0.0) text="< method CheckOpenShort ("+DoubleToString(check_open_short_lot,2)+")"; else text="< Lots ("+DoubleToString(InpLots,2)+")"; Print(__FUNCTION__,", ERROR: method CheckVolume (",DoubleToString(InpLots,2),") ", text); return; } } else { Print(__FUNCTION__,", ERROR: method CheckVolume returned the value of \"0.0\""); return; } //--- } //+------------------------------------------------------------------+ //| CTトレードの結果を表示| //+------------------------------------------------------------------+ void PrintResult(CTrade &trade,CSymbolInfo &symbol) { Print("Code of request result: "+IntegerToString(trade.ResultRetcode())); Print("code of request result: "+trade.ResultRetcodeDescription()); Print("deal ticket: "+IntegerToString(trade.ResultDeal())); Print("order ticket: "+IntegerToString(trade.ResultOrder())); Print("volume of deal or order: "+DoubleToString(trade.ResultVolume(),2)); Print("price, confirmed by broker: "+DoubleToString(trade.ResultPrice(),symbol.Digits())); Print("current bid price: "+DoubleToString(trade.ResultBid(),symbol.Digits())); Print("current ask price: "+DoubleToString(trade.ResultAsk(),symbol.Digits())); Print("broker comment: "+trade.ResultComment()); //int d=0; } //+------------------------------------------------------------------+ 12 新しいコメント 取引の機会を逃しています。 無料取引アプリ 8千を超えるシグナルをコピー 金融ニュースで金融マーケットを探索 新規登録 ログイン スペースを含まないラテン文字 このメールにパスワードが送信されます エラーが発生しました Googleでログイン WebサイトポリシーおよびMQL5.COM利用規約に同意します。 新規登録 MQL5.com WebサイトへのログインにCookieの使用を許可します。 ログインするには、ブラウザで必要な設定を有効にしてください。 ログイン/パスワードをお忘れですか? Googleでログイン
うーん、281行目と287行目でコンパイルエラーのinitが失敗しています。その結果、何も実行できない=(
うーん、281行目と287行目でコンパイルエラーのinitが失敗しています。その結果、何も実行できない=(
どこで何をダウンロードするか注意してください。今のところ、バージョン1.003は KodoBaseのロシア・パートからダウンロードし、エラーなくコンパイルできている。
取引、自動取引システム、取引戦略のテストに関するフォーラム。
エキスパートアドバイザー:2MAバニークロスエキスパート
ウラジーミル・カルプトフ, 2019.05.01 15:17
ヒント:https://www.mql5.com/ja/code/16783
cảm ơn bạn về code
nhưng nó không hoạt động
khi nén lại n ó báo lỗi
bạn có thể chỉ tôi cách khắc phục không ?
xin cảm ơn
cảm ơn bạn về code
nhưng nó không hoạt động
khi nén lại n ó báo lỗi
bạn có thể chỉ tôi cách khắc phục không ?
xin cảm ơn
バージョン1.003は、ロシアのフォーラムから入手できます:https://www.mql5.com/ru/code/16783
こんにちは、
MAの期間を変更するように修正しました。
以下に修正したコードを示します。