기본적인 질문 ... - 페이지 8

 

이 스레드를 보십시오: https://www.mql5.com/en/forum/178677

 
newdigital:
이 스레드를 보십시오: https://www.mql5.com/en/forum/178677

파일 열기 지침 및 다운로드 링크에 대해 정말 감사합니다.

 

10포인트3

프로그래머 여러분!

우리는 10points3 EA에서 세 번째 거래가 열릴 때 첫 번째 거래가 닫힐 필요가 있습니다. 저는 시도하고 있지만 여전히 모든 포지션을 닫고 있습니다.

실제로 우리는 다음을 가지고 있습니다:

if (이전OpenOrders>OpenOrders)

{

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

{

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

모드=주문 유형();

if (OrderSymbol()==Symbol() && OrderMagicNumber() == 매직)

{

if (mode==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Blue); }

if (mode==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Red); }

리턴(0);

}

나는 이것을 하기 위해 생각하고 있었다:

1. 두 번째 거래가 열릴 때 첫 번째 거래의 매직 번호를 변경합니다(예: magicnumber+1).

2. 세 번째 거래가 열리면 첫 번째 거래를 닫고 매직넘버+1을 할당합니다.

내 말이 맞아?

또는 나중에 청산하기 위해 열린 첫 번째 거래를 식별할 수 있는 다른 방법은 무엇입니까?

당신이 나를 안내하거나 변경을 할 수 있다면, 나는 프로그래머가 아니기 때문에 더 나은, 나는 단지 배우는 중입니다.

이 변화가 바로 Holly Grail 의 시작이 될 것입니다!!!

 

10포인트3

죄송합니다, EA.

그리고 이 스레드에 있습니다.

https://www.mql5.com/en/forum/174975

감사해요!

파일:
10p3v0.03_1.mq4  12 kb
 

프로그래밍 도움말 - 반환 연산자

안녕하세요

저는 mt4 프로그래밍의 초보자이며 이제 종종 void 함수 에서 메인 프로그램 "start()"로 커밋 변수에 대한 솔루션을 찾으려고 합니다.

아래에서 샘플을 볼 수 있으며 질문은 "CountOpenSell", "CountOpenBuy", "ProfitSell" 및 "ProfitBuy" 변수의 값을 어떻게 start() - mainprogram에 커밋할 수 있습니까?

내 제안을 추가했지만(반환은 굵은 글씨로 표시) 그것이 올바른지, "start()" 메인 프로그램에 대한 올바른 코드는 무엇인지 모르겠습니다???

내 나쁜 영어와 모든 도움에 대해 유감스럽게 생각합니다.

정말 감사합니다

문안 인사

외환2006

무효 CallBuySellProfit()

{ 이익 매수=0;

ProfitSell=0;

CountOpenSell=0;

CountOpenBuy=0;

(i=OrdersTotal()-1;i>=0;i--)

{if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

{

if (OrderType()==OP_SELL) {ProfitSell = ProfitSell + OrderProfit();CountOpenSell++;}

if (OrderType()==OP_BUY) {ProfitBuy = ProfitBuy + OrderProfit();CountOpenBuy++;}

}

else Print( "주문 선택 시 오류 발생 ", GetLastError());

}

반환(CountOpenSell);

반환(CountOpenBuy);

반환(ProfitSell);

반환(ProfitBuy);

}

 

forex2006 프로그래밍 도움말 - 연산자 반환

안녕하세요 forex2006,

mql을 정말로 배우고 싶다면 codersguru 튜토리얼을 시도해 보라고 제안했습니다. 바로 여기에서 시작했습니다. 귀하의 질문에 따르면 void 함수 는 값을 반환할 수 없습니다. void 함수에서 값을 가져오려면 전역 변수를 사용해야 합니다. 값을 가져오는 가장 좋은 방법은 원하는 값을 나타내기 위해 매개변수와 함께 사용되는 값을 반환하는 함수를 사용하는 것입니다. 아래의 간단한 예입니다. 나중에 어렵게 만들 수 있으므로 함수에서 전역 변수를 사용하지 마십시오.

도움이 되기를 바랍니다.

정수 시작()

