코딩 도움말 - 페이지 156

 
Marco320:
친애하는 MLaden,

다음 인디는 내 라이브 계정과 Markets.com(CFD's)의 데모에서 차트에 올릴 수 있습니다. 데모의 Liquid Markets에서 차트에 올리는 데 문제가 있습니다. Liquid는 다양한 상품 옵션(특히 MT4의 선물 )을 제공하기 때문에 해당 플랫폼의 차트에 포함하고 싶습니다. 내가 찾을 수 없기 때문에 이 문제를 일으키는 문제를 볼 수 있습니까?

Thx 마르코

해당 표시기가 디컴파일된 표시기이기 때문일 수 있습니다. 빌드 500에서 메타레이더는 이러한 지표가 컴파일되는 것을 방지합니다.

 
mladen:
해당 표시기가 디컴파일된 표시기 때문일 수 있습니다. 빌드 500에서 메타레이더는 이러한 지표가 컴파일되는 것을 방지합니다.

안녕하세요 엠라덴입니다.

Thx, 하지만 내가 사용하는 브로커의 모든 MT4 플랫폼이 500 버전이기 때문에 이상합니다.

마르코 안부

 

부분 이익 실현 기능을 사용하려는 EA가 있습니다. 나는 이 기능을 코딩했고 일단 잘 작동하고 다른 때는 그렇지 않습니다. 뭐가 문제인지 파악을 못했는데...

친애하는 Mladen 또는 MrTools, 코드를 살펴보고 버그를 찾고 부분 처리 기능을 해결할 수 있는 방법에 대한 조언을 주시겠습니까?

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

//| expert start function |

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

int start()

{

int signal;

CheckOrders();

int numTrades = GetNumTickets();

signal = CheckSignal();

if (signal == OP_BUY)

{

OpenBuy();

lasttime = TimeCurrent();

}

if (signal == OP_SELL)

{

OpenSell();

lasttime = TimeCurrent();

}

return;

}

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

// | Order checking function

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

void CheckOrders()

{

int typ,i,cnt,ticket;

int Mv1 = 0;

int SL1 = 0;

int Mv2 = 0;

int SL2 = 0;

int Mv3 = 0;

int id;

double PipDist, CLots, buy_nextTP, sell_nextTP;

cnt = OrdersTotal();

for (i=cnt-1; i>=0; i--)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)

{

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

{

typ = OrderType();

//

if (typ == OP_BUY)

{

if (TrailingStopLoss)

{

if (AdjTrailOnAllOrders(2, buy_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false)

Alert("Scalp_RSI: Modifying BUY order failed!");

}

PipDist = (NormalizeDouble(Bid,Digits) - NormalizeDouble(OrderOpenPrice(),Digits));

PipDist = MathFloor(PipDist/myPoint);

}

if (typ == OP_SELL)

{

if(TrailingStopLoss)

{

if (AdjTrailOnAllOrders(2, sell_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false)

Alert("Scalp_RSI: Modifying SELL order failed!");

}

PipDist = (NormalizeDouble(OrderOpenPrice(),Digits) - NormalizeDouble(Ask,Digits));

PipDist = MathFloor(PipDist/myPoint);

}

if (TakePartialProfit == true && PartCloseLots > 0)

{

if (UseMoneyMgmt != 1) Lotsi = Lots;

CLots = NormalizeDouble(Lotsi * PartCloseLots/100,Decimals); // Computing lots to close

if (CLots < MarketInfo(Symbol(), MODE_MINLOT))

CLots = MarketInfo(Symbol(), MODE_MINLOT);

PartialTP(PipDist,OrderTicket(),CLots);

}

}

}

}

}

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

//| PartialTP - i.e. TakePartialProfit function

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

void PartialTP(int pipsval, int ticket, double CLots) //

{

int gle;

int loopcount = 0;

string bER;

string myInfo = "PartialTP";

if(OrderSelect(ticket, SELECT_BY_TICKET)==true)

{

if (OrderType() == OP_BUY)

{

if ((pipsval >= buy_PartialTP) && (pipsval < buy_TakeProfit+1)) //

{

while(true)

{

OrderClose(ticket,CLots,Bid,3,YellowGreen);

gle=GetLastError();

bER=" error="+gle+" "+ErrorDescription(gle);

if(gle==0 || gle==1)

{

logwrite(TradeComment,"CLOSE BUY "+myInfo+ " " + CLots + " at Bid= " + Bid);

buy_PartialTP = buy_TakeProfit+1; //

break;

}

else

{

logwrite(TradeComment,"---ERROR--- CLOSE BUY "+myInfo+bER+ " " + CLots + " at Bid= " + Bid);

RefreshRates();

Sleep(500);

}

loopcount++;

if(loopcount>maxloop)

{

logwrite(TradeComment,"---ERROR--- Giving up on closing BUY order");

return(gle);

}

}

}

}

if (OrderType() == OP_SELL) //

{

if ((pipsval >= sell_PartialTP) && (pipsval < sell_TakeProfit)) //

{

while(true)

{

OrderClose(ticket,CLots,Ask,3,YellowGreen);

gle=GetLastError();

bER=" error="+gle+" "+ErrorDescription(gle);

if(gle==0 || gle==1)

{

logwrite(TradeComment,"CLOSE SELL "+myInfo+ " " + CLots + " at Ask= " + Ask);

sell_PartialTP = sell_TakeProfit; //

break;

}

else

{

logwrite(TradeComment,"---ERROR--- CLOSE SELL "+myInfo+bER+ " " + CLots + " at Ask= " + Ask);

RefreshRates();

Sleep(500);

}

loopcount++;

if(loopcount>maxloop)

{

logwrite(TradeComment,"---ERROR--- Giving up on closing SELL order");

return(gle);

}

}

}

}

} else {

gle=GetLastError();

bER=" Error="+gle+" "+ErrorDescription(gle);

if (gle != 0 || gle!=1)

{

logwrite(TradeComment,"---ERROR--- in selecting order in PartialTP function "+bER);

}

}

}

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

//| Get number of open trades

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

int GetNumTickets()

{

int i;

int typ;

numTickets = 0;

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

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

{

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

{

typ = OrderType();

if (typ == OP_BUY || typ == OP_SELL)

{

numTickets ++;

}

}

}

}

return (numTickets);

}

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

