アスク! - ページ 106

 

グラフの時間帯

グラフがどの期間で動いているかを知るためのコードを教えてください。そうすれば、期間ごとに変数の設定を変えることができますね。

if(???????) ... ....

デイブ

 
Dave137:
グラフがどの時間帯で動いているかを調べるコードは何でしょうか?そうすれば、期間ごとに変数設定を変えることができますね。

if(???????) ... .

Dave
if(Period() == PERIOD_M15) ...

[/PHP]

or:

switch(Period())

{

case PERIOD_M1:

...

break;

case PERIOD_M5:

...

break;

...

}

[/PHP]

Sometime it maybe easier to work with indices:[PHP]

int tfIndex = ArrayBsearch({PERIOD_M1, PERIOD_M5, PERIOD_M15, ...}, Period());

Example : how to display the period by the string you want:[PHP]

int Periods[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, ...};

string sPeriods[] = {" M1", " M5", " M15", " M30", " Hourly", " 4 hours", " Daily", " Weekly"...};

int tfIndex = ArrayBsearch(Periods, Period());

comment(Symbol() + sPeriods[tfIndex]);

 

Michelさん、ありがとうございます。

私が作っているこのEAがそうなることを願っています。 あなたの助けはとてもありがたいです

デイブ

 

こんにちは。

この機能を 追加するのを手伝ってくれる人はいますか?そのバーが終了したときに取引を終了するようにするか、別の言葉で次のバーが表示されたときに取引を終了するようにします(取引が利益または損失であるかどうかは関係ありません)。

extern int SystemMagicNumber=197;

extern double TakeProfit = 100;

extern double StopLoss = 500;

extern double Lots=0.1;

extern double TrailingStop = 0.1; extern double Lots=0.1; extern double TrailingStop = 0;

extern int MaxBuyTrades=5;

extern int MaxSellTrades=5; extern int MaxBuyTrades=5;

int start()

{

if( HavePosThisBar(SystemMagicNumber)==false )

&&iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,1)<iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,1)

&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,2)>iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,2)

&& 売建玉数()<最大売建玉数

)

{

OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",SystemMagicNumber,0,Red).OrderSend(Symbol(),OP_Sell,Lots,Bid,0,Bid+StopLoss*Point,Bid-TakeProfit*Point);

return(0);

}

if( HavePosThisBar(SystemMagicNumber)==false)

&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,1)>iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,1)の場合

&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,2)<iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,2)

&& BuyPositionsCount()<MaxBuyTrades

)

{

OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-StopLoss*Point,Ask+TakeProfit*Point,"", SystemMagicNumber,0,Blue).を送信します。

return(0);

}

for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol() == Symbol())

{

if (オーダータイプ()==OP_SELL)

{

if (TrailingStop>0)

{

if (オーダーオープン価格()-アスク>トレイリングストップ*ポイント)

{

if (OrderStopLoss() == 0 || OrderStopLoss()>(Ask+Point*TrailingStop))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Purple).OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProtect(),0,Purple);

return(0);

}

}

}

}

if (OrderType()==OP_BUY)

{

if (TrailingStop>0)

{

if (ビッド-オープンプライス()>トレイリングストップ*ポイント)

{

if (オーダーストップ・ロス()<(ビッドポイント*トレイリングストップ))

{

オーダーモディファイ(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Yellow);

return(0);

}

}

}

}

}

}

//----

return(0);

}

//+------------------------------------------------------------------+

bool HavePosThisBar(int magic)

{

int cnt;

bool Result=false。

for(cnt=0; cnt<=OrdersHistoryTotal()-1; cnt++)

if(OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY))

if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == magic) && Time[0]<=OrderOpenTime()))

{

Result=true。

ブレーク

}

for(cnt=0; cnt<=OrdersTotal()-1; cnt++)

if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))

if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == magic) && Time[0]<=OrderOpenTime()))

{

Result=true。

ブレーク

return(Result);

}

int BuyPositionsCount()

{

int Result=0;

for(int cnt=0; cnt<=OrdersTotal()-1; cnt++)

if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))

if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == SystemMagicNumber) && (OrderType() == OPT))

(オーダータイプ()==OP_BUY)

)

{

Result++;

}

return(Result);

}

int SellPositionsCount()

{

int Result=0;

for(int cnt=0; cnt<=OrdersTotal()-1; cnt++)

if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))

if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == SystemMagicNumber) && (OrderType() == OPMagicNumber))

(オーダータイプ()==OP_SELL)

)

{

結果++。

}

return(Result)。

}

 
bearfoot090:
こんにちは。

この機能を追加するのを手伝ってくれる人はいますか?バーが完了したときに取引を終了するようにするか、別の言葉で、次のバーが表示されたときに取引を終了するようにする(取引が利益または損失は関係ありません)。

新しいバーを検出するために、いくつかのソリューションがあります。

1)

if(Volume[0] == 1) CloseOrders(); [/PHP] Not very reliable, for example if the terminal has to be restarted you may loose the first tick of the bar.

2)

if(BarsCnt < Bars) {BarsCnt = Bars; CloseOrders();}[/PHP] Not very reliable, for example if new bars are added to the left of the chart.

3)

if(Time1 < Time[0]) {Time1 = Time[0]; CloseOrders();}

Better, but again, restarting the terminal may produce wrong behaviors.

So my opinion is that the best is to write the lifetime max of each order into the order itself, using the "Comment" field :[PHP]OrderSend(..., ""+(Time[0] + Period()*60), ..);
Then you can scan the orders and check :[PHP]if(TimeCurrent() > OrderComment()) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, CLR_NONE);

.これは良い方法です。なぜなら、クローズする注文がいくつかある場合、それを実行するのに必要なすべての時間があるからです。

 

ミッシェルさん、返信ありがとうございます。

でも、コメントには何を書けばいいのでしょうか?

 
bearfoot090:
ミッシェルさん、ありがとうございます!やってみます。

注文を確定したい時刻を入力してください。コメント欄は文字列でなければならないので、値の前に「"+」があるのはそのためです。

""+(Time[0] + Period()*60) // begin of the next bar on the current timeframe

""+(TimeCurrent() + 2*360 + 30*60) // 2 hours 30 minutes after the openning

""+(iTime(NULL,PERIOD_D1,0) + 23*360 + 45*60) // today at 23:45 (server time)

""+(iTime(NULL,PERIOD_W1,0) + (PERIOD_W1 - 10)*60) // next friday at 23:50
 

感謝

Michel:
必要であれば、まず朝8時よりも遅いかどうかを確認します。
if(Hour() < 8) return;[/PHP]

Then, find the max and min of the current day. (if its ok for you, its easier than from 8 am): [PHP]double Max = iHigh(Symbol(), PERIOD_D1, 0);

double Min = iLow(Symbol(), PERIOD_D1, 0);

int Range = (Max - Min) / Point;

if(Range > 90) return;

...

こんにちは。

お礼を言うのが遅くなってしまい申し訳ありません。

ありがとうございました。

またよろしくお願いします。

シェック

 
Michel:
新しいバーを検出するには、いくつかの解決策があります。

1)

if(Volume[0] == 1) CloseOrders(); [/PHP] Not very reliable, for example if the terminal has to be restarted you may loose the first tick of the bar.

2)

if(BarsCnt < Bars) {BarsCnt = Bars; CloseOrders();}[/PHP] Not very reliable, for example if new bars are added to the left of the chart.

3)

if(Time1 < Time[0]) {Time1 = Time[0]; CloseOrders();}[/PHP] Better, but again, restarting the terminal may produce wrong behaviors.

So my opinion is that the best is to write the lifetime max of each order into the order itself, using the "Comment" field :

OrderSend(..., ""+(Time[0] + Period()*60), ..);[/PHP] Then you can scan the orders and check :[PHP]if(TimeCurrent() > OrderComment()) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, CLR_NONE);
. This is a good solution because if you have several orders to close, you have all the time needed to do it.

i got the error below.what does ot mean?

[PHP]'>' - different types in comparison F:\Program Files\MetaTrader - FXOpen\experts\EMA_10.mq4 (88, 22)

I make it like this

for the send order

[PHP]OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-25*Point,Ask+TakeProfit*Point, ""+(Time[0] + Period()*60),SystemMagicNumber,0,Blue);

そして終値注文の場合

[PHP]if(TimeCurrent() > OrderComment())

{

OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, CLR_NONE);

}

というエラーが出てしまいます。

これは正しいのでしょうか?

 

私のミスです、すみません。

これでうまくいくはずです。

if(TimeCurrent() > StringToInteger(OrderComment())