코딩 도움말..경보 대신 필터링할 지표를 얻으려면 어떻게 해야 합니까? - 페이지 8

 

우다맨!

그래서 ....이것을 제대로 이해했는지 봅시다 ...

이동 평균의 백 크로스를 기반으로 포지션을 청산하려면 이 코드만 있으면 됩니다....

if(currentlong>minorts) {CloseOrder(OP_SELL); // 모든 판매 주문 닫기}

여기서 currentlong은 20ema이고 minorts는 150ema이므로 오픈 포지션이 되었거나 IS가 숏 포지션을 취했고 이제 20ema는 150ema 위로 이동하고 있습니다. 이는 매도 거래의 종가 신호입니다.

그리고...

if (currentlong<minorts) {CloseOrder(OP_BUY); // 모든 구매 주문 닫기}

여기서 currentlong은 20ema이고 minorts는 150ema이므로 오픈 포지션은 롱 포지션이 되었을 것입니다.

그래서 나는 이 두 줄을 넣을 수 있었다

if (currentlong<minorts) {CloseOrder(OP_BUY); // 모든 구매 주문 닫기}

if(currentlong>minorts) {CloseOrder(OP_SELL); // 모든 판매 주문 닫기}

입력 코드 바로 다음과 이와 같은 다른 모든 닫기 및 후행 중지 전에? 그리고 작동할까요?

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

}

//+---------end of order entry-------------------------+

//+------close on moving average cross-----------------+

if(currentlong<minorts) {CloseOrder(OP_BUY);} // Close all buy orders}

if(currentlong>minorts) {CloseOrder(OP_SELL);} // Close all sell orders}

//+--------end of close on moving average cross--------+

//+-------------------------Trailing Stop Code------------------------------------+

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

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) {

if(OrderType()==OP_BUY){

컴파일러는 다음과 같이 말합니다.

')' - 잘못된 매개변수 개수 C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (85, 43)

')' - 잘못된 매개변수 개수 C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (86, 44)

그것은 그 라인을 좋아하지 않습니다. 의사소통이 잘 안되는 것 같아요.

 

갑자기 메타에디터의 검색 기능이 작동하니 재미있네요??

bool OrderCloseBy( int 티켓, int 반대편, color Color=CLR_NONE)

열린 주문을 다른 반대의 열린 주문으로 마감합니다. 함수가 성공하면 반환 값은 true입니다. 함수가 실패하면 반환 값은 false입니다. 자세한 오류 정보를 얻으려면 GetLastError() 를 호출하십시오 .

매개변수:

티켓 - 주문 티켓의 고유 번호입니다.

반대 - 반대 주문 티켓의 고유 번호입니다.

색상 - 차트에서 닫는 화살표의 색상입니다. 매개변수가 없거나 CLR_NONE 값이 있으면 닫는 화살표가 차트에 그려지지 않습니다.

견본:

if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)

{

OrderCloseBy(order_id, 반대 ID);

반환(0);

}

그래서 이런 상상을 하고 있는데...

if(currentlong<minorts)

{

OrderCloseBy(order_id,opposite_id);

return(0);

}[/PHP]

thing is this doesn't distinguish what kind of position I'm into first, long or short. So if I put the opposite side of this with it...like this...

[PHP] if(currentlong>minorts)

{

OrderCloseBy(order_id,opposite_id);

return(0);

}

함께 그들은 모든 것을 닫을 것입니다 그렇죠? 더 많은 것이 있어야 합니다...나는 아직 완전한 문장을 전달하기 위해 실제로 말하지 못하는 어린아이처럼, 밖으로 나갈 수 없는 완전한 생각이 내 안에 있을 때 좌절감을 느낍니다.

 
elihayun:
나는 이것을 잊는다
void CloseOrder(int ticket,double numLots,double close_price)

{

int CloseCnt, err;

// try to close 3 Times

CloseCnt = 0;

color clr = Violet;

if (OrderType() == OP_SELL)

clr = Orange;

while (CloseCnt < 3)

{

if (OrderClose(ticket,numLots,close_price,Slippage,clr))

{

CloseCnt = 3;

}

else

{

err=GetLastError();

Print(CloseCnt," Error closing order : (", err , ") " + ErrorDescription(err));

if (err > 0) CloseCnt++;

}

}

}

[/PHP]

and dont forget to add this line after #property link

[PHP]#property link "http://www.elihayun.com"

#include

이것은 무엇을합니까? 호출할 수 있게 하려면 다운로드해야 하는 다른 것입니까? 이것이 하는 일, 롱 포지션과 숏 포지션을 구별하는 방법을 이해하고 싶습니다. 배우고 싶습니다.

 
Aaragorn:
우다맨!

그래서 ....이것을 제대로 이해했는지 봅시다 ...

그래서 나는 이 두 줄을 넣을 수 있었다

if (currentlong<minorts) {CloseOrder(OP_BUY); // 모든 구매 주문 닫기}

if(currentlong>minorts) {CloseOrder(OP_SELL); // 모든 판매 주문 닫기}

//+------이동평균선 종가---+

if(currentlong<minorts) {CloseOrder(OP_BUY);} // 모든 구매 주문 닫기}

if(currentlong>minorts) {CloseOrder(OP_SELL);} // 모든 판매 주문 닫기}

if(주문유형()==OP_BUY){[/PHP]

컴파일러는 다음과 같이 말합니다.

')' - 잘못된 매개변수 개수 C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (85, 43)

')' - 잘못된 매개변수 개수 C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (86, 44)

그것은 그 라인을 좋아하지 않습니다. 의사소통이 잘 안되는 것 같아요.

CloseOrder가 아닌 끝에 s 를 사용하여 CloseOrder를 호출해야 합니다(하나의 주문만 마감)

 
Aaragorn:
이것은 무엇을합니까? 호출할 수 있게 하려면 다운로드해야 하는 다른 것입니까? 이것이 하는 일, 롱 포지션과 숏 포지션을 구별하는 방법을 이해하고 싶습니다. 배우고 싶습니다.

MQL4의 일부이며 ErrorDescription 기능 을 포함합니다.

 
elihayun:
MQL4의 일부이며 ErrorDescription 기능을 포함합니다.

좋아, 나는 여전히 이동 평균 크로스백을 기반으로 마감할 수 있는 일부 코드가 필요합니다.

 

이 코드 조각은 당신이 가야 할 것입니다 ...

물론 자신의 필요에 맞게 수정해야 합니다. 그러나 이것은 시작점을 제공해야 합니다. 이 루틴은 SMA1 라인을 후행 정지점으로 사용합니다. 그러니 이 아이디어를 가지고 무엇을 만들 수 있는지 보십시오.

//these two lines within start()

SMA1 = iMA(NULL,TimePeriod,SlowPeriod,0,SlowMode,SlowPrice,1);

TrailingAlls(TrailStart, SMA1);

// trailing routine using the value of SMA1

void TrailingAlls(int start, double currvalue)

{

int profit;

double stoptrade;

double stopcal;

// if(stop==0) return;

int trade;

for(trade=OrdersTotal()-1;trade>=0;trade--)

{

if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))

continue;

if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)

continue;

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

{

if(OrderType()==OP_BUY)

{

profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Bid-(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);

}//Long

if(OrderType()==OP_SELL)

{

profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Ask+(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);

}//Shrt

}

}//for

}

 

내가 먼저 이것을 알아낼 수 있다면 후행 정지 닫기가 아마도 유용할 것입니다....

elihayun이 나에게 준 이 스니펫은 누군가가 ma backcross와 올바른 방향에 반응하도록 하는 방법을 알아낼 수 있다면 효과가 있을 수 있다고 생각합니다. 나는 op_buy 및 op_sell과 혼동됩니다. 롱 포지션을 청산하는 데 사용하고 숏 포지션을 청산하는 데 사용합니다.

//+------close on moving average cross-----------------+

void CloseOrders(int op)

{

int tik[30], t = 0;

for(int i =0;i<OrdersTotal();i++){

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

if(OrderSymbol()==Symbol() && MagicNum==OrderMagicNumber() && OrderType() == op){

tik[t] = OrderTicket(); t++;

}

}

}

for (i = 0; i<t; i++)

{

if(OrderSelect(tik,SELECT_BY_TICKET)){

double prc = Bid;

if (op == OP_SELL) prc = Ask;

CloseOrder(tik, OrderLots(), prc);

}

}

}

//+--------end of close on moving average cross--------+[/PHP]

I think I see that at this point in the code it has selected the orders by ticket and it's figuring out to set the close price based on the bid or the ask. So I'm not sure which is which for long or short positions. If the ticket is a long position that means it was opened at the ask price right? so it should close on the bid price? so this snippet is saying use the bid price to close so I assume that's for a long position. THEN it asks the

if (op == OP_SELL) prc = Ask;

so I assume this is the first place in this code where we now know if we are looking at a long or a short position ticket.

Then it moves immediately to close. But if I can put my closing criteria in here BEFORE it does that???

here it is as I received it...

for (i = 0; i<t; i++)

{

if(OrderSelect(tik,SELECT_BY_TICKET)){

double prc = Bid;

if (op == OP_SELL) prc = Ask;

CloseOrder(tik, OrderLots(), prc);

}[/PHP]

so what I'm thinking is that this is the place in the code where I should insert the moving average criteria to trigger the close for long or short positions. Something like this...

[PHP]for (i = 0; i<t; i++)

{

if(OrderSelect(tik,SELECT_BY_TICKET)){

double prc = Bid;

if (op == OP_SELL) prc = Ask;

if (prc == Bid && currentlong minorts);

CloseOrder(tik, OrderLots(), prc);

}

Will this do it? I think it might if I understand correctly..

Please tell me coders if this is correct??

I think this connects the direction of the moving average cross to the type of position that the ticket is identifed as being.

if the bid is to close long positions so we know the ticket is for a long position then it can close long positions if the currentlongema < minortsEMA because it knows that the ticket is for a long position and the 20ema has moved below the 150ema.

If the ask is for closing short positions and the ticket is identified as a short position because it wants to close at the ask price and the currentlongEMA has moved above the minortsEMA because it knows the ticket is for a short position and the 20ema has moved above the 150ema.

if that is correct will adding this line to the code,

if (prc == Bid && currentlong minorts)

stop it from closing UNLESS each ticket fits this criteria?

...that for the long position the 20ema150ema?

if that is ok then the logic for deciding to close long or short based on the emacrossback is ok and it's worth fixing these errors

I get these errors from the compiler...

[PHP]Compiling 'whatever.mq4'...

'(' - function definition unexpected C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (85, 17)

'MagicNum' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (90, 40)

'op' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (90, 87)

'tik' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (91, 13)

't' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (91, 17)

't' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (91, 37)

't' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (96, 18)

'tik' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (98, 22)

'op' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (100, 14)

'tik' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (102, 21)

'cnt' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 5)

'cnt' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 5)

'cnt' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 11)

'cnt' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 11)