//| Get signal

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

int CheckSignal()

{

return (SignalScalp());

}

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

//| Get scalp signal

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

int SignalScalp()

{

int signal=6; //

if (enable_buy){

// Buy-Condition

{

signal = OP_BUY;

}

}

//

//

if (enable_sell){

// Sell-Condition

{

signal = OP_SELL;

}

}

//

//

//

return(signal);

}

//-----

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

// | Buy Order

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

void OpenBuy()

{

int gle = 0;

int ticket = 0;

double SL = 0;

double TP = 0;

double LotsB = Lots; //GetLots();

int loopcount = 0;

while(true)

{

ticket=OrderSend(Symbol(),OP_BUY,LotsB,Ask,Slippage,0,0,TradeComment,Magic,White);

}

}

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

// | Sell Order

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

void OpenSell()

{

int gle = 0;

int ticket = 0;

double SL = 0;

double TP = 0;

double LotsS = Lots;

int loopcount = 0;

while(true)

{

ticket=OrderSend(Symbol(),OP_SELL,LotsS,Bid,Slippage,0,0,TradeComment,Magic,Red);

}

}

bool AdjTrailOnAllOrders(

int TrailType,

int TrailPips,

int Magic,

int Direction,

int FirstMove,

int FirstStopLoss,

int SecondMove,

int SecondStopLoss,

int ThirdMove)

{

double retValue;

return(retValue);

}

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

//| SetComment function

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

void SetComment(string s) { TradeComment = s; }

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

// | Pip setting

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

double SetPoint()

{

double mPoint;

return(mPoint);

}

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

// | Log write function

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

void logwrite (string filename, string mydata)

{

int myhandle;

}

 
chrisstoff:
부분 이익 실현 기능을 사용하려는 EA가 있습니다. 나는 이 기능을 코딩했고 일단 잘 작동하고 다른 때는 그렇지 않습니다. 뭐가 문제인지 파악을 못했는데...

친애하는 Mladen 또는 MrTools, 코드를 살펴보고 버그를 찾고 부분 처리 기능을 해결할 수 있는 방법에 대한 조언을 주시겠습니까?

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

//| expert start function |

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

int start()

{

int signal;

CheckOrders();

int numTrades = GetNumTickets();

signal = CheckSignal();

if (signal == OP_BUY)

{

OpenBuy();

lasttime = TimeCurrent();

}

if (signal == OP_SELL)

{

OpenSell();

lasttime = TimeCurrent();

}

return;

}

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

