Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL4 (http://www.expert-advisor.com/forum/forumdisplay.php?f=220)
-   -   pending order modify (http://www.expert-advisor.com/forum/showthread.php?t=3091)

fabian103 20.07.13 14:53

pending order modify
 
Moin,
ich bin komplett neu im Reich des MT4. Habe bereits schon einige sehr einfach EAs geschrieben und sie erfolgreich auf meinem Demo-Account angewendet.

Jetzt wollte ich mal komplexere EAs schreiben und habe mit einem order modify angefangen. Dort soll der Preis der pending order modifiziert werden sofern ein bestimmter Abstand zwischen aktuellem Preis der Chart und Preis der Order besteht. Jetzt habe ich das Problem, dass der EA das nicht macht. Könnte sich jemand mal den Code angucken und mir sagen woran es liegt, was ich besser machen könnte und eventuelle Klammerfehler beheben. Das wäre super. Ich versuche hier nämlich zu lernen, damit ich später eventuell mal sehr komplexe EAs schreiben kann. Danke schonmal.

Gruß,
Fabian
PHP-Code:

{
RefreshRates();
double ppoint=MarketInfo(OrderSymbol(), MODE_POINT); 
int total=OrdersTotal();
double pBid=MarketInfo(OrderSymbol(), MODE_BID); 

double pAsk=MarketInfo(OrderSymbol(), MODE_ASK);

double priceNew;

//----
for(int i=0i<totali++)
{
if(
OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
Print(
"Error = ",GetLastError());
{

OrderPrint();

if (
OrderType()==OP_BUYSTOP)
{
if (
pBid-OrderOpenPrice()>50*ppoint)
{
priceNew=(pBid-50*ppoint);
OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit());
Print(
"Modified Order");
}
}
}
if (
OrderType()==OP_SELLSTOP)
{
if (
OrderOpenPrice()-pAsk>50*ppoint)
{
priceNew=(pAsk+50*ppoint);
OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit());
Print(
"Modified Order");
}
}
}
}



traderdoc 20.07.13 15:47

Versuche mal in Zukunft mit Einrückungen zu arbeiten, das ist viel übersichtlicher. Die OrderSelect-Funktion soll sicherlich bei Dir bewirken, dass falls die Abfrage false ist, die Errormeldung rausgeht. Daher habe ich Dir ein ! vor die Funktion eingebaut und ein return, damit das Programm aus der übergeordneten Funktion rausspringt.

Code:

RefreshRates();
double*ppoint=MarketInfo(OrderSymbol(),*MODE_POINT);*
int*total=OrdersTotal();
double*pBid=MarketInfo(OrderSymbol(),*MODE_BID);*

double*pAsk=MarketInfo(OrderSymbol(),*MODE_ASK);

double*priceNew;

//----
for(int*i=0;*i<total;*i++) {
  if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
      Print("Error*=*",GetLastError());
      return;
  }

  OrderPrint();

  if*(OrderType()==OP_BUYSTOP) {
      if*(pBid-OrderOpenPrice()>50*ppoint) {
        priceNew=(pBid-50*ppoint);
        OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit());
        Print("Modified*Order");
      }
  }

  if*(OrderType()==OP_SELLSTOP) {
      if*(OrderOpenPrice()-pAsk>50*ppoint) {
        priceNew=(pAsk+50*ppoint);
        OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit());
        Print("Modified*Order");
      }
  }
}


traderdoc 20.07.13 18:47

Un nun der 2. Versuch einen ordendlichen Code hinzulegen. Ich weiss auch nicht was mit meinem iPad los war. Die OrderModify()-Zeile kann ich leider aufgrund der Länge nicht bündig nach rechts schieben.

Code:

RefreshRates();
double ppoint = MarketInfo(OrderSymbol(), MODE_POINT);
int total = OrdersTotal();
double pBid = MarketInfo(OrderSymbol(), MODE_BID);
double pAsk = MarketInfo(OrderSymbol(), MODE_ASK);
double priceNew;

for(int i = 0; i < total; i++) {
  if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
      Print("Error = ", GetLastError());
      return;
  }

  OrderPrint();

  if (OrderType() == OP_BUYSTOP) {
      if (pBid - OrderOpenPrice() > 50*ppoint) {
        priceNew = (pBid - 50*ppoint);
    OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit());
        Print("ModifiedOrder");
      }
  }

  if (OrderType() == OP_SELLSTOP) {
      if (OrderOpenPrice() - pAsk > 50*ppoint) {
        priceNew = (pAsk + 50*ppoint);
  OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit());
        Print("ModifiedOrder");
      }
  }
}



Alle Zeitangaben in WEZ +1. Es ist jetzt 14:19 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum