MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
int open_orders() { int count = 0; for(int i=OrdersTotal()-1; i>=0; i--) // good habit to count down { if(!OrderSelect(i,SELECT_BY_POS)) continue; // select the order if(OrderSymbol() != _Symbol) continue; // optional check for same symbol if(OrderMagicNumber()!= magic_no) continue; // optional check for magic number if(OrderType() < 2) count++; // 0 == OP_BUY and 1 == OP_SELL } return(count); }
int open_orders() { int count = 0; for(int i=OrdersTotal()-1; i>=0; i--) // good habit to count down { if(!OrderSelect(i,SELECT_BY_POS)) continue; // select the order if(OrderSymbol() != _Symbol) continue; // optional check for same symbol if(OrderMagicNumber()!= magic_no) continue; // optional check for magic number if(OrderType() < 2) count++; // 0 == OP_BUY and 1 == OP_SELL } return(count); }
bool order= 0;
int ticket;
void OnTick()
{
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMax (up,down) < Bid )
int ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket!=1)
{
order=1;
}
}
}
}
チケットの二重宣言。
int ticket;
void OnTick()
{
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMax (up,down) < Bid )
int ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket!=1)
{
order=1;
}
}
}
}
チケットの宣言は、...ブラブラ...を隠す? 私は人間のコンパイラです。
2番目のintを削除して ください。
を入れた。
ブールオーダーと
int ticket
をグローバル変数に、残りのコードをOnTickに置きましたが、それでもまだ何も入力されません。
未コンパイル、未テスト
{
double up = iIchimoku(NULL,5,9,26,52,3,0),
down = iIchimoku(NULL,5,9,26,52,4,0);
static bool was_above = true;
bool is_above = (MathMax(up,down)< Bid);
if(!was_above && is_above && open_orders()<1)
{
if(OrderSend(NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point)<0)
{
printf("OrderSend() failed. Error code: %i",GetLastError());
}
}
was_above = is_above;
}
int open_orders()
{
int count = 0;
for(int i=OrdersTotal()-1; i>=0; i--) // good habit to count down
{
if(!OrderSelect(i,SELECT_BY_POS)) continue; // select the order
if(OrderSymbol() != _Symbol) continue; // optional check for same symbol
if(OrderMagicNumber()!= magic_no) continue; // optional check for magic number
if(OrderType() < 2) count++; // 0 == OP_BUY and 1 == OP_SELL
}
return(count);
}
Marco: 重複したintを削除しましたが、今は取引が成立していません。
が雲の上にある場合、新しいトレードを作成し続けます。
Honest Knave: あなたのコードを試してみました、私はちょうど欠けていたmagic_noを定義しました、それは正常に動作します、それは価格が再び雲に触れる新しい貿易を待ちます、それは本当に次のプロジェクトのために有用であろう、しかし、。
1ºの取引後に停止させたいのですが、どうしたらよいでしょうか?
ありがとうございました。
int ticket;
void OnTick()
{
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMax (up,down) < Bid )
ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket!=1)
{
order=1;
}
}
}
}
これが問題なのです。
int ticket;
void OnTick()
{
if(order==0)
{
double up= iIchimoku (NULL, 5,9,26,52,3,0);
double down= iIchimoku (NULL,5,9,26,52,4,0);
if (MathMax (up,down) < Bid )
ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket>-1)
{
order=1;
}
}
}
}
というわけで、これを試してみてください。
また、OrderSendはチケット番号を返すか、失敗した場合は-1マイナス1することに注意してください。
Honest Knave: あなたのコードを試しました、私はちょうど欠けていたmagic_noを定義しました、それはうまく動作します、それは価格が再び雲に触れる場合、新しい取引に待機します、それは本当に次のプロジェクトに有用である、しかし
1回の取引で停止させたいのですが、どうしたらよいでしょうか?
ありがとうございました。
1回以上取引してはいけないのでしょうか...?これはそうです。
{
double up = iIchimoku(NULL,5,9,26,52,3,0),
down = iIchimoku(NULL,5,9,26,52,4,0);
static bool was_above = true;
bool is_above = (MathMax(up,down)< Bid);
if(!was_above && is_above && open_orders()<1)
{
if(OrderSend(NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point)<0)
{
printf("OrderSend() failed. Error code: %i",GetLastError());
}
}
was_above = is_above;
}
int open_orders()
{
int count = 0;
for(int i=OrdersTotal()-1; i>=0; i--) // good habit to count down
{
if(!OrderSelect(i,SELECT_BY_POS)) continue; // select the order
if(OrderSymbol() != _Symbol) continue; // optional check for same symbol
if(OrderMagicNumber()!= magic_no) continue; // optional check for magic number
if(OrderType() < 2) count++; // 0 == OP_BUY and 1 == OP_SELL
}
return(count);
}
正直なKnaveです。
あなたのEAは素晴らしいですが、価格が再び一目の雲まで下がり、その後上昇した場合に新しい取引を作成します。同じローソク足で注文を繰り返すことができないので、私が抱えていた問題と同じです。
しかし、最初の取引の後、EAまたはスクリプトがすぐに終了するようにコード化する方法が必要です。
Marco: あなたの新しいアップデートを試しましたが、それはどんな取引もしません。あなたが最後に投稿した方法と同じように、2番目のintを削除してチケットに入れました。しかし、最初のトレードはstrategy testerでは 行われません。
正直なKnaveです。
あなたのEAは素晴らしいですが、価格が再び一目の雲まで下がり、その後上昇した場合に新しい取引を作成します。同じローソク足で注文を繰り返すことができないので、私が抱えていた問題と同じです。
しかし、最初の取引の後、EAやスクリプトがすぐに終了するようにコード化する方法が必要です。
何を言っているのか分かりません。
そのコードでは、一度に1つ以上の注文を出すことはできません。
しかし、注文が終了し、トリガーが再び発生した場合、別の注文が開かれます。
つまり、1つの取引しか開かれないようにしたいのでしょうか?
意味がよくわからないのですが
そのコードでは一度に1つ以上の注文を開くことはできません。
しかし、注文が終了し、トリガーが再び発生した場合、別の注文を開くことになります。
つまり、1つの取引しか開かれないようにしたいのでしょうか?