// | Order checking function

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

void CheckOrders()

{

int typ,i,cnt,ticket;

int Mv1 = 0;

int SL1 = 0;

int Mv2 = 0;

int SL2 = 0;

int Mv3 = 0;

int id;

double PipDist, CLots, buy_nextTP, sell_nextTP;

cnt = OrdersTotal();

for (i=cnt-1; i>=0; i--)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)

{

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

{

typ = OrderType();

//

if (typ == OP_BUY)

{

if (TrailingStopLoss)

{

if (AdjTrailOnAllOrders(2, buy_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false)

Alert("Scalp_RSI: Modifying BUY order failed!");

}

PipDist = (NormalizeDouble(Bid,Digits) - NormalizeDouble(OrderOpenPrice(),Digits));

PipDist = MathFloor(PipDist/myPoint);

}

if (typ == OP_SELL)

{

if(TrailingStopLoss)

{

if (AdjTrailOnAllOrders(2, sell_Trailpips, Magic, typ, Mv1, SL1, Mv2, SL2, Mv3) == false)

Alert("Scalp_RSI: Modifying SELL order failed!");

}

PipDist = (NormalizeDouble(OrderOpenPrice(),Digits) - NormalizeDouble(Ask,Digits));

PipDist = MathFloor(PipDist/myPoint);

}

if (TakePartialProfit == true && PartCloseLots > 0)

{

if (UseMoneyMgmt != 1) Lotsi = Lots;

CLots = NormalizeDouble(Lotsi * PartCloseLots/100,Decimals); // Computing lots to close

if (CLots < MarketInfo(Symbol(), MODE_MINLOT))

CLots = MarketInfo(Symbol(), MODE_MINLOT);

PartialTP(PipDist,OrderTicket(),CLots);

}

}

}

}

}

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

//| PartialTP - i.e. TakePartialProfit function

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

void PartialTP(int pipsval, int ticket, double CLots) //

{

int gle;

int loopcount = 0;

string bER;

string myInfo = "PartialTP";

if(OrderSelect(ticket, SELECT_BY_TICKET)==true)

{

if (OrderType() == OP_BUY)

{

if ((pipsval >= buy_PartialTP) && (pipsval < buy_TakeProfit+1)) //

{

while(true)

{

OrderClose(ticket,CLots,Bid,3,YellowGreen);

gle=GetLastError();

bER=" error="+gle+" "+ErrorDescription(gle);

if(gle==0 || gle==1)

{

logwrite(TradeComment,"CLOSE BUY "+myInfo+ " " + CLots + " at Bid= " + Bid);

buy_PartialTP = buy_TakeProfit+1; //

break;

}

else

{

logwrite(TradeComment,"---ERROR--- CLOSE BUY "+myInfo+bER+ " " + CLots + " at Bid= " + Bid);

RefreshRates();

Sleep(500);

}

loopcount++;

if(loopcount>maxloop)

{

logwrite(TradeComment,"---ERROR--- Giving up on closing BUY order");

return(gle);

}

}

}

}

if (OrderType() == OP_SELL) //

{

if ((pipsval >= sell_PartialTP) && (pipsval < sell_TakeProfit)) //

{

while(true)

{

OrderClose(ticket,CLots,Ask,3,YellowGreen);

gle=GetLastError();

bER=" error="+gle+" "+ErrorDescription(gle);

if(gle==0 || gle==1)

{

logwrite(TradeComment,"CLOSE SELL "+myInfo+ " " + CLots + " at Ask= " + Ask);

sell_PartialTP = sell_TakeProfit; //

break;

}

else

{

logwrite(TradeComment,"---ERROR--- CLOSE SELL "+myInfo+bER+ " " + CLots + " at Ask= " + Ask);

RefreshRates();

Sleep(500);

}

loopcount++;

if(loopcount>maxloop)

{

logwrite(TradeComment,"---ERROR--- Giving up on closing SELL order");

return(gle);

}

}

}

}

} else {

gle=GetLastError();

bER=" Error="+gle+" "+ErrorDescription(gle);

if (gle != 0 || gle!=1)

{

logwrite(TradeComment,"---ERROR--- in selecting order in PartialTP function "+bER);

}

}

}

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

//| Get number of open trades

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

int GetNumTickets()

{

int i;

int typ;

numTickets = 0;

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

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

{

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

{

typ = OrderType();

if (typ == OP_BUY || typ == OP_SELL)

{

numTickets ++;

}

}

}

}

return (numTickets);

}

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

//| Get signal

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

int CheckSignal()

{

return (SignalScalp());

}

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

//| Get scalp signal

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

int SignalScalp()

{

int signal=6; //

if (enable_buy){

// Buy-Condition

{

signal = OP_BUY;

}

}

//

//

if (enable_sell){

// Sell-Condition

{

signal = OP_SELL;

}

}

//

//

//

return(signal);

}

//-----

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

// | Buy Order

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

void OpenBuy()

{

int gle = 0;

int ticket = 0;

double SL = 0;

double TP = 0;

double LotsB = Lots; //GetLots();

int loopcount = 0;

while(true)

{

ticket=OrderSend(Symbol(),OP_BUY,LotsB,Ask,Slippage,0,0,TradeComment,Magic,White);

}

}

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

// | Sell Order

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

void OpenSell()

{

int gle = 0;

int ticket = 0;

double SL = 0;

double TP = 0;

double LotsS = Lots;

int loopcount = 0;

while(true)

{

ticket=OrderSend(Symbol(),OP_SELL,LotsS,Bid,Slippage,0,0,TradeComment,Magic,Red);

}

}

bool AdjTrailOnAllOrders(

int TrailType,

int TrailPips,

int Magic,

int Direction,

int FirstMove,

int FirstStopLoss,

int SecondMove,

int SecondStopLoss,

int ThirdMove)

{

double retValue;

return(retValue);

}

void SetComment(string s) { TradeComment = s; }

double SetPoint()

{

double mPoint;

return(mPoint);

}

void logwrite (string filename, string mydata)

{

int myhandle;

}

크리스토프

"Decimals" 변수에 어떤 값을 사용하고 있는지 알 수 없지만 아마도 이것이 문제의 원인일 것입니다. 주문의 결과 부분도 로트 단계 값과 일치해야 합니다(예: 로트 단계가 0.1이면 0.11로트를 청산할 수 없음). 계속되지 않는 부분 닫기 후 마지막 오류 가 무엇인지 확인하십시오(다음과 같은 행 뒤에 주석을 추가하면 됩니다.

bER="오류="+글+" "+오류설명(글);

if (gle>1) 주석(bER);

코드의 logwrite 기능이 작동하지 않기 때문에

 

믈라덴,

답변 감사합니다.

글쎄, 글이 10,000자를 넘을 가능성이 없기 때문에 코드를 줄였습니다. 따라서 원래 코드에서 Decimals 변수는 다음과 같이 init()에 있습니다.

LotStep = MarketInfo(Symbol(),MODE_LOTSTEP);

if(LotStep == 0.01) {Decimals = 2;}

if(LotStep == 0.1) {Decimals = 1;}

if(LotStep == 1) {Decimals = 0;}[/PHP]

Yes, logwrite function is not functionable in the code posted, also because of the shortening. Normally it looks like:

[PHP]

void logwrite (string filename, string mydata)

{

int myhandle;

string wcalend=TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS);

Print(mydata+" "+wcalend);

if(IsTesting()) return(0);

myhandle=FileOpen(Symbol()+"_"+filename, FILE_CSV|FILE_WRITE|FILE_READ, ";");

if(myhandle>0)

{

FileSeek(myhandle,0,SEEK_END);

FileWrite(myhandle, mydata+" "+wcalend);

FileClose(myhandle);

}

}

따라서 Decimals 변수 때문에 문제가 발생한다고 생각하지 않습니다.

 
chrisstoff:
믈라덴,

답변 감사합니다.

글쎄, 글이 10,000자를 넘을 가능성이 없기 때문에 코드를 줄였습니다. 따라서 원래 코드에서 Decimals 변수는 다음과 같이 init()에 있습니다.

LotStep = MarketInfo(Symbol(),MODE_LOTSTEP);

if(LotStep == 0.01) {Decimals = 2;}

if(LotStep == 0.1) {Decimals = 1;}

if(LotStep == 1) {Decimals = 0;}[/PHP]

Yes, logwrite function is not functionable in the code posted, also because of the shortening. Normally it looks like:

[PHP]

void logwrite (string filename, string mydata)

{

int myhandle;

string wcalend=TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS);

