코딩하는 방법? - 페이지 284

 

Time Filter Close All에 대한 솔루션을 정렬했습니다.

외부 변수

extern string timefilter="Time Filter";

extern int gmtshift=1; // gmt offset of the broker

extern bool generalfilter=false; // enable time filter

extern int starthour=7; // start hour to trade after this hour

extern int startminutes=0; // minutes of the start hour

extern int endhour=21; // stop to trade after this hour

extern int endminutes=0; // minutes of the start hour

extern bool tradesunday=true; // trade on sunday

extern bool fridayfilter=false; // enable special time filter on friday

extern int fridayhour=21; // stop to trade after this hour

extern int fridayminutes=0; // minutes of the friday hour

[/CODE]

int nstarthour,nendhour,nfridayhour;

string istarthour,istartminutes,iendhour,iendminutes,ifridayhour,ifridayminutes;

datetime tstart,tend,tfriday;[/CODE]

Place Code in Start,

[CODE] if(generalfilter){

nstarthour=starthour+(gmtshift);if(nstarthour>23)nstarthour=nstarthour-24;

if(nstarthour<10)istarthour="0"+nstarthour;

if(nstarthour>9)istarthour=nstarthour;

if(startminutes<10)istartminutes="0"+startminutes;

if(startminutes>9)istartminutes=startminutes;

tstart=StrToTime(istarthour+":"+istartminutes);

nendhour=endhour+(gmtshift);if(nendhour>23)nendhour=nendhour-24;

if(endhour<10)iendhour="0"+nendhour;

if(endhour>9)iendhour=nendhour;

if(endminutes<10)iendminutes="0"+endminutes;

if(endminutes>9)iendminutes=endminutes;

tend=StrToTime(iendhour+":"+iendminutes);

}

if(fridayfilter){

nfridayhour=fridayhour+(gmtshift);if(nfridayhour>23)nfridayhour=nfridayhour-24;

if(nfridayhour<10)ifridayhour="0"+nfridayhour;

if(nfridayhour>9)ifridayhour=nfridayhour;

if(fridayminutes<10)ifridayminutes="0"+fridayminutes;

if(fridayminutes>9)ifridayminutes=fridayminutes;

tfriday=StrToTime(ifridayhour+":"+ifridayminutes);

}

if((generalfilter && (nstarthour<nendhour && TimeCurrent()tend) || (nstarthour>nendhour && TimeCurrent()tend))

|| (tradesunday==false && DayOfWeek()==0) || (fridayfilter && DayOfWeek()==5 && TimeCurrent()>tfriday))

{

CloseAll();

Comment("Non-trading Hours All Positions Closed");

return(0);

}

and the CloseAll function.

[CODE]

void CloseAll(){

int total = OrdersTotal();

for(int i=total-1;i>=0;i--){

OrderSelect(i, SELECT_BY_POS);

int type = OrderType();

bool result = false;

switch(type){

//Close opened long positions

case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Lime); break;

//Close opened short positions

case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, LightGreen );

} if(result == false){

Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );

Sleep(3000);

}

}

return(0);

}

힌트와 팁 감사합니다

 

손절매

기드데이

나는 최대 dd와 거래당 백분율을 기반으로 SL을 계산하는 실험을 시도했습니다.

double lotSize = NormalizeDouble(Kellylot(),2);

double Pip = Point;

if(Digits==3 || Digits==5) Pip = 10*Point;

double Bal = AccountBalance(); // $1000

double TV = MarketInfo(Symbol(), MODE_TICKVALUE); // $1

double Risk = 2; // 2%

double MaxDD = 10; // 10%

double RiskCapital = Bal*MaxDD/100; // Total Exposure 10% of $1000 = $100

double RPT = Bal*Risk/100; // 2% of $1000 = $20

double stopLoss = NormalizeDouble(RPT/TV*lotSize/Pip,Digits); //$20/1*0.01/10 = 0.02000

double Positions = MathAbs(RiskCapital/RPT); // Maximum 5 positions 100 / 20

아이디어는 쌍과 쌍에 따라 개별 tickvalue와 lotsize 2% sl을 설정할 수 있다는 것입니다.

나는 그것이 옳다고 생각하지만 가능하다면 누군가가 그것을 확인 했으면합니다.

 
Beno:
기드데이

나는 최대 dd와 거래당 백분율을 기반으로 SL을 계산하는 실험을 시도했습니다.

double lotSize = NormalizeDouble(Kellylot(),2);

double Pip = Point;

if(Digits==3 || Digits==5) Pip = 10*Point;

double Bal = AccountBalance(); // $1000

double TV = MarketInfo(Symbol(), MODE_TICKVALUE); // $1

double Risk = 2; // 2%

double MaxDD = 10; // 10%

double RiskCapital = Bal*MaxDD/100; // Total Exposure 10% of $1000 = $100

double RPT = Bal*Risk/100; // 2% of $1000 = $20

double stopLoss = NormalizeDouble(RPT/TV*lotSize/Pip,Digits); //$20/1*0.01/10 = 0.02000

double Positions = MathAbs(RiskCapital/RPT); // Maximum 5 positions 100 / 20

아이디어는 쌍과 쌍에 따라 개별 tickvalue와 lotsize 2% sl을 설정할 수 있다는 것입니다.

나는 그것이 옳다고 생각하지만 가능하다면 누군가가 그것을 확인했으면합니다.

잘했어 베노

항상 물고기보다 낚싯대를주는 것이 좋습니다. 몇 가지 의견으로 도움을 드릴 수 있게 되어 매우 기쁩니다.

정지 손실 에 관해서는 아이디어가 좋지만 반대로 생각해보십시오.

첫 번째 세트 손절매

두 번째 설정 거래 규모

이러한 방식으로 시스템 진입/출구를 시장 조건에 맞출 수 있으며 계정에서 X% 이상 위험을 감수하지 않지만 탈출은 위험 비율 대신 시스템 논리에 따라 달라집니다.

 
Kalenzo:
잘했어 베노

항상 물고기보다 낚싯대를주는 것이 좋습니다. 몇 가지 의견으로 도움을 드릴 수 있게 되어 매우 기쁩니다.

정지 손실에 관해서는 아이디어가 좋지만 반대로 생각해보십시오.

첫 번째 세트 손절매

두 번째로 설정된 거래 규모

이러한 방식으로 시스템 진입/출구를 시장 조건에 맞출 수 있으며 계정에서 X% 이상 위험을 감수하지 않지만 탈출은 위험 비율 대신 시스템 논리에 따라 달라집니다.

기드데이 칼렌조

SELL 주문 을 여는 중 오류가 발생합니다. EA와의 잘못된 중지가 데모 및 라이브 계정에 있고 거래가 열리지 않습니다. 그러나 테스터에서 잘 작동하며 오류 메시지가 없습니다.

EURUSD,매일: 1.43348 sl: 1.43895 tp: 0.00000 ok에서 0.01 EURUSD 구매 수정 #1

SL 0.00547 포인트 차이

나는 확인했다

MODE_FREEZELEVEL 0.0000

MODE_STOPLEVEL 0.0000

double lotSize = NormalizeDouble(Kellylot(),2);

double Bal = AccountFreeMargin();

double TV = MarketInfo(Symbol(), MODE_TICKVALUE);

double Risk = 0.3;

double MaxDD = 10;

double RiskCapital = Bal*MaxDD/100;

double RPT = Bal*Risk/100;

double stopLoss = NormalizeDouble((RPT/TV)*lotSize/pips2dbl,Digits);

double Positions = MathAbs(RiskCapital/RPT);

double SL;

//---- sell conditions

if(sellsig && ttime!=Time[0]){

double bid = NormalizeDouble(Bid, Digits);

SL = NormalizeDouble(Bid + stopLoss * pips2dbl, Digits);

res=OrderSend(symbol,OP_SELL,lotSize,bid,slippage * pips2dbl,SL,0,"Pivot_Sell",SpecificMagic,0,Red);

if( res<0 )

{

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

Print("Bid=" + DoubleToStr(bid,Digits) + " : SL=" + DoubleToStr(SL,Digits));

res=0;

}

else //now enter in the SL and TP via OrderModify to make compatible with ECN broker

{

if (OrderSelect(res, SELECT_BY_TICKET))

{

if (!OrderModify(res, Bid, SL, 0, 0, Red))

Print("Error modifying order");

}

}

ttime=Time[0];

return;

}

//---- buy conditions

if(buysig && ttime!=Time[0]) {

double ask = NormalizeDouble(Ask, Digits);

SL = NormalizeDouble(Ask - stopLoss * pips2dbl, Digits);

res=OrderSend(symbol,OP_BUY,lotSize,ask,slippage * pips2dbl,SL,0,"Pivot Buy",SpecificMagic,0,Blue);

if( res<0 )

{

Print("Error opening BUY order : ",ErrorDescription(GetLastError()));

Print("Ask=" + DoubleToStr(ask,Digits) + " : SL=" + DoubleToStr(SL,Digits));

res=0;

}

else //now enter in the SL and TP via OrderModify to make compatible with ECN broker

{

if (OrderSelect(res, SELECT_BY_TICKET))

{

if (!OrderModify(res, Ask, SL, 0, 0, Blue))

Print("Error modifying order");

}

}

ttime=Time[0];

return;

}

}

나는 전에 이것을 접한 적이 없다.

건배

베노

 

래치/언래치 기능

mq4에서 래치/래치 해제 기능을 코딩하는 방법이 있습니까? 조건에 따라 약간의 참을 래치하고 다른 조건에 의해 래치가 해제될 때까지 이 값을 저장합니다.

cmfxtrader

 
Beno:
기드데이 칼렌조

SELL 주문을 여는 중 오류가 발생합니다. EA와의 잘못된 중지가 데모 및 라이브 계정에 있고 거래가 열리지 않습니다. 그러나 테스터에서 잘 작동하며 오류 메시지가 없습니다.

EURUSD,매일: 1.43348 sl: 1.43895 tp: 0.00000 ok에서 0.01 EURUSD 구매 수정 #1

SL 0.00547 포인트 차이

나는 확인했다

MODE_FREEZELEVEL 0.0000

MODE_STOPLEVEL 0.0000

double lotSize = NormalizeDouble(Kellylot(),2);

double Bal = AccountFreeMargin();

double TV = MarketInfo(Symbol(), MODE_TICKVALUE);

double Risk = 0.3;

double MaxDD = 10;

double RiskCapital = Bal*MaxDD/100;

double RPT = Bal*Risk/100;

double stopLoss = NormalizeDouble((RPT/TV)*lotSize/pips2dbl,Digits);

double Positions = MathAbs(RiskCapital/RPT);

double SL;

//---- sell conditions

if(sellsig && ttime!=Time[0]){

double bid = NormalizeDouble(Bid, Digits);

SL = NormalizeDouble(Bid + stopLoss * pips2dbl, Digits);

res=OrderSend(symbol,OP_SELL,lotSize,bid,slippage * pips2dbl,SL,0,"Pivot_Sell",SpecificMagic,0,Red);

if( res<0 )

{

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

Print("Bid=" + DoubleToStr(bid,Digits) + " : SL=" + DoubleToStr(SL,Digits));

res=0;

}

else //now enter in the SL and TP via OrderModify to make compatible with ECN broker

{

if (OrderSelect(res, SELECT_BY_TICKET))

{

if (!OrderModify(res, Bid, SL, 0, 0, Red))

Print("Error modifying order");

}

}

ttime=Time[0];

return;

}

//---- buy conditions

if(buysig && ttime!=Time[0]) {

double ask = NormalizeDouble(Ask, Digits);

SL = NormalizeDouble(Ask - stopLoss * pips2dbl, Digits);

res=OrderSend(symbol,OP_BUY,lotSize,ask,slippage * pips2dbl,SL,0,"Pivot Buy",SpecificMagic,0,Blue);

if( res<0 )

{

Print("Error opening BUY order : ",ErrorDescription(GetLastError()));

Print("Ask=" + DoubleToStr(ask,Digits) + " : SL=" + DoubleToStr(SL,Digits));

res=0;

}

else //now enter in the SL and TP via OrderModify to make compatible with ECN broker

{

if (OrderSelect(res, SELECT_BY_TICKET))

{

if (!OrderModify(res, Ask, SL, 0, 0, Blue))

Print("Error modifying order");

}

}

ttime=Time[0];

return;

}

}

나는 전에 이것을 접한 적이 없다.

건배

베노

아마도 당신의 손절매가 너무 가깝습니다. 손절매 값 에 10을 곱해 보십시오. 4자리 브로커에서 시스템을 테스트하고 5자리 브로커에서 거래할 때 자주 발생하는 문제입니다. 5자리 브로커에서 테스트할 수도 있지만 브로커에 연결하지 마십시오(오프라인 모드에서). 그러면 메타트레이더는 이전 설정(4자리에서)을 갖게 됩니다.

이 줄에서 먼저 :

NormalizeDouble(Ask - stopLoss * pips2dbl, Digits);

이 값 인쇄 => stopLoss*pips2dbl

그러면 손절매의 실제 가치를 알게 될 것입니다.

20 또는 10과 같으면 포인트 값으로 곱해야 함을 의미합니다.

NormalizeDouble(Ask - (stopLoss * pips2dbl) *포인트, 자릿수);

0.00009와 같으면 0.0009여야 하기 때문에 10만큼 곱해야 합니다(물론 9핍 정지 손실을 설정하려는 경우).

 
cmfxtrader:
mq4에서 래치/래치 해제 기능을 코딩하는 방법이 있습니까? 조건에 따라 약간의 참을 래치하고 다른 조건에 의해 래치가 해제될 때까지 이 값을 저장합니다. cmfxtrader

내가 당신을 올바르게 이해했는지 확실하지 않습니다. ea( 기능 )의 특정 부분을 켜고 끄거나 ea B에서 취한 조치로 ea A의 기능을 비활성화하고 싶습니까? 이 방법 또는 다른 방법, 둘 다 가능합니다.

 

화폐 가치를 가격으로 변환(이익 목표 계산용)

거래 바구니의 주어진 이익 목표에 대한 가격 값을 반환하는 함수를 프로그래밍하고 싶지만 어려움이 있습니다. 내가 도달하고 싶은 목표는 이익 목표를 나타내는 화면에 그려지는 단순한 수평선 입니다. 그러나 수익 목표는 가격 가치가 아닌 화폐 가치의 형태로 사용자가 정의할 수 있는 변수입니다. (예: 목표 = 목표 = 1.2000 대신 € 100)

내가 지금까지 가지고 있는 루틴:

(내 계정은 EUR로 되어 있습니다!)

1) USDJPY에 대해 여러 매수 포지션을 연다고 가정해 보겠습니다(예시 상황을 만들기 위해 임의의 포지션에서)

2) 바스켓의 평균 시가를 계산하고(가상적으로 1.1500이라고 가정해 봅시다) 이를 나타내는 수평선을 표시합니다.

3) 수익 목표가 설정된 변수가 있습니다. 목표 = € 100라고 가정해 보겠습니다.

4) 나는 바구니 이익 >= 목표일 때 모든 열린 포지션을 성공적으로 청산할 수 있습니다

사이의 단계가 누락되었습니다. targetPrice를 반환하는 double targetPrice(){} 함수가 필요합니다. 수평선을 그리는 것이 문제가 아닙니다. targetPrice를 계산하는 것이 중요합니다!

targetPrice = 평균 공개 가격 + 돈 가치 목표(€100)

그래서 기본적으로 알고 싶은 것: 돈 가치를 핍으로 변환하는 방법 . 이런 식으로 평균 가격에 핍을 추가할 수 있고 내 targetPrice가 있습니다. 이것은 또한 내가 EUR 계정을 가지고 있고 USDJPY를 거래하고 있다는 사실을 고려해야 한다는 것을 기억하십시오. 거기에도 함정이 있는 것 같은데요?

 

ECN SL이 작동하지 않음

기드데이

ECN에서 작동할 EA를 설정하려고 합니다. SL과 TP가 배치/수정되어야 한다는 것을 이해하고 설정이 정확하다고 생각합니다. 주문은 지금 열리지만 SL은 배치되지 않습니다. extern double StopLoss = 100; 어떤 도움이 될 것입니다.

//---- buy conditions

if(buysig && ttime!=Time[0]) {

ticket = OrderSend(Symbol(), OP_BUY, lotSize, MarketInfo(Symbol(), MODE_ASK), 2, 0, 0, "", 12345);

if(ticket > -1){

if (!OrderSelect(ticket, SELECT_BY_TICKET)) {

error_code = GetLastError();

Print("Error: " + ErrorDescription(error_code));

return(-1);

}

Print("order "+ticket+" successfully opened");

//now enter in the SL and TP via OrderModify to make compatible with ECN broker

SL = MarketInfo(Symbol(), MODE_ASK) - (StopLoss * pips2points);

Print("Ask = " + DoubleToStr(Ask,Digits) + " : SL = " + DoubleToStr(SL,Digits));

//round to nearest Tickvalue

SL = DoubleRound(SL, MarketInfo(Symbol(), MODE_TICKSIZE));

Print("SL rounded: " + SL);

if(!OrderModify(ticket, entry_price, SL, 0, Blue)) {

error_code = GetLastError();

Print("Error: " + ErrorDescription(error_code));

return(-1);

}

Print("Stoploss successfully set");

ttime=Time[0];

return(0);

}

}

}

//Tickvalue Rounding

double DoubleRound(double number, double step){

double mod = MathMod(number, step);

if(mod < step/2.0)

step = 0;

double rounded = number - mod + step;

return (rounded);

}
 

,,,,,,,,,,,,,,,,,,,,,,,

파일:
test_ea.txt  10 kb
aizig.ex4  10 kb