コーディングの方法は? - ページ 207 1...200201202203204205206207208209210211212213214...347 新しいコメント username1 2009.09.26 21:06 #2061 オープンポジションを減らす ポジションを半分に減らす方法をご存知の方はいらっしゃいますか?どのような関数を 呼び出すのでしょうか? 例オープンポジションを10ロットから5ロットに減らし、反対方向に別の取引を開始することなく? Ovidiu Marius 2009.09.26 21:27 #2062 パーシャルクローズ」と呼ばれるものです。 bool OrderClose( int ticket, double lots, double price, int slippage, color Color=CLR_NONE) クローズするロットの数を指定するだけです。 Roger09 2009.09.27 03:58 #2063 ljuba973: こんにちは。 この方法で試してみる for (int i=OrdersTotal()-1;i>=0 i--) { if (OrderSelect(i, SELECT_BY_POS)) { if (OrderSymbol()==Symbol()&&OrderType()==0) { Ans=OrderClose(OrderTicket(),alLots,Bid,2);// Order closing } if (OrderSymbol()==Symbol()&&OrderType()==1) { Ans=OrderClose(OrderTicket(),alLots,Ask,2);// Order closing } } Roger09 2009.09.27 04:01 #2064 username1: 誰かポジションの半分をクローズ/削減する方法を知っていますか。どのような関数を呼び出すのですか? 例:例:反対方向に別の取引を開始することなく、オープンポジションを10ロットから5ロットに減らす? 5ロット分の注文を閉じるだけ、こんな感じです。 OrderClose(OrderTicket(),5.0,........) ljubas 2009.09.27 07:29 #2065 Rogerさん、こんにちは。 助けてくれてありがとうございます。とりあえず、なんとか動くように直しました。 OrderSend(Symbol(),OP_BUY,alLots,Ask,3,0,0,EA_Tester,Magic); if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS)==true) { alTicker = OrderTicket(); Alert("Bought! ", alTicker); } else Print("OrderSelect failed error code is ",GetLastError()); [/CODE] Like that I found alTicker (after opening position) which I close later on. But your code I will use to optimize my Closing function. Sorry for maybe "beginner's code", I am into mq4 just 2 days ... will improve - I promise Thanks again Roger09: Try this way [CODE] for (int i=OrdersTotal()-1;i>=0 i--) { if (OrderSelect(i, SELECT_BY_POS)) { if (OrderSymbol()==Symbol()&&OrderType()==0) { Ans=OrderClose(OrderTicket(),alLots,Bid,2);// Order closing } if (OrderSymbol()==Symbol()&&OrderType()==1) { Ans=OrderClose(OrderTicket(),alLots,Ask,2);// Order closing } } How to code? Helping with a simple Slawa How to Close fxbg 2009.09.27 18:13 #2066 固定ストップロスを設定するには? こんにちは。 どなたか、このコードで固定ストップロスを置く方法を教えていただけませんか? //+------------------------------------------------------------------+ //| Daydream by Cothool | //| Recommended: USD/JPY 1H | //+------------------------------------------------------------------+ #define MAGIC_NUM 48213657 //+------------------------------------------------------------------+ extern double Lots = 0.1; extern int ChannelPeriod = 25; extern int Slippage = 3; extern int TakeProfit = 15; //+------------------------------------------------------------------+ double LastOrderTime = 0; double CurrentDirection = 0; double CurrentTakeProfitPrice = 0; //+------------------------------------------------------------------+ void OpenLong() { if (Time[0] == LastOrderTime) return; if (CurrentDirection != 0) return; OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "Daydream", MAGIC_NUM, 0, Blue); LastOrderTime = Time[0]; CurrentDirection = 1; } //+------------------------------------------------------------------+ void OpenShort() { if (Time[0] == LastOrderTime) return; if (CurrentDirection != 0) return; OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "Daydream", MAGIC_NUM, 0, Red); LastOrderTime = Time[0]; CurrentDirection = -1; } //+------------------------------------------------------------------+ void CloseLong() { int i; if (Time[0] == LastOrderTime) return; if (CurrentDirection != 1) return; for (i = 0; i < OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_BUY) { OrderClose(OrderTicket(), OrderLots(), Bid, 3, White); LastOrderTime = Time[0]; CurrentDirection = 0; } } } //+------------------------------------------------------------------+ void CloseShort() { int i; if (Time[0] == LastOrderTime) return; if (CurrentDirection != -1) return; for (i = 0; i < OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_SELL) { OrderClose(OrderTicket(), OrderLots(), Ask, 3, White); LastOrderTime = Time[0]; CurrentDirection = 0; } } } //+------------------------------------------------------------------+ void start() { double HighestValue; double LowestValue; HighestValue = High; LowestValue = Low[Lowest(NULL, 0, MODE_LOW, ChannelPeriod, 1)]; // BUY if (Close[0] < LowestValue) { CloseShort(); OpenLong(); CurrentTakeProfitPrice = Bid + TakeProfit * Point; } // SELL if (Close[0] > HighestValue) { CloseLong(); OpenShort(); CurrentTakeProfitPrice = Ask - TakeProfit * Point; } // Trailing Profit Taking for Long Position if (CurrentDirection == 1) { if (CurrentTakeProfitPrice > Bid + TakeProfit * Point) CurrentTakeProfitPrice = Bid + TakeProfit * Point; if (Bid >= CurrentTakeProfitPrice) CloseLong(); } // Trailing Profit Taking for Short Position if (CurrentDirection == -1) { if (CurrentTakeProfitPrice < Ask - TakeProfit * Point) CurrentTakeProfitPrice = Ask - TakeProfit * Point; if (Ask <= CurrentTakeProfitPrice) CloseShort(); } } //+------------------------------------------------------------------+ よろしくお願いします。 How to code? [アーカイブ!】どんなエキスパートやインジケーターでも無料で書きます。 コーディングヘルプ...アラートの代わりにインジケータをフィルタリングする方法を教えてください。 Roger09 2009.09.27 20:44 #2067 fxbg: こんにちは。どなたか、このコードで固定ストップロスを配置する方法を教えていただけませんか? 置換 extern double Lots = 0.1; extern int ChannelPeriod = 25; extern int Slippage = 3; extern int TakeProfit = 15; //+------------------------------------------------------------------+ double LastOrderTime = 0; double CurrentDirection = 0; double CurrentTakeProfitPrice = 0; //+------------------------------------------------------------------+ void OpenLong() { if (Time[0] == LastOrderTime) return; if (CurrentDirection != 0) return; OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "Daydream", MAGIC_NUM, 0, Blue); LastOrderTime = Time[0]; CurrentDirection = 1; } //+------------------------------------------------------------------+ void OpenShort() { if (Time[0] == LastOrderTime) return; if (CurrentDirection != 0) return; OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "Daydream", MAGIC_NUM, 0, Red); LastOrderTime = Time[0]; CurrentDirection = -1; } [/CODE] to [CODE]extern double Lots = 0.1; extern int ChannelPeriod = 25; extern int Slippage = 3; extern int TakeProfit = 15; extern int StopLoss = 15; //+------------------------------------------------------------------+ double LastOrderTime = 0; double CurrentDirection = 0; double CurrentTakeProfitPrice = 0; //+------------------------------------------------------------------+ void OpenLong() { if (Time[0] == LastOrderTime) return; if (CurrentDirection != 0) return; OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, Ask-StopLoss*Point, 0, "Daydream", MAGIC_NUM, 0, Blue); LastOrderTime = Time[0]; CurrentDirection = 1; } //+------------------------------------------------------------------+ void OpenShort() { if (Time[0] == LastOrderTime) return; if (CurrentDirection != 0) return; OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, Bid+StopLoss*Point, 0, "Daydream", MAGIC_NUM, 0, Red); LastOrderTime = Time[0]; CurrentDirection = -1; } How to code? Can anybody help me [アーカイブ!】どんなルーキーの質問でも、フォーラムを散らかさないように。プロフェッショナルの皆さん、通り過ぎないでください。あなたなしではどこにも行けない - 2. 削除済み 2009.09.27 21:20 #2068 インジケーターの修正について こんにちは、プログラマーの皆さん。 私はフォーラムで私が取引している現在のポジションを表示するインジケータ(通貨ポジション)を発見しました。今、このインジケータをチャートの下にある外部ウィンドウを使用するように作るのを手伝ってくれる人を見つけたいのですが、フォントや色も変えることができます。私はプログラムが得意ではありません。どうもありがとうございました。 アサム ファイル: currencypositions.mq4 5 kb fxbg 2009.09.28 07:13 #2069 テスターで動作しない テスターでこのEAを起動しました。最初のストップロスに 到達するとテスターは 停止し、テストを続行しません。この問題を修正することは可能ですか? //+------------------------------------------------------------------+ //| Daydream by Cothool | //| Recommended: USD/JPY 1H | //+------------------------------------------------------------------+ #define MAGIC_NUM 48213657 //+------------------------------------------------------------------+ extern double Lots = 0.1; extern int ChannelPeriod = 25; extern int Slippage = 3; extern int TakeProfit = 0; extern int StopLoss = 15; //+------------------------------------------------------------------+ double LastOrderTime = 0; double CurrentDirection = 0; double CurrentTakeProfitPrice = 0; //+------------------------------------------------------------------+ void OpenLong() { if (Time[0] == LastOrderTime) return; if (CurrentDirection != 0) return; OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage,Ask-StopLoss*Point, 0, "Daydream", MAGIC_NUM, 0, Blue); LastOrderTime = Time[0]; CurrentDirection = 1; } //+------------------------------------------------------------------+ void OpenShort() { if (Time[0] == LastOrderTime) return; if (CurrentDirection != 0) return; OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage,Bid+StopLoss*Point, 0, "Daydream", MAGIC_NUM, 0, Red); LastOrderTime = Time[0]; CurrentDirection = -1; } //+------------------------------------------------------------------+ void CloseLong() { int i; if (Time[0] == LastOrderTime) return; if (CurrentDirection != 1) return; for (i = 0; i < OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_BUY) { OrderClose(OrderTicket(), OrderLots(), Bid, 3, White); LastOrderTime = Time[0]; CurrentDirection = 0; } } } //+------------------------------------------------------------------+ void CloseShort() { int i; if (Time[0] == LastOrderTime) return; if (CurrentDirection != -1) return; for (i = 0; i < OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_SELL) { OrderClose(OrderTicket(), OrderLots(), Ask, 3, White); LastOrderTime = Time[0]; CurrentDirection = 0; } } } //+------------------------------------------------------------------+ void start() { double HighestValue; double LowestValue; HighestValue = High; LowestValue = Low[Lowest(NULL, 0, MODE_LOW, ChannelPeriod, 1)]; // BUY if (Close[0] < LowestValue) { CloseShort(); OpenLong(); CurrentTakeProfitPrice = Bid + TakeProfit * Point; } // SELL if (Close[0] > HighestValue) { CloseLong(); OpenShort(); CurrentTakeProfitPrice = Ask - TakeProfit * Point; } // Trailing Profit Taking for Long Position if (CurrentDirection == 1) { if (CurrentTakeProfitPrice > Bid + TakeProfit * Point) CurrentTakeProfitPrice = Bid + TakeProfit * Point; if (Bid >= CurrentTakeProfitPrice) CloseLong(); } // Trailing Profit Taking for Short Position if (CurrentDirection == -1) { if (CurrentTakeProfitPrice < Ask - TakeProfit * Point) CurrentTakeProfitPrice = Ask - TakeProfit * Point; if (Ask <= CurrentTakeProfitPrice) CloseShort(); } } //+------------------------------------------------------------------+ How to code? [アーカイブ!】どんなエキスパートやインジケーターでも無料で書きます。 コーディングヘルプ...アラートの代わりにインジケータをフィルタリングする方法を教えてください。 nicesurf 2009.09.28 14:05 #2070 このコードは素晴らしいです。 1...200201202203204205206207208209210211212213214...347 新しいコメント 取引の機会を逃しています。 無料取引アプリ 8千を超えるシグナルをコピー 金融ニュースで金融マーケットを探索 新規登録 ログイン スペースを含まないラテン文字 このメールにパスワードが送信されます エラーが発生しました Googleでログイン WebサイトポリシーおよびMQL5.COM利用規約に同意します。 新規登録 MQL5.com WebサイトへのログインにCookieの使用を許可します。 ログインするには、ブラウザで必要な設定を有効にしてください。 ログイン/パスワードをお忘れですか? Googleでログイン
オープンポジションを減らす
ポジションを半分に減らす方法をご存知の方はいらっしゃいますか?どのような関数を 呼び出すのでしょうか?
例オープンポジションを10ロットから5ロットに減らし、反対方向に別の取引を開始することなく?
パーシャルクローズ」と呼ばれるものです。
クローズするロットの数を指定するだけです。
こんにちは。
この方法で試してみる
for (int i=OrdersTotal()-1;i>=0 i--) {
if (OrderSelect(i, SELECT_BY_POS)) {
if (OrderSymbol()==Symbol()&&OrderType()==0) {
Ans=OrderClose(OrderTicket(),alLots,Bid,2);// Order closing
}
if (OrderSymbol()==Symbol()&&OrderType()==1) {
Ans=OrderClose(OrderTicket(),alLots,Ask,2);// Order closing
}
}
誰かポジションの半分をクローズ/削減する方法を知っていますか。どのような関数を呼び出すのですか? 例:例:反対方向に別の取引を開始することなく、オープンポジションを10ロットから5ロットに減らす?
5ロット分の注文を閉じるだけ、こんな感じです。
OrderClose(OrderTicket(),5.0,........)
Rogerさん、こんにちは。
助けてくれてありがとうございます。とりあえず、なんとか動くように直しました。
OrderSend(Symbol(),OP_BUY,alLots,Ask,3,0,0,EA_Tester,Magic);
if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS)==true) {
alTicker = OrderTicket();
Alert("Bought! ", alTicker);
} else Print("OrderSelect failed error code is ",GetLastError());
[/CODE]
Like that I found alTicker (after opening position) which I close later on.
But your code I will use to optimize my Closing function. Sorry for maybe "beginner's code", I am into mq4 just 2 days ... will improve - I promise
Thanks again
Try this way
[CODE]
for (int i=OrdersTotal()-1;i>=0 i--) {
if (OrderSelect(i, SELECT_BY_POS)) {
if (OrderSymbol()==Symbol()&&OrderType()==0) {
Ans=OrderClose(OrderTicket(),alLots,Bid,2);// Order closing
}
if (OrderSymbol()==Symbol()&&OrderType()==1) {
Ans=OrderClose(OrderTicket(),alLots,Ask,2);// Order closing
}
}
固定ストップロスを設定するには?
こんにちは。
どなたか、このコードで固定ストップロスを置く方法を教えていただけませんか?
//| Daydream by Cothool |
//| Recommended: USD/JPY 1H |
//+------------------------------------------------------------------+
#define MAGIC_NUM 48213657
//+------------------------------------------------------------------+
extern double Lots = 0.1;
extern int ChannelPeriod = 25;
extern int Slippage = 3;
extern int TakeProfit = 15;
//+------------------------------------------------------------------+
double LastOrderTime = 0;
double CurrentDirection = 0;
double CurrentTakeProfitPrice = 0;
//+------------------------------------------------------------------+
void OpenLong()
{
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != 0)
return;
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0,
"Daydream", MAGIC_NUM, 0, Blue);
LastOrderTime = Time[0];
CurrentDirection = 1;
}
//+------------------------------------------------------------------+
void OpenShort()
{
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != 0)
return;
OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0,
"Daydream", MAGIC_NUM, 0, Red);
LastOrderTime = Time[0];
CurrentDirection = -1;
}
//+------------------------------------------------------------------+
void CloseLong()
{
int i;
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != 1)
return;
for (i = 0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() &&
OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_BUY)
{
OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);
LastOrderTime = Time[0];
CurrentDirection = 0;
}
}
}
//+------------------------------------------------------------------+
void CloseShort()
{
int i;
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != -1)
return;
for (i = 0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() &&
OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_SELL)
{
OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);
LastOrderTime = Time[0];
CurrentDirection = 0;
}
}
}
//+------------------------------------------------------------------+
void start()
{
double HighestValue;
double LowestValue;
HighestValue = High;
LowestValue = Low[Lowest(NULL, 0, MODE_LOW, ChannelPeriod, 1)];
// BUY
if (Close[0] < LowestValue)
{
CloseShort();
OpenLong();
CurrentTakeProfitPrice = Bid + TakeProfit * Point;
}
// SELL
if (Close[0] > HighestValue)
{
CloseLong();
OpenShort();
CurrentTakeProfitPrice = Ask - TakeProfit * Point;
}
// Trailing Profit Taking for Long Position
if (CurrentDirection == 1)
{
if (CurrentTakeProfitPrice > Bid + TakeProfit * Point)
CurrentTakeProfitPrice = Bid + TakeProfit * Point;
if (Bid >= CurrentTakeProfitPrice)
CloseLong();
}
// Trailing Profit Taking for Short Position
if (CurrentDirection == -1)
{
if (CurrentTakeProfitPrice < Ask - TakeProfit * Point)
CurrentTakeProfitPrice = Ask - TakeProfit * Point;
if (Ask <= CurrentTakeProfitPrice)
CloseShort();
}
}
//+------------------------------------------------------------------+
よろしくお願いします。
こんにちは。
どなたか、このコードで固定ストップロスを配置する方法を教えていただけませんか?
置換
extern int ChannelPeriod = 25;
extern int Slippage = 3;
extern int TakeProfit = 15;
//+------------------------------------------------------------------+
double LastOrderTime = 0;
double CurrentDirection = 0;
double CurrentTakeProfitPrice = 0;
//+------------------------------------------------------------------+
void OpenLong()
{
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != 0)
return;
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0,
"Daydream", MAGIC_NUM, 0, Blue);
LastOrderTime = Time[0];
CurrentDirection = 1;
}
//+------------------------------------------------------------------+
void OpenShort()
{
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != 0)
return;
OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0,
"Daydream", MAGIC_NUM, 0, Red);
LastOrderTime = Time[0];
CurrentDirection = -1;
} [/CODE]
to
[CODE]extern double Lots = 0.1;
extern int ChannelPeriod = 25;
extern int Slippage = 3;
extern int TakeProfit = 15;
extern int StopLoss = 15;
//+------------------------------------------------------------------+
double LastOrderTime = 0;
double CurrentDirection = 0;
double CurrentTakeProfitPrice = 0;
//+------------------------------------------------------------------+
void OpenLong()
{
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != 0)
return;
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, Ask-StopLoss*Point, 0,
"Daydream", MAGIC_NUM, 0, Blue);
LastOrderTime = Time[0];
CurrentDirection = 1;
}
//+------------------------------------------------------------------+
void OpenShort()
{
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != 0)
return;
OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, Bid+StopLoss*Point, 0,
"Daydream", MAGIC_NUM, 0, Red);
LastOrderTime = Time[0];
CurrentDirection = -1;
}インジケーターの修正について
こんにちは、プログラマーの皆さん。
私はフォーラムで私が取引している現在のポジションを表示するインジケータ(通貨ポジション)を発見しました。今、このインジケータをチャートの下にある外部ウィンドウを使用するように作るのを手伝ってくれる人を見つけたいのですが、フォントや色も変えることができます。私はプログラムが得意ではありません。どうもありがとうございました。
アサム
テスターで動作しない
テスターでこのEAを起動しました。最初のストップロスに 到達するとテスターは 停止し、テストを続行しません。この問題を修正することは可能ですか?
//| Daydream by Cothool |
//| Recommended: USD/JPY 1H |
//+------------------------------------------------------------------+
#define MAGIC_NUM 48213657
//+------------------------------------------------------------------+
extern double Lots = 0.1;
extern int ChannelPeriod = 25;
extern int Slippage = 3;
extern int TakeProfit = 0;
extern int StopLoss = 15;
//+------------------------------------------------------------------+
double LastOrderTime = 0;
double CurrentDirection = 0;
double CurrentTakeProfitPrice = 0;
//+------------------------------------------------------------------+
void OpenLong()
{
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != 0)
return;
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage,Ask-StopLoss*Point, 0,
"Daydream", MAGIC_NUM, 0, Blue);
LastOrderTime = Time[0];
CurrentDirection = 1;
}
//+------------------------------------------------------------------+
void OpenShort()
{
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != 0)
return;
OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage,Bid+StopLoss*Point, 0,
"Daydream", MAGIC_NUM, 0, Red);
LastOrderTime = Time[0];
CurrentDirection = -1;
}
//+------------------------------------------------------------------+
void CloseLong()
{
int i;
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != 1)
return;
for (i = 0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() &&
OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_BUY)
{
OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);
LastOrderTime = Time[0];
CurrentDirection = 0;
}
}
}
//+------------------------------------------------------------------+
void CloseShort()
{
int i;
if (Time[0] == LastOrderTime)
return;
if (CurrentDirection != -1)
return;
for (i = 0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() &&
OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_SELL)
{
OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);
LastOrderTime = Time[0];
CurrentDirection = 0;
}
}
}
//+------------------------------------------------------------------+
void start()
{
double HighestValue;
double LowestValue;
HighestValue = High;
LowestValue = Low[Lowest(NULL, 0, MODE_LOW, ChannelPeriod, 1)];
// BUY
if (Close[0] < LowestValue)
{
CloseShort();
OpenLong();
CurrentTakeProfitPrice = Bid + TakeProfit * Point;
}
// SELL
if (Close[0] > HighestValue)
{
CloseLong();
OpenShort();
CurrentTakeProfitPrice = Ask - TakeProfit * Point;
}
// Trailing Profit Taking for Long Position
if (CurrentDirection == 1)
{
if (CurrentTakeProfitPrice > Bid + TakeProfit * Point)
CurrentTakeProfitPrice = Bid + TakeProfit * Point;
if (Bid >= CurrentTakeProfitPrice)
CloseLong();
}
// Trailing Profit Taking for Short Position
if (CurrentDirection == -1)
{
if (CurrentTakeProfitPrice < Ask - TakeProfit * Point)
CurrentTakeProfitPrice = Ask - TakeProfit * Point;
if (Ask <= CurrentTakeProfitPrice)
CloseShort();
}
}
//+------------------------------------------------------------------+
このコードは素晴らしいです。