'total' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 15)

'total' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 15)

'cnt' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 21)

'cnt' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 21)

'{' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 28)

'i' - variable is already defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (135, 11)

'}' - unbalanced parentheses C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (165, 1)

16 error(s), 5 warning(s)

 

모든 회원에게 제안합니다. "카운트업" 루틴을 사용하여 거래를 마감하지 마십시오. 예를 들어 다음과 같은 것을 사용하지 마십시오.

(i = 0; i<t; i++)

{

if(주문선택(tik,SELECT_BY_TICKET)){

이중 가격 = 입찰가;

if (op == OP_SELL) prc = 묻다;

CloseOrder(tik, OrderLots(), prc);

}

여러 주문을 사용하는 경우 마지막 주문이 마감되지 않습니다. "카운트다운" 루틴을 사용합니다. 다음은 이 짜증나는 "버그"를 처음 발견했을 때 Metaquotes 개발자와의 토론입니다.

http://www.metaquotes.net/forum/2018/

 
Maji:
이 코드 조각은 당신이 가야 할 것입니다 ...

물론 자신의 필요에 맞게 수정해야 합니다. 그러나 이것은 시작점을 제공해야 합니다. 이 루틴은 SMA1 라인을 후행 정지점으로 사용합니다. 그러니 이 아이디어를 가지고 무엇을 만들 수 있는지 보십시오.

//these two lines within start()

SMA1 = iMA(NULL,TimePeriod,SlowPeriod,0,SlowMode,SlowPrice,1);

TrailingAlls(TrailStart, SMA1);

// trailing routine using the value of SMA1

void TrailingAlls(int start, double currvalue)

{

int profit;

double stoptrade;

double stopcal;

// if(stop==0) return;

int trade;

for(trade=OrdersTotal()-1;trade>=0;trade--)

{

if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))

continue;

if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)

continue;

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

{

if(OrderType()==OP_BUY)

{

profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Bid-(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);

}//Long

if(OrderType()==OP_SELL)

{

profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Ask+(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);

}//Shrt

}

}//for

}

매우 감사합니다. 나는 이것을 해부하고 내가 그것을 할 수 있는 것을 보기를 고대한다...

내가 emacrossback을 먼저 작동시키려는 이유는 기본적으로 손절매와 기본 출구 전략이 될 것이기 때문입니다.

그것이 작동하면 수익성을 높이기 위해 이와 같은 것을 추가할 것입니다. 그러나 나는 그것을 엉망으로 만들지 않고 손절매 를 가질 수 없기 때문에 큰 손절매 매개변수를 기꺼이 허용하지 않기 때문에 이동 평균 크로스백 마감이 먼저 작동하도록 하고 싶습니다. 지금까지 크로스백 마감으로 수행한 작업을 확인할 수 있는 기회가 있다면 감사하겠습니다.