Print(mydata+" "+wcalend);

if(IsTesting()) return(0);

myhandle=FileOpen(Symbol()+"_"+filename, FILE_CSV|FILE_WRITE|FILE_READ, ";");

if(myhandle>0)

{

FileSeek(myhandle,0,SEEK_END);

FileWrite(myhandle, mydata+" "+wcalend);

FileClose(myhandle);

}

}
따라서 Decimals 변수 때문에 문제가 발생한다고 생각하지 않습니다.

크리스토프

그렇게하면 Decimals 변수가 정상이어야합니다.

어쨌든 주문(부분) 마감에 실패한 경우 어떤 오류 코드 가 나타나는지 확인하십시오.

 
mladen:
나는 당신이 매직 넘버를 사용하지 않는다는 것을 알고 있으므로 그것이 매직 넘버나 기호가 무엇인지는 중요하지 않다고 가정합니다. 이 경우 먼저 다음과 같이 이미 개설된 주문이 있는지 확인하십시오.
if (OrdersTotal()<1)

{

ticket=OrderSend(Symbol(), OP_BUY, lots, Ask, 3, 0, 0);

stop=(Ask-stopsize*Point);

prof=(Ask+profsize*Point);

OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Blue);

}

매직 넘버와 심볼 체크를 사용하기로 결정했다면 지정된 심볼 및/또는 매직 넘버에 대해 열린 주문을 세는 함수를 만드는 것이 가장 좋습니다.

감사합니다.

if (OrdersTotal()<1

그것은 내 문제를 해결했습니다.

It Total은 하나를 주문할 수 있지만 각 통화 쌍을 열 수 있기를 바랍니다.

오해해서 죄송합니다.

그러나 내가 의미하는 것은 각 쌍에서 하나의 주문을 실행하고 중지한다는 것입니다. 예시:

이제 EURUSD에서 주문을 열면 하나의 주문만 실행됩니다. 그러면 다른 통화도 동시에 하나의 주문을 실행할 수 있습니다. 내 서투른 영어로 유감입니다.

-------------------------------------------------- ---------------

감사해요.

 
hock87:
감사합니다.

if (OrdersTotal()<1

그것은 내 문제를 해결했습니다.

It Total은 하나를 주문할 수 있지만 각 통화 쌍을 열 수 있기를 바랍니다.

오해해서 죄송합니다.

그러나 내가 의미하는 것은 각 쌍에서 하나의 주문을 실행하고 중지한다는 것입니다. 예시:

이제 EURUSD에서 주문을 열면 하나의 주문만 실행됩니다. 그러면 다른 통화도 동시에 하나의 주문을 실행할 수 있습니다. 내 서투른 영어로 유감입니다.

-------------------------------------------------- ---------------

감사해요.

호크87

이걸 더해 :

int TotalOrders = 0;

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

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

if (OrderSymbol() == Symbol())

TotalOrders++;

}

if ( OrdersTotal ()< 1 ) 줄 앞에 있고 해당 줄을 if ( TotalOrders < 1 ) 로 바꿉니다. 그렇게 하면 심볼당 하나의 열린 주문만 허용됩니다.

 

정말 고마워요, mladen.

나는 지금 그것을 시도한다.

 
hock87:
감사합니다.

if (OrdersTotal()<1

그것은 내 문제를 해결했습니다.

It Total은 하나를 주문할 수 있지만 각 통화 쌍을 열 수 있기를 바랍니다.

오해해서 죄송합니다.

그러나 내가 의미하는 것은 각 쌍에서 하나의 주문을 실행하고 중지한다는 것입니다. 예시:

이제 EURUSD에서 주문을 열면 하나의 주문만 실행됩니다. 그러면 다른 통화도 동시에 하나의 주문을 실행할 수 있습니다. 내 서투른 영어로 유감입니다.

-------------------------------------------------- ---------------

감사해요.

호크87

해당 문제의 해결 방법은 게시물 위의 게시물을 참조하세요.

이에 대한 완전한 코드는 다음과 같습니다.

int TotalOrders = 0;

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

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

if (OrderSymbol() == Symbol())

TotalOrders++;

}

if (TotalOrders<1)

{

ticket=OrderSend(Symbol(), OP_BUY, lots, Ask, 3, 0, 0);

stop=(Ask-stopsize*Point);

prof=(Ask+profsize*Point);

OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Blue);

}