{

이중 ProfitBuy = CallBuySellProfit(OP_BUY,false);

이중 ProfitSell = CallBuySellProfit(OP_SELL,false);

정수 CountOpenBuy = CallBuySellProfit(OP_BUY,true);

정수 CountOpenSell = CallBuySellProfit(OP_SELL,true);

Comment( "ProfitBuy: "+DoubleToStr(ProfitBuy,2) +"\n"+

"ProfitSell: "+DoubleToStr(ProfitSell,2) +"\n"+

"CountOpenBuy: "+DoubleToStr(CountOpenBuy,2)+"\n"+

"CountOpenSell: "+DoubleToStr(CountOpenSell,2)+"\n"+

"");

반품;

}

이중 CallBuySellProfit(int iOrderType, bool bCount)

{

이중 dProfit = 0;

정수 iCount = 0;

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

{

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

{

if(OrderType()==iOrderType)

{

dProfit = dProfit + OrderProfit();

아이카운트++;

}

}

또 다른

{

Print( "주문 선택 시 오류", GetLastError());

}

}//끝

if(bCount) return(iCount);

그렇지 않으면 반환(dProfit);

}//CallBuySellProfit 종료

 

같은 바에서 EA 거래 중지

안녕하세요, 어쨌든 EA에서 거래가 이미 해당 막대에 배치되었는지 확인한 다음 새 막대가 나올 때까지 더 이상 거래를 배치하지 않도록 코드를 입력하시겠습니까?

고맙습니다

 

matrixebiz, 양초가 닫히기 전에 같은 양초에서 거래가 열리고 닫힐 가능성을 생각해 보셨습니까? 기록 목록도 확인해야 합니다.

저는 항상 제가 작성한 이 작은 기능 을 모든 EA에 이식했습니다. 아마도 여러분도 이 기능이 유용하다는 것을 알게 될 것입니다.

bool DecideToOpenTrade()

{

int total = OrdersTotal();

if (total > 0)

{

for(int cnt=0;cnt<total;cnt++)

{

if(OrderSelect(cnt,SELECT_BY_POS))

{

if(OrderSymbol()==Symbol() && OrderMagicNumber() == EA_MAGIC_NUM)

{

return (false);

}

}

}

}

// in case trades has already opened and closed within the candle

int histotal = OrdersHistoryTotal();

if (histotal > 0)

{

for(cnt=0;cnt<histotal;cnt++)

{

if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))

{

if(OrderSymbol()==Symbol() && OrderMagicNumber() == EA_MAGIC_NUM)

{

if (Time[0] <= OrderOpenTime()) // don't open a new position if we're still on the same candle

{

return (false);

}

}

}

}

}

return (true);

}

int start()

{

// some time check codes first.. blah blah

// ...

// ...

// ...

// check signals

if (Should_Buy())

{

if (DecideToOpenTrade())

{

//... trade opening codes here

}

}

if (Should_Sell())

{

if (DecideToOpenTrade())

{

//... trade opening codes here

}

}

}

참고: 이 함수는 고유한 값을 EA_MAGIC_NUM으로 설정했다고 가정합니다. 그렇게 하면 수표는 다른 EA가 개설한 거래를 확인하지 않습니다.

Should_Buy() 및 Should_Sell()은 매수 또는 매도 신호가 발생했는지 확인하기 위해 모든 EA에서 생성한 함수입니다.

도움이 되었기를 바랍니다. 추가 설명이 필요하면 저에게 PM하십시오.

문안 인사,

 

아래에 업데이트 된 게시물 ...

 

이것은 나를 위해 일하는 것 같습니다 고맙습니다

void DesideToOpen()

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

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

{

int total = OrdersTotal();

if (total > 0)

{

for(int cnt=0;cnt<total;cnt++)

{

if(OrderSelect(cnt,SELECT_BY_POS))

{

if(OrderComment() == EA_Name + MagicNumber) DecideToOpenTrade = false;

}

}

}

// in case trades has already opened and closed within the candle

int histotal = OrdersHistoryTotal();

if (histotal > 0)

{

for(cnt=0;cnt<histotal;cnt++)

{

if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))

{

if(OrderComment() == EA_Name + MagicNumber)

{

if (Time[0] <= OrderOpenTime()) DecideToOpenTrade = false; // don't open a new position if we're still on the same candle

}

}

}

}

}