コーディングのヘルプ - ページ 156 1...149150151152153154155156157158159160161162163...786 新しいコメント Mladen Rakic 2013.10.01 18:28 #1551 Marco320: 親愛なるMLaden。次の指標は、私のライブ口座とMarkets.com(CFD)のデモでチャート上に取得することができます。Liquid Marketsのデモでは、チャート上に表示させることができないのでしょうか?Liquidは金融商品のいくつかのオプション(特にMT4の先物)を提供しているので、私はそのプラットフォームでチャート上にそれを持ちたいと思います。私は見つけることができないので、あなたは、この問題を上昇させる問題を見ることができます。 Thx Marco おそらく、そのインディケータがデコンパイルされたインディケータであることが原因でしょう。ビルド500からmataraderはそのような指標をコンパイルするのを防ぎます。 Marco Hinderink 2013.10.01 19:14 #1552 mladen: おそらく、そのインディケータがデコンパイルされたインディケータであることが原因だと思います。ビルド500からmetaraderはそのようなインジケータをコンパイルするのを防ぎます。 MLadenさん、こんにちは。 でも、私が使っているブローカーのMT4プラットフォームは、すべて500バージョンなので、不思議です。 マルコさんへ Chrisstoff 2013.10.02 09:52 #1553 あるEAで、部分的な利食い 機能を使いたいのです。この機能をコーディングしたところ、あるときはうまく動作し、あるときは動作しません。何が問題なのかが分かりませんでした。 MladenまたはMrToolsへ、コードを調べて、どのようにバグを見つけ、部分取得機能を解決することができるか、親切にアドバイスしていただけないでしょうか? //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { int signal; CheckOrders(); int numTrades = GetNumTickets(); signal = CheckSignal(); if (signal == OP_BUY) { OpenBuy(); lasttime = TimeCurrent(); } if (signal == OP_SELL) { OpenSell(); lasttime = TimeCurrent(); } return; } // +----------------------------------------------------------------------------+ // | Order checking function // +----------------------------------------------------------------------------+ void CheckOrders() { int typ,i,cnt,ticket; int Mv1 = 0; int SL1 = 0; int Mv2 = 0; int SL2 = 0; int Mv3 = 0; int id; double PipDist, CLots, buy_nextTP, sell_nextTP; cnt = OrdersTotal(); for (i=cnt-1; i>=0; i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { typ = OrderType(); // if (typ == OP_BUY) { if (TrailingStopLoss) { if (AdjTrailOnAllOrders(2, buy_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false) Alert("Scalp_RSI: Modifying BUY order failed!"); } PipDist = (NormalizeDouble(Bid,Digits) - NormalizeDouble(OrderOpenPrice(),Digits)); PipDist = MathFloor(PipDist/myPoint); } if (typ == OP_SELL) { if(TrailingStopLoss) { if (AdjTrailOnAllOrders(2, sell_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false) Alert("Scalp_RSI: Modifying SELL order failed!"); } PipDist = (NormalizeDouble(OrderOpenPrice(),Digits) - NormalizeDouble(Ask,Digits)); PipDist = MathFloor(PipDist/myPoint); } if (TakePartialProfit == true && PartCloseLots > 0) { if (UseMoneyMgmt != 1) Lotsi = Lots; CLots = NormalizeDouble(Lotsi * PartCloseLots/100,Decimals); // Computing lots to close if (CLots < MarketInfo(Symbol(), MODE_MINLOT)) CLots = MarketInfo(Symbol(), MODE_MINLOT); PartialTP(PipDist,OrderTicket(),CLots); } } } } } //+------------------------------------------------------------------+ //| PartialTP - i.e. TakePartialProfit function //+------------------------------------------------------------------+ void PartialTP(int pipsval, int ticket, double CLots) // { int gle; int loopcount = 0; string bER; string myInfo = "PartialTP"; if(OrderSelect(ticket, SELECT_BY_TICKET)==true) { if (OrderType() == OP_BUY) { if ((pipsval >= buy_PartialTP) && (pipsval < buy_TakeProfit+1)) // { while(true) { OrderClose(ticket,CLots,Bid,3,YellowGreen); gle=GetLastError(); bER=" error="+gle+" "+ErrorDescription(gle); if(gle==0 || gle==1) { logwrite(TradeComment,"CLOSE BUY "+myInfo+ " " + CLots + " at Bid= " + Bid); buy_PartialTP = buy_TakeProfit+1; // break; } else { logwrite(TradeComment,"---ERROR--- CLOSE BUY "+myInfo+bER+ " " + CLots + " at Bid= " + Bid); RefreshRates(); Sleep(500); } loopcount++; if(loopcount>maxloop) { logwrite(TradeComment,"---ERROR--- Giving up on closing BUY order"); return(gle); } } } } if (OrderType() == OP_SELL) // { if ((pipsval >= sell_PartialTP) && (pipsval < sell_TakeProfit)) // { while(true) { OrderClose(ticket,CLots,Ask,3,YellowGreen); gle=GetLastError(); bER=" error="+gle+" "+ErrorDescription(gle); if(gle==0 || gle==1) { logwrite(TradeComment,"CLOSE SELL "+myInfo+ " " + CLots + " at Ask= " + Ask); sell_PartialTP = sell_TakeProfit; // break; } else { logwrite(TradeComment,"---ERROR--- CLOSE SELL "+myInfo+bER+ " " + CLots + " at Ask= " + Ask); RefreshRates(); Sleep(500); } loopcount++; if(loopcount>maxloop) { logwrite(TradeComment,"---ERROR--- Giving up on closing SELL order"); return(gle); } } } } } else { gle=GetLastError(); bER=" Error="+gle+" "+ErrorDescription(gle); if (gle != 0 || gle!=1) { logwrite(TradeComment,"---ERROR--- in selecting order in PartialTP function "+bER); } } } //+------------------------------------------------------------------+ //| Get number of open trades //+------------------------------------------------------------------+ int GetNumTickets() { int i; int typ; numTickets = 0; for (i = OrdersTotal()-1; i >= 0; i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { typ = OrderType(); if (typ == OP_BUY || typ == OP_SELL) { numTickets ++; } } } } return (numTickets); } //+------------------------------------------------------------------+ //| Get signal //+------------------------------------------------------------------+ int CheckSignal() { return (SignalScalp()); } //+------------------------------------------------------------------+ //| Get scalp signal //+------------------------------------------------------------------+ int SignalScalp() { int signal=6; // if (enable_buy){ // Buy-Condition { signal = OP_BUY; } } // // if (enable_sell){ // Sell-Condition { signal = OP_SELL; } } // // // return(signal); } //----- // +----------------------------------------------------------------------------+ // | Buy Order // +----------------------------------------------------------------------------+ void OpenBuy() { int gle = 0; int ticket = 0; double SL = 0; double TP = 0; double LotsB = Lots; //GetLots(); int loopcount = 0; while(true) { ticket=OrderSend(Symbol(),OP_BUY,LotsB,Ask,Slippage,0,0,TradeComment,Magic,White); } } // +----------------------------------------------------------------------------+ // | Sell Order // +----------------------------------------------------------------------------+ void OpenSell() { int gle = 0; int ticket = 0; double SL = 0; double TP = 0; double LotsS = Lots; int loopcount = 0; while(true) { ticket=OrderSend(Symbol(),OP_SELL,LotsS,Bid,Slippage,0,0,TradeComment,Magic,Red); } } bool AdjTrailOnAllOrders( int TrailType, int TrailPips, int Magic, int Direction, int FirstMove, int FirstStopLoss, int SecondMove, int SecondStopLoss, int ThirdMove) { double retValue; return(retValue); } //+------------------------------------------------------------------+ //| SetComment function //+------------------------------------------------------------------+ void SetComment(string s) { TradeComment = s; } // +----------------------------------------------------------------------------+ // | Pip setting // +----------------------------------------------------------------------------+ double SetPoint() { double mPoint; return(mPoint); } // +----------------------------------------------------------------------------+ // | Log write function // +----------------------------------------------------------------------------+ void logwrite (string filename, string mydata) { int myhandle; } Coding help EAが複数のペアで実行されない、助けが必要 どんな新人の質問でも、フォーラムを乱雑にしないように。プロフェッショナルは、通り過ぎないでください。Nowhere without you - Mladen Rakic 2013.10.02 10:44 #1554 chrisstoff: あるEAで、パーシャルテイクプロフィット機能を使いたいと考えています。この関数をコード化したところ、うまく動くときと動かないときがあります。何が問題なのかが分かりませんでした。MladenまたはMrToolsへ、コードを調べて、どのようにバグを見つけ、部分的に取る関数を解決できるか、親切にアドバイスしていただけないでしょうか? //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { int signal; CheckOrders(); int numTrades = GetNumTickets(); signal = CheckSignal(); if (signal == OP_BUY) { OpenBuy(); lasttime = TimeCurrent(); } if (signal == OP_SELL) { OpenSell(); lasttime = TimeCurrent(); } return; } // +----------------------------------------------------------------------------+ // | Order checking function // +----------------------------------------------------------------------------+ void CheckOrders() { int typ,i,cnt,ticket; int Mv1 = 0; int SL1 = 0; int Mv2 = 0; int SL2 = 0; int Mv3 = 0; int id; double PipDist, CLots, buy_nextTP, sell_nextTP; cnt = OrdersTotal(); for (i=cnt-1; i>=0; i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { typ = OrderType(); // if (typ == OP_BUY) { if (TrailingStopLoss) { if (AdjTrailOnAllOrders(2, buy_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false) Alert("Scalp_RSI: Modifying BUY order failed!"); } PipDist = (NormalizeDouble(Bid,Digits) - NormalizeDouble(OrderOpenPrice(),Digits)); PipDist = MathFloor(PipDist/myPoint); } if (typ == OP_SELL) { if(TrailingStopLoss) { if (AdjTrailOnAllOrders(2, sell_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false) Alert("Scalp_RSI: Modifying SELL order failed!"); } PipDist = (NormalizeDouble(OrderOpenPrice(),Digits) - NormalizeDouble(Ask,Digits)); PipDist = MathFloor(PipDist/myPoint); } if (TakePartialProfit == true && PartCloseLots > 0) { if (UseMoneyMgmt != 1) Lotsi = Lots; CLots = NormalizeDouble(Lotsi * PartCloseLots/100,Decimals); // Computing lots to close if (CLots < MarketInfo(Symbol(), MODE_MINLOT)) CLots = MarketInfo(Symbol(), MODE_MINLOT); PartialTP(PipDist,OrderTicket(),CLots); } } } } } //+------------------------------------------------------------------+ //| PartialTP - i.e. TakePartialProfit function //+------------------------------------------------------------------+ void PartialTP(int pipsval, int ticket, double CLots) // { int gle; int loopcount = 0; string bER; string myInfo = "PartialTP"; if(OrderSelect(ticket, SELECT_BY_TICKET)==true) { if (OrderType() == OP_BUY) { if ((pipsval >= buy_PartialTP) && (pipsval < buy_TakeProfit+1)) // { while(true) { OrderClose(ticket,CLots,Bid,3,YellowGreen); gle=GetLastError(); bER=" error="+gle+" "+ErrorDescription(gle); if(gle==0 || gle==1) { logwrite(TradeComment,"CLOSE BUY "+myInfo+ " " + CLots + " at Bid= " + Bid); buy_PartialTP = buy_TakeProfit+1; // break; } else { logwrite(TradeComment,"---ERROR--- CLOSE BUY "+myInfo+bER+ " " + CLots + " at Bid= " + Bid); RefreshRates(); Sleep(500); } loopcount++; if(loopcount>maxloop) { logwrite(TradeComment,"---ERROR--- Giving up on closing BUY order"); return(gle); } } } } if (OrderType() == OP_SELL) // { if ((pipsval >= sell_PartialTP) && (pipsval < sell_TakeProfit)) // { while(true) { OrderClose(ticket,CLots,Ask,3,YellowGreen); gle=GetLastError(); bER=" error="+gle+" "+ErrorDescription(gle); if(gle==0 || gle==1) { logwrite(TradeComment,"CLOSE SELL "+myInfo+ " " + CLots + " at Ask= " + Ask); sell_PartialTP = sell_TakeProfit; // break; } else { logwrite(TradeComment,"---ERROR--- CLOSE SELL "+myInfo+bER+ " " + CLots + " at Ask= " + Ask); RefreshRates(); Sleep(500); } loopcount++; if(loopcount>maxloop) { logwrite(TradeComment,"---ERROR--- Giving up on closing SELL order"); return(gle); } } } } } else { gle=GetLastError(); bER=" Error="+gle+" "+ErrorDescription(gle); if (gle != 0 || gle!=1) { logwrite(TradeComment,"---ERROR--- in selecting order in PartialTP function "+bER); } } } //+------------------------------------------------------------------+ //| Get number of open trades //+------------------------------------------------------------------+ int GetNumTickets() { int i; int typ; numTickets = 0; for (i = OrdersTotal()-1; i >= 0; i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { typ = OrderType(); if (typ == OP_BUY || typ == OP_SELL) { numTickets ++; } } } } return (numTickets); } //+------------------------------------------------------------------+ //| Get signal //+------------------------------------------------------------------+ int CheckSignal() { return (SignalScalp()); } //+------------------------------------------------------------------+ //| Get scalp signal //+------------------------------------------------------------------+ int SignalScalp() { int signal=6; // if (enable_buy){ // Buy-Condition { signal = OP_BUY; } } // // if (enable_sell){ // Sell-Condition { signal = OP_SELL; } } // // // return(signal); } //----- // +----------------------------------------------------------------------------+ // | Buy Order // +----------------------------------------------------------------------------+ void OpenBuy() { int gle = 0; int ticket = 0; double SL = 0; double TP = 0; double LotsB = Lots; //GetLots(); int loopcount = 0; while(true) { ticket=OrderSend(Symbol(),OP_BUY,LotsB,Ask,Slippage,0,0,TradeComment,Magic,White); } } // +----------------------------------------------------------------------------+ // | Sell Order // +----------------------------------------------------------------------------+ void OpenSell() { int gle = 0; int ticket = 0; double SL = 0; double TP = 0; double LotsS = Lots; int loopcount = 0; while(true) { ticket=OrderSend(Symbol(),OP_SELL,LotsS,Bid,Slippage,0,0,TradeComment,Magic,Red); } } bool AdjTrailOnAllOrders( int TrailType, int TrailPips, int Magic, int Direction, int FirstMove, int FirstStopLoss, int SecondMove, int SecondStopLoss, int ThirdMove) { double retValue; return(retValue); } void SetComment(string s) { TradeComment = s; } double SetPoint() { double mPoint; return(mPoint); } void logwrite (string filename, string mydata) { int myhandle; } クリストフ Decimals "変数にどのような値を使用しているかはわかりませんが、おそらくそれが問題の原因でしょう。注文の結果は、ロットステップの値にも従わなければなりません(意味:ロットステップが例えば0.1である場合、あなたは0.11ロットをクローズしようとすることはできません)。成功しない部分的なクローズの後の最後のエラーは 何であるかを確認してください(あなたは、単に次のように行く行の後にコメントを追加することによって、それを行うことができます。 bER=" error="+gle+" "+ErrorDescription(gle); if (gle>1) Comment(bER); コード内のlogwrite関数が動作しないので Chrisstoff 2013.10.02 11:14 #1555 ムラデンです。 ご返信ありがとうございます。 さて、1つの投稿が10,000文字以上になる可能性はないので、コードを短くしました。で、元のコードでは以下のようにinit()の中にDecimalsという変数があります。 LotStep = MarketInfo(Symbol(),MODE_LOTSTEP); if(LotStep == 0.01) {Decimals = 2;} if(LotStep == 0.1) {Decimals = 1;} if(LotStep == 1) {Decimals = 0;}[/PHP] Yes, logwrite function is not functionable in the code posted, also because of the shortening. Normally it looks like: [PHP] void logwrite (string filename, string mydata) { int myhandle; string wcalend=TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS); Print(mydata+" "+wcalend); if(IsTesting()) return(0); myhandle=FileOpen(Symbol()+"_"+filename, FILE_CSV|FILE_WRITE|FILE_READ, ";"); if(myhandle>0) { FileSeek(myhandle,0,SEEK_END); FileWrite(myhandle, mydata+" "+wcalend); FileClose(myhandle); } } ですので、Decimals変数が原因で問題が浮上することはないと思います。 Coding help コーディングの方法は? Problem with AccountMargin() Mladen Rakic 2013.10.02 11:22 #1556 chrisstoff: Mladenご返信ありがとうございます。 さて、1万文字以上の投稿はありえないので、コードを短くしました。で、元のコードではDecimals変数はinit()の中に以下のように入っています。 LotStep = MarketInfo(Symbol(),MODE_LOTSTEP); if(LotStep == 0.01) {Decimals = 2;} if(LotStep == 0.1) {Decimals = 1;} if(LotStep == 1) {Decimals = 0;}[/PHP] Yes, logwrite function is not functionable in the code posted, also because of the shortening. Normally it looks like: [PHP] void logwrite (string filename, string mydata) { int myhandle; string wcalend=TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS); Print(mydata+" "+wcalend); if(IsTesting()) return(0); myhandle=FileOpen(Symbol()+"_"+filename, FILE_CSV|FILE_WRITE|FILE_READ, ";"); if(myhandle>0) { FileSeek(myhandle,0,SEEK_END); FileWrite(myhandle, mydata+" "+wcalend); FileClose(myhandle); } } というわけで、Decimals変数が原因で問題が発生することはないと思います。 クリストフ この方法でDecimals変数は問題ないはずです いずれにせよ、注文(部分)決済に失敗した場合のエラーコードを 確認してみてください。 Hock 2013.10.02 11:35 #1557 mladen: マジックナンバーを使用していないようなので、マジックナンバーや記号は関係ないという前提です。その場合、まず、すでにオープンしている注文があるかどうかを確認します - このように。if (OrdersTotal()<1) { ticket=OrderSend(Symbol(), OP_BUY, lots, Ask, 3, 0, 0); stop=(Ask-stopsize*Point); prof=(Ask+profsize*Point); OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Blue); } もし、マジックナンバーとシンボルチェックを使うのであれば、指定されたシンボルと/またはマジックナンバーに対してオープンされた注文をカウントする関数を作るのがベストでしょう。 mladenさんありがとうございます。 if (OrdersTotal()<1) で解決しました。 合計で1つ注文できるのですが、各ペアの通貨を開くことができるようにしたいのです。 誤解を招くようで申し訳ありません。 しかし、私が言いたいのは、各ペアで1つの注文とストップを実行 するということです。例 今、私はEURUSDで注文を開き、1つの注文を実行 します。その後、他の通貨も同時に開くことができ、1つの注文を実行 します。 私の拙い英語で申し訳ありません。 ----------------------------------------------------------------- ありがとうございます。 Mladen Rakic 2013.10.02 11:48 #1558 hock87: mladenさん、ありがとうございます。もし(OrdersTotal()<1) これは私の問題を解決しました。 合計で1つ注文できるのですが、各ペアの通貨を開くことができるようにしたいのです。 誤解を招いたようで申し訳ない。 しかし、私が言いたいのは、各ペアで1つの注文と停止を実行 することです。例 今、私はEURUSDで注文を開き、1つの注文を実行 します。その後、他の通貨も同時に開くことができ、1つの注文を実行 します。 私の拙い英語で申し訳ありません。 ----------------------------------------------------------------- ありがとうございます。 hock87 これを追加してください。 int TotalOrders = 0; for (int i=0; i <= OrdersTotal(); i++) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if (OrderSymbol() == Symbol()) TotalOrders++; } の前に、if (OrdersTotal()<1)の 行を追加し、その行をif (TotalOrders<1) に置き換えてください。そうすれば、1つのシンボルにつき1つのオープンオーダーだけが許可されます。 Hock 2013.10.02 13:51 #1559 mladenさん、どうもありがとうございました。 今、試してみます。 Mladen Rakic 2013.10.02 13:53 #1560 hock87: ありがとうmladen。もし(OrdersTotal()<1) これは私の問題を解決しました。 合計で1つ注文できるのですが、各ペアの通貨を開くことができるようにしたいのです。 誤解を招いたようで申し訳ない。 しかし、私が言いたいのは、各ペアで1つの注文と停止を実行 することです。例 今、私はEURUSDで注文を開き、1つの注文を実行 します。その後、他の通貨も同時に開くことができ、1つの注文を実行 します。 私の拙い英語で申し訳ありません。 ----------------------------------------------------------------- ありがとうございます。 hock87 その問題の解決策については、あなたの投稿の上の投稿をお読みください。 そのための完全なコードは次のとおりです。 int TotalOrders = 0; for (int i=0; i <= OrdersTotal(); i++) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if (OrderSymbol() == Symbol()) TotalOrders++; } if (TotalOrders<1) { ticket=OrderSend(Symbol(), OP_BUY, lots, Ask, 3, 0, 0); stop=(Ask-stopsize*Point); prof=(Ask+profsize*Point); OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Blue); } Coding help Basic questions ... [ARCHIVE] Any rookie question, 1...149150151152153154155156157158159160161162163...786 新しいコメント 取引の機会を逃しています。 無料取引アプリ 8千を超えるシグナルをコピー 金融ニュースで金融マーケットを探索 新規登録 ログイン スペースを含まないラテン文字 このメールにパスワードが送信されます エラーが発生しました Googleでログイン WebサイトポリシーおよびMQL5.COM利用規約に同意します。 新規登録 MQL5.com WebサイトへのログインにCookieの使用を許可します。 ログインするには、ブラウザで必要な設定を有効にしてください。 ログイン/パスワードをお忘れですか? Googleでログイン
親愛なるMLaden。
次の指標は、私のライブ口座とMarkets.com(CFD)のデモでチャート上に取得することができます。Liquid Marketsのデモでは、チャート上に表示させることができないのでしょうか?Liquidは金融商品のいくつかのオプション(特にMT4の先物)を提供しているので、私はそのプラットフォームでチャート上にそれを持ちたいと思います。私は見つけることができないので、あなたは、この問題を上昇させる問題を見ることができます。
Thx Marcoおそらく、そのインディケータがデコンパイルされたインディケータであることが原因でしょう。ビルド500からmataraderはそのような指標をコンパイルするのを防ぎます。
おそらく、そのインディケータがデコンパイルされたインディケータであることが原因だと思います。ビルド500からmetaraderはそのようなインジケータをコンパイルするのを防ぎます。
MLadenさん、こんにちは。
でも、私が使っているブローカーのMT4プラットフォームは、すべて500バージョンなので、不思議です。
マルコさんへ
あるEAで、部分的な利食い 機能を使いたいのです。この機能をコーディングしたところ、あるときはうまく動作し、あるときは動作しません。何が問題なのかが分かりませんでした。
MladenまたはMrToolsへ、コードを調べて、どのようにバグを見つけ、部分取得機能を解決することができるか、親切にアドバイスしていただけないでしょうか?
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int signal;
CheckOrders();
int numTrades = GetNumTickets();
signal = CheckSignal();
if (signal == OP_BUY)
{
OpenBuy();
lasttime = TimeCurrent();
}
if (signal == OP_SELL)
{
OpenSell();
lasttime = TimeCurrent();
}
return;
}
// +----------------------------------------------------------------------------+
// | Order checking function
// +----------------------------------------------------------------------------+
void CheckOrders()
{
int typ,i,cnt,ticket;
int Mv1 = 0;
int SL1 = 0;
int Mv2 = 0;
int SL2 = 0;
int Mv3 = 0;
int id;
double PipDist, CLots, buy_nextTP, sell_nextTP;
cnt = OrdersTotal();
for (i=cnt-1; i>=0; i--)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
typ = OrderType();
//
if (typ == OP_BUY)
{
if (TrailingStopLoss)
{
if (AdjTrailOnAllOrders(2, buy_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false)
Alert("Scalp_RSI: Modifying BUY order failed!");
}
PipDist = (NormalizeDouble(Bid,Digits) - NormalizeDouble(OrderOpenPrice(),Digits));
PipDist = MathFloor(PipDist/myPoint);
}
if (typ == OP_SELL)
{
if(TrailingStopLoss)
{
if (AdjTrailOnAllOrders(2, sell_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false)
Alert("Scalp_RSI: Modifying SELL order failed!");
}
PipDist = (NormalizeDouble(OrderOpenPrice(),Digits) - NormalizeDouble(Ask,Digits));
PipDist = MathFloor(PipDist/myPoint);
}
if (TakePartialProfit == true && PartCloseLots > 0)
{
if (UseMoneyMgmt != 1) Lotsi = Lots;
CLots = NormalizeDouble(Lotsi * PartCloseLots/100,Decimals); // Computing lots to close
if (CLots < MarketInfo(Symbol(), MODE_MINLOT))
CLots = MarketInfo(Symbol(), MODE_MINLOT);
PartialTP(PipDist,OrderTicket(),CLots);
}
}
}
}
}
//+------------------------------------------------------------------+
//| PartialTP - i.e. TakePartialProfit function
//+------------------------------------------------------------------+
void PartialTP(int pipsval, int ticket, double CLots) //
{
int gle;
int loopcount = 0;
string bER;
string myInfo = "PartialTP";
if(OrderSelect(ticket, SELECT_BY_TICKET)==true)
{
if (OrderType() == OP_BUY)
{
if ((pipsval >= buy_PartialTP) && (pipsval < buy_TakeProfit+1)) //
{
while(true)
{
OrderClose(ticket,CLots,Bid,3,YellowGreen);
gle=GetLastError();
bER=" error="+gle+" "+ErrorDescription(gle);
if(gle==0 || gle==1)
{
logwrite(TradeComment,"CLOSE BUY "+myInfo+ " " + CLots + " at Bid= " + Bid);
buy_PartialTP = buy_TakeProfit+1; //
break;
}
else
{
logwrite(TradeComment,"---ERROR--- CLOSE BUY "+myInfo+bER+ " " + CLots + " at Bid= " + Bid);
RefreshRates();
Sleep(500);
}
loopcount++;
if(loopcount>maxloop)
{
logwrite(TradeComment,"---ERROR--- Giving up on closing BUY order");
return(gle);
}
}
}
}
if (OrderType() == OP_SELL) //
{
if ((pipsval >= sell_PartialTP) && (pipsval < sell_TakeProfit)) //
{
while(true)
{
OrderClose(ticket,CLots,Ask,3,YellowGreen);
gle=GetLastError();
bER=" error="+gle+" "+ErrorDescription(gle);
if(gle==0 || gle==1)
{
logwrite(TradeComment,"CLOSE SELL "+myInfo+ " " + CLots + " at Ask= " + Ask);
sell_PartialTP = sell_TakeProfit; //
break;
}
else
{
logwrite(TradeComment,"---ERROR--- CLOSE SELL "+myInfo+bER+ " " + CLots + " at Ask= " + Ask);
RefreshRates();
Sleep(500);
}
loopcount++;
if(loopcount>maxloop)
{
logwrite(TradeComment,"---ERROR--- Giving up on closing SELL order");
return(gle);
}
}
}
}
} else {
gle=GetLastError();
bER=" Error="+gle+" "+ErrorDescription(gle);
if (gle != 0 || gle!=1)
{
logwrite(TradeComment,"---ERROR--- in selecting order in PartialTP function "+bER);
}
}
}
//+------------------------------------------------------------------+
//| Get number of open trades
//+------------------------------------------------------------------+
int GetNumTickets()
{
int i;
int typ;
numTickets = 0;
for (i = OrdersTotal()-1; i >= 0; i--)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
typ = OrderType();
if (typ == OP_BUY || typ == OP_SELL)
{
numTickets ++;
}
}
}
}
return (numTickets);
}
//+------------------------------------------------------------------+
//| Get signal
//+------------------------------------------------------------------+
int CheckSignal()
{
return (SignalScalp());
}
//+------------------------------------------------------------------+
//| Get scalp signal
//+------------------------------------------------------------------+
int SignalScalp()
{
int signal=6; //
if (enable_buy){
// Buy-Condition
{
signal = OP_BUY;
}
}
//
//
if (enable_sell){
// Sell-Condition
{
signal = OP_SELL;
}
}
//
//
//
return(signal);
}
//-----
// +----------------------------------------------------------------------------+
// | Buy Order
// +----------------------------------------------------------------------------+
void OpenBuy()
{
int gle = 0;
int ticket = 0;
double SL = 0;
double TP = 0;
double LotsB = Lots; //GetLots();
int loopcount = 0;
while(true)
{
ticket=OrderSend(Symbol(),OP_BUY,LotsB,Ask,Slippage,0,0,TradeComment,Magic,White);
}
}
// +----------------------------------------------------------------------------+
// | Sell Order
// +----------------------------------------------------------------------------+
void OpenSell()
{
int gle = 0;
int ticket = 0;
double SL = 0;
double TP = 0;
double LotsS = Lots;
int loopcount = 0;
while(true)
{
ticket=OrderSend(Symbol(),OP_SELL,LotsS,Bid,Slippage,0,0,TradeComment,Magic,Red);
}
}
bool AdjTrailOnAllOrders(
int TrailType,
int TrailPips,
int Magic,
int Direction,
int FirstMove,
int FirstStopLoss,
int SecondMove,
int SecondStopLoss,
int ThirdMove)
{
double retValue;
return(retValue);
}
//+------------------------------------------------------------------+
//| SetComment function
//+------------------------------------------------------------------+
void SetComment(string s) { TradeComment = s; }
// +----------------------------------------------------------------------------+
// | Pip setting
// +----------------------------------------------------------------------------+
double SetPoint()
{
double mPoint;
return(mPoint);
}
// +----------------------------------------------------------------------------+
// | Log write function
// +----------------------------------------------------------------------------+
void logwrite (string filename, string mydata)
{
int myhandle;
}
あるEAで、パーシャルテイクプロフィット機能を使いたいと考えています。この関数をコード化したところ、うまく動くときと動かないときがあります。何が問題なのかが分かりませんでした。
MladenまたはMrToolsへ、コードを調べて、どのようにバグを見つけ、部分的に取る関数を解決できるか、親切にアドバイスしていただけないでしょうか?
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int signal;
CheckOrders();
int numTrades = GetNumTickets();
signal = CheckSignal();
if (signal == OP_BUY)
{
OpenBuy();
lasttime = TimeCurrent();
}
if (signal == OP_SELL)
{
OpenSell();
lasttime = TimeCurrent();
}
return;
}
// +----------------------------------------------------------------------------+
// | Order checking function
// +----------------------------------------------------------------------------+
void CheckOrders()
{
int typ,i,cnt,ticket;
int Mv1 = 0;
int SL1 = 0;
int Mv2 = 0;
int SL2 = 0;
int Mv3 = 0;
int id;
double PipDist, CLots, buy_nextTP, sell_nextTP;
cnt = OrdersTotal();
for (i=cnt-1; i>=0; i--)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
typ = OrderType();
//
if (typ == OP_BUY)
{
if (TrailingStopLoss)
{
if (AdjTrailOnAllOrders(2, buy_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false)
Alert("Scalp_RSI: Modifying BUY order failed!");
}
PipDist = (NormalizeDouble(Bid,Digits) - NormalizeDouble(OrderOpenPrice(),Digits));
PipDist = MathFloor(PipDist/myPoint);
}
if (typ == OP_SELL)
{
if(TrailingStopLoss)
{
if (AdjTrailOnAllOrders(2, sell_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false)
Alert("Scalp_RSI: Modifying SELL order failed!");
}
PipDist = (NormalizeDouble(OrderOpenPrice(),Digits) - NormalizeDouble(Ask,Digits));
PipDist = MathFloor(PipDist/myPoint);
}
if (TakePartialProfit == true && PartCloseLots > 0)
{
if (UseMoneyMgmt != 1) Lotsi = Lots;
CLots = NormalizeDouble(Lotsi * PartCloseLots/100,Decimals); // Computing lots to close
if (CLots < MarketInfo(Symbol(), MODE_MINLOT))
CLots = MarketInfo(Symbol(), MODE_MINLOT);
PartialTP(PipDist,OrderTicket(),CLots);
}
}
}
}
}
//+------------------------------------------------------------------+
//| PartialTP - i.e. TakePartialProfit function
//+------------------------------------------------------------------+
void PartialTP(int pipsval, int ticket, double CLots) //
{
int gle;
int loopcount = 0;
string bER;
string myInfo = "PartialTP";
if(OrderSelect(ticket, SELECT_BY_TICKET)==true)
{
if (OrderType() == OP_BUY)
{
if ((pipsval >= buy_PartialTP) && (pipsval < buy_TakeProfit+1)) //
{
while(true)
{
OrderClose(ticket,CLots,Bid,3,YellowGreen);
gle=GetLastError();
bER=" error="+gle+" "+ErrorDescription(gle);
if(gle==0 || gle==1)
{
logwrite(TradeComment,"CLOSE BUY "+myInfo+ " " + CLots + " at Bid= " + Bid);
buy_PartialTP = buy_TakeProfit+1; //
break;
}
else
{
logwrite(TradeComment,"---ERROR--- CLOSE BUY "+myInfo+bER+ " " + CLots + " at Bid= " + Bid);
RefreshRates();
Sleep(500);
}
loopcount++;
if(loopcount>maxloop)
{
logwrite(TradeComment,"---ERROR--- Giving up on closing BUY order");
return(gle);
}
}
}
}
if (OrderType() == OP_SELL) //
{
if ((pipsval >= sell_PartialTP) && (pipsval < sell_TakeProfit)) //
{
while(true)
{
OrderClose(ticket,CLots,Ask,3,YellowGreen);
gle=GetLastError();
bER=" error="+gle+" "+ErrorDescription(gle);
if(gle==0 || gle==1)
{
logwrite(TradeComment,"CLOSE SELL "+myInfo+ " " + CLots + " at Ask= " + Ask);
sell_PartialTP = sell_TakeProfit; //
break;
}
else
{
logwrite(TradeComment,"---ERROR--- CLOSE SELL "+myInfo+bER+ " " + CLots + " at Ask= " + Ask);
RefreshRates();
Sleep(500);
}
loopcount++;
if(loopcount>maxloop)
{
logwrite(TradeComment,"---ERROR--- Giving up on closing SELL order");
return(gle);
}
}
}
}
} else {
gle=GetLastError();
bER=" Error="+gle+" "+ErrorDescription(gle);
if (gle != 0 || gle!=1)
{
logwrite(TradeComment,"---ERROR--- in selecting order in PartialTP function "+bER);
}
}
}
//+------------------------------------------------------------------+
//| Get number of open trades
//+------------------------------------------------------------------+
int GetNumTickets()
{
int i;
int typ;
numTickets = 0;
for (i = OrdersTotal()-1; i >= 0; i--)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
typ = OrderType();
if (typ == OP_BUY || typ == OP_SELL)
{
numTickets ++;
}
}
}
}
return (numTickets);
}
//+------------------------------------------------------------------+
//| Get signal
//+------------------------------------------------------------------+
int CheckSignal()
{
return (SignalScalp());
}
//+------------------------------------------------------------------+
//| Get scalp signal
//+------------------------------------------------------------------+
int SignalScalp()
{
int signal=6; //
if (enable_buy){
// Buy-Condition
{
signal = OP_BUY;
}
}
//
//
if (enable_sell){
// Sell-Condition
{
signal = OP_SELL;
}
}
//
//
//
return(signal);
}
//-----
// +----------------------------------------------------------------------------+
// | Buy Order
// +----------------------------------------------------------------------------+
void OpenBuy()
{
int gle = 0;
int ticket = 0;
double SL = 0;
double TP = 0;
double LotsB = Lots; //GetLots();
int loopcount = 0;
while(true)
{
ticket=OrderSend(Symbol(),OP_BUY,LotsB,Ask,Slippage,0,0,TradeComment,Magic,White);
}
}
// +----------------------------------------------------------------------------+
// | Sell Order
// +----------------------------------------------------------------------------+
void OpenSell()
{
int gle = 0;
int ticket = 0;
double SL = 0;
double TP = 0;
double LotsS = Lots;
int loopcount = 0;
while(true)
{
ticket=OrderSend(Symbol(),OP_SELL,LotsS,Bid,Slippage,0,0,TradeComment,Magic,Red);
}
}
bool AdjTrailOnAllOrders(
int TrailType,
int TrailPips,
int Magic,
int Direction,
int FirstMove,
int FirstStopLoss,
int SecondMove,
int SecondStopLoss,
int ThirdMove)
{
double retValue;
return(retValue);
}
void SetComment(string s) { TradeComment = s; }
double SetPoint()
{
double mPoint;
return(mPoint);
}
void logwrite (string filename, string mydata)
{
int myhandle;
}
クリストフ
Decimals "変数にどのような値を使用しているかはわかりませんが、おそらくそれが問題の原因でしょう。注文の結果は、ロットステップの値にも従わなければなりません(意味:ロットステップが例えば0.1である場合、あなたは0.11ロットをクローズしようとすることはできません)。成功しない部分的なクローズの後の最後のエラーは 何であるかを確認してください(あなたは、単に次のように行く行の後にコメントを追加することによって、それを行うことができます。
bER=" error="+gle+" "+ErrorDescription(gle);
if (gle>1) Comment(bER);
コード内のlogwrite関数が動作しないので
ムラデンです。
ご返信ありがとうございます。
さて、1つの投稿が10,000文字以上になる可能性はないので、コードを短くしました。で、元のコードでは以下のようにinit()の中にDecimalsという変数があります。
LotStep = MarketInfo(Symbol(),MODE_LOTSTEP);
if(LotStep == 0.01) {Decimals = 2;}
if(LotStep == 0.1) {Decimals = 1;}
if(LotStep == 1) {Decimals = 0;}[/PHP]
Yes, logwrite function is not functionable in the code posted, also because of the shortening. Normally it looks like:
[PHP]
void logwrite (string filename, string mydata)
{
int myhandle;
string wcalend=TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS);
Print(mydata+" "+wcalend);
if(IsTesting()) return(0);
myhandle=FileOpen(Symbol()+"_"+filename, FILE_CSV|FILE_WRITE|FILE_READ, ";");
if(myhandle>0)
{
FileSeek(myhandle,0,SEEK_END);
FileWrite(myhandle, mydata+" "+wcalend);
FileClose(myhandle);
}
}ですので、Decimals変数が原因で問題が浮上することはないと思います。
Mladen
ご返信ありがとうございます。
さて、1万文字以上の投稿はありえないので、コードを短くしました。で、元のコードではDecimals変数はinit()の中に以下のように入っています。
LotStep = MarketInfo(Symbol(),MODE_LOTSTEP);
if(LotStep == 0.01) {Decimals = 2;}
if(LotStep == 0.1) {Decimals = 1;}
if(LotStep == 1) {Decimals = 0;}[/PHP]
Yes, logwrite function is not functionable in the code posted, also because of the shortening. Normally it looks like:
[PHP]
void logwrite (string filename, string mydata)
{
int myhandle;
string wcalend=TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS);
Print(mydata+" "+wcalend);
if(IsTesting()) return(0);
myhandle=FileOpen(Symbol()+"_"+filename, FILE_CSV|FILE_WRITE|FILE_READ, ";");
if(myhandle>0)
{
FileSeek(myhandle,0,SEEK_END);
FileWrite(myhandle, mydata+" "+wcalend);
FileClose(myhandle);
}
}クリストフ
この方法でDecimals変数は問題ないはずです
いずれにせよ、注文(部分)決済に失敗した場合のエラーコードを 確認してみてください。
マジックナンバーを使用していないようなので、マジックナンバーや記号は関係ないという前提です。その場合、まず、すでにオープンしている注文があるかどうかを確認します - このように。
{
ticket=OrderSend(Symbol(), OP_BUY, lots, Ask, 3, 0, 0);
stop=(Ask-stopsize*Point);
prof=(Ask+profsize*Point);
OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Blue);
}
mladenさんありがとうございます。
if (OrdersTotal()<1)
で解決しました。
合計で1つ注文できるのですが、各ペアの通貨を開くことができるようにしたいのです。
誤解を招くようで申し訳ありません。
しかし、私が言いたいのは、各ペアで1つの注文とストップを実行 するということです。例
今、私はEURUSDで注文を開き、1つの注文を実行 します。その後、他の通貨も同時に開くことができ、1つの注文を実行 します。 私の拙い英語で申し訳ありません。
-----------------------------------------------------------------
ありがとうございます。
mladenさん、ありがとうございます。
もし(OrdersTotal()<1)
これは私の問題を解決しました。
合計で1つ注文できるのですが、各ペアの通貨を開くことができるようにしたいのです。
誤解を招いたようで申し訳ない。
しかし、私が言いたいのは、各ペアで1つの注文と停止を実行 することです。例
今、私はEURUSDで注文を開き、1つの注文を実行 します。その後、他の通貨も同時に開くことができ、1つの注文を実行 します。 私の拙い英語で申し訳ありません。
-----------------------------------------------------------------
ありがとうございます。
hock87
これを追加してください。
for (int i=0; i <= OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if (OrderSymbol() == Symbol())
TotalOrders++;
}
の前に、if (OrdersTotal()<1)の 行を追加し、その行をif (TotalOrders<1) に置き換えてください。そうすれば、1つのシンボルにつき1つのオープンオーダーだけが許可されます。
mladenさん、どうもありがとうございました。
今、試してみます。
ありがとうmladen。
もし(OrdersTotal()<1)
これは私の問題を解決しました。
合計で1つ注文できるのですが、各ペアの通貨を開くことができるようにしたいのです。
誤解を招いたようで申し訳ない。
しかし、私が言いたいのは、各ペアで1つの注文と停止を実行 することです。例
今、私はEURUSDで注文を開き、1つの注文を実行 します。その後、他の通貨も同時に開くことができ、1つの注文を実行 します。 私の拙い英語で申し訳ありません。
-----------------------------------------------------------------
ありがとうございます。
hock87
その問題の解決策については、あなたの投稿の上の投稿をお読みください。
そのための完全なコードは次のとおりです。
int TotalOrders = 0;
for (int i=0; i <= OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if (OrderSymbol() == Symbol())
TotalOrders++;
}
if (TotalOrders<1)
{
ticket=OrderSend(Symbol(), OP_BUY, lots, Ask, 3, 0, 0);
stop=(Ask-stopsize*Point);
prof=(Ask+profsize*Point);
OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Blue);
}