묻다! - 페이지 106

 

그래프의 기간

그래프가 실행되는 시간을 확인하는 코드는 무엇입니까? 따라서 각 기간에 대한 변수 설정을 변경할 수 있습니다.

만약(?????) . . .

데이브

 
Dave137:
그래프가 실행되는 시간을 확인하는 코드는 무엇입니까? 따라서 각 기간에 대한 변수 설정을 변경할 수 있습니다.

만약(?????) . . .

데이브
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]);

 

미셸 감사합니다!

내가 만들고 있는 이 EA가 하나가 되길 바랍니다! 귀하의 도움에 감사드립니다!

데이브

 

안녕!

여기 일부가 이 기능 을 추가하는 데 도움이 될 수 있습니다. 바가 완료되면 거래를 종료하거나 다음 바가 나타날 때 거래를 종료하도록 합니다.(거래가 손익인지 여부는 중요하지 않음)

extern int SystemMagicNumber=197;

외부 이중 TakeProfit = 100;

외부 이중 손절매 = 500;

외부 이중 로트=0.1;

외부 이중 TrailingStop = 0;

extern int MaxBuyTrades=5;

extern int MaxSellTrades=5;

정수 시작()

{

if(HavePosThisBar(SystemMagicNumber)==거짓

&&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)

&& SellPositionsCount()<MaxSellTrades

)

{

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

리턴(0);

}

if(HavePosThisBar(SystemMagicNumber)==거짓

&& 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);

리턴(0);

}

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

{

주문 선택(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol() == Symbol())

{

if (주문 유형()==OP_SELL)

{

if (TrailingStop>0)

{

if (OrderOpenPrice()-Ask>TrailingStop*Point)

{

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

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,퍼플);

리턴(0);

}

}

}

}

if (주문유형()==OP_BUY)

{

if (TrailingStop>0)

{

if (Bid-OrderOpenPrice()>TrailingStop*Point)

{

if (OrderStopLoss()<(Bid-Point*TrailingStop))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Yellow);

리턴(0);

}

}

}

}

}

}

//----

리턴(0);

}

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

bool HavePosThisBar(int 마법)

{

정수 cnt;

부울 결과=거짓;

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

if(주문 선택(cnt, SELECT_BY_POS, MODE_HISTORY))

if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == 마술) && 시간[0]<=OrderOpenTime())

{

결과=참;

부서지다;

}

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

if(주문 선택(cnt, SELECT_BY_POS, MODE_TRADES))

if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == 마술) && 시간[0]<=OrderOpenTime())

{

결과=참;

부서지다;

}

반환(결과);

}

int BuyPositionsCount()

{

정수 결과 = 0;

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

if(주문 선택(cnt, SELECT_BY_POS, MODE_TRADES))

if((OrderSymbol() == 기호()) &&(OrderMagicNumber() == SystemMagicNumber) &&

(주문 유형()==OP_BUY)

)

{

결과++;

}

반환(결과);

}

int SellPositionsCount()

{

정수 결과 = 0;

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

if(주문 선택(cnt, SELECT_BY_POS, MODE_TRADES))

if((OrderSymbol() == 기호()) &&(OrderMagicNumber() == SystemMagicNumber) &&

(주문 유형()==OP_SELL)

)

{

결과++;

}

반환(결과);

}

 
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);

. 마감해야 할 주문이 여러 개 있는 경우 이를 수행하는 데 필요한 시간이 항상 있기 때문에 이는 좋은 솔루션입니다.

 

michel님 답변 감사합니다.

노력하겠습니다. 하지만 댓글에 무엇을 넣어야 하나요? 내가 좋아하는 것?

 
bearfoot090:
답변 감사합니다 michel. 노력하겠습니다. 하지만 댓글에 무엇을 넣어야 하나요? 내가 좋아하는 것?

주문을 마감하고 싶은 시간을 입력하세요. 주석 필드는 문자열이어야 하므로 값 앞에 ""+가 있습니다. 예를 들어:

""+(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())