Hilfe bei der Codierung - Seite 156

 
Marco320:
Lieber MLaden,

Next indi kann ich auf dem Chart in meinem Live-Konto und auf der Demo von Markets.com (CFD's) bekommen. Entweder gibt es ein Problem, es auf dem Chart bei Liquid Markets auf Demo zu bekommen. Da Liquid Markets mehrere Optionen von Instrumenten anbietet (insbesondere Futures in MT4), würde ich es gerne auf dem Chart in dieser Plattform haben. Können Sie ein Problem sehen, das dieses Problem aufwirft, denn ich kann es nicht finden.

Danke Marco

Es liegt wahrscheinlich daran, dass dieser Indikator ein dekompilierter Indikator ist. Ab Build 500 verhindert Metarader, dass solche Indikatoren kompiliert werden.

 
mladen:
Es liegt wahrscheinlich daran, dass dieser Indikator ein dekompilierter Indikator ist. Ab Build 500 verhindert Metarader, dass solche Indikatoren kompiliert werden.

Hallo MLaden,

Thx, aber seltsam, weil alle MT4-Plattformen von Brokern, die ich benutze, sind die 500-Version.

Gruß Marco

 

Ich habe einen EA, in dem ich eine partielle Take-Profit-Funktion verwenden möchte. Ich habe diese Funktion codiert und einmal funktioniert es gut, ein anderes Mal nicht. Ich konnte nicht herausfinden, was das Problem ist...

Lieber Mladen oder MrTools, wären Sie so freundlich, sich den Code anzusehen und mir einen Rat zu geben, wie ich den Fehler finden und die Funktion der teilweisen Gewinnmitnahme beheben könnte?

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

//| 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:
Ich habe einen EA, in dem ich eine partielle Take-Profit-Funktion verwenden möchte. Ich habe diese Funktion codiert und einmal funktioniert sie gut, ein anderes Mal nicht. Ich war nicht in der Lage herauszufinden, was das Problem ist...

Lieber Mladen oder MrTools, wären Sie so freundlich, sich den Code anzuschauen und mir einen Rat zu geben, wie ich den Fehler finden und die Teilentnahmefunktion auflösen kann?

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

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

}

christoff

Ich kann nicht sehen, welchen Wert Sie für die Variable "Decimals" verwenden, aber wahrscheinlich ist das die Ursache für Ihr Problem. Der resultierende Teil des Auftrags muss auch mit dem Wert des Lotschrittes übereinstimmen (d.h. wenn der Lotschritt z.B. 0,1 ist, können Sie nicht versuchen, 0,11 Lots zu schließen). Prüfen Sie, welches der letzte Fehler nach dem partiellen Abschluss ist, der nicht erfolgreich ist (Sie können dies tun, indem Sie einfach einen Kommentar nach Zeilen hinzufügen, die wie diese gehen:

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

if (gle>1) Kommentar(bER);

da die Logwrite-Funktion im Code nicht funktioniert

 

Mladen,

vielen Dank für Ihre Antwort.

Nun, ich habe den Code gekürzt, weil es keine Möglichkeit gibt, dass ein Beitrag länger als 10.000 Zeichen ist. Im ursprünglichen Code ist die Decimals-Variable in der init() wie folgt:

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

}

}

Ich glaube also nicht, dass das Problem wegen der Decimals-Variable auftritt.

 
chrisstoff:
Mladen,

Ich danke Ihnen für Ihre Antwort.

Nun, ich habe den Code gekürzt, weil es keine Möglichkeit gibt, dass ein Beitrag länger als 10.000 Zeichen ist. Im ursprünglichen Code steht die Variable Decimals in init() wie folgt:

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

}

}
Ich glaube nicht, dass das Problem durch die Decimals-Variable verursacht wird.

Christoff

Auf diese Weise sollte die Decimals-Variable in Ordnung sein.

Prüfen Sie auf jeden Fall, welchen Fehlercode Sie bei einem erfolglosen (teilweisen) Auftragsabschluss erhalten.

 
mladen:
Ich sehe, dass Sie keine magische Zahl verwenden, also ist die Annahme, dass es keine Rolle spielt, was die magische Zahl oder das Symbol ist. In diesem Fall sollten Sie zunächst prüfen, ob bereits eine Bestellung eröffnet wurde - etwa so:
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);

}

Wenn Sie sich entscheiden, die magische Zahl und das Symbol zu verwenden, dann ist es am besten, eine Funktion zu erstellen, die die für das angegebene Symbol und/oder die magische Zahl geöffneten Aufträge zählt.

Danke mladen.

if (OrdersTotal()<1

Das hat mein Problem gelöst.

Es Total kann eine bestellen, aber ich will jedes Paar Währungen öffnen können.

Es tut mir leid, dass ich das falsch verstanden habe.

Aber ich meine, dass in jedem Paar eine Order und ein Stop ausgeführt werden soll. Beispiel:

Jetzt eröffne ich eine Order in EURUSD und führe nur eine Order aus. Dann andere Währungen können auch in der gleichen Zeit öffnen, führen Sie eine Bestellung. Es tut mir leid für mein schlechtes Englisch.

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

Danke.

 
hock87:
Danke mladen.

if (AufträgeSumme()<1

Das hat mein Problem gelöst.

Es Total kann eine bestellen, aber ich will jedes Paar Währungen öffnen können.

Es tut mir leid, dass ich das falsch verstanden habe.

Aber ich meine, dass in jedem Paar eine Order und ein Stop ausgeführt werden soll. Beispiel:

Jetzt eröffne ich eine Order in EURUSD und führe nur eine Order aus. Dann andere Währungen können auch in der gleichen Zeit öffnen, führen Sie eine Bestellung. Es tut mir leid für mein schlechtes Englisch.

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

Danke!

hock87

Füge dies hinzu:

int TotalOrders = 0;

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

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

if (OrderSymbol() == Symbol())

TotalOrders++;

}

vor der Zeile if (OrdersTotal()<1) und ersetzen Sie diese Zeile durch if (TotalOrders<1). Auf diese Weise wird nur ein geöffneter Auftrag pro Symbol zugelassen.

 

Vielen Dank, mladen.

Ich versuche es jetzt.

 
hock87:
Danke mladen.

if (AufträgeSumme()<1

Das hat mein Problem gelöst.

Es Total kann eine bestellen, aber ich will jedes Paar Währungen öffnen können.

Es tut mir leid, dass ich das falsch verstanden habe.

Aber ich meine, dass in jedem Paar eine Order und ein Stop ausgeführt werden soll. Beispiel:

Jetzt eröffne ich eine Order in EURUSD und führe nur eine Order aus. Dann andere Währungen können auch in der gleichen Zeit öffnen, führen Sie eine Bestellung. Es tut mir leid für mein schlechtes Englisch.

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

Danke!

hock87

Bitte lesen Sie den Beitrag über Ihrem Beitrag, um eine Lösung für dieses Problem zu finden

Der komplette Code dafür ist der folgende:

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

}

Grund der Beschwerde: