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)
-   -   Bitte Hilfe für absoluten noob (http://www.expert-advisor.com/forum/showthread.php?t=4234)

Chton 25.05.15 23:24

Nachtrag:
 
wenn ich einen EURUSD Chart öffne, und dann auf das Script gehe und "Anwenden auf Chart" auswähle, dann habe ich bessere Werte:

TP = 1.0989
SL = 1.0968

etc.

aber wieder OrderSend failed with error #4109.
Prinzipiell kann ich (manuell) Positionen öffnen.
Nur halt nicht per Script / EA.

pako 26.05.15 00:13

Zitat:

Zitat von Chton (Beitrag 29867)
Z.B dieses Script (jetzt mal kein EA):



int start()
{
int ticket,iSlipPage,iSLPips,iTPPips;
double dStopLoss, dTakeProfit,dLots;
string sText,sArrow;
iSLPips=100; //Stop Loss in Pips
iTPPips=100; //Take Profit in Pips
dLots=0.01; //Amount of Lots
iSlipPage=3;
sText="My Order"; //Order Text
sArrow=CLR_NONE; //Order Arrow Color

dStopLoss=Bid-NormalizeDouble(iSLPips*Point,MarketInfo("EURUSD", MODE_DIGITS));
dTakeProfit=Ask + NormalizeDouble(iTPPips*Point,MarketInfo("EURUSD", MODE_DIGITS));
ticket=OrderSend("EURUSD",OP_BUY,dLots, Ask,iSlipPage,dStopLoss, dTakeProfit,sText,000,0,sArrow);
if(ticket<0)
{
Alert("OrderSend failed with error #",GetLastError());
Alert("Ask-Price = ", Ask);
Alert("Bid-Price = ", Bid);
Alert("SL = ", dStopLoss);
Alert("TP = ", dTakeProfit);
}

return(0);
}





Liefert mir als Ausgabe:
-----------------------------------------------------
TP = 0.9464
SL = 0.9439
Bid-Price = 0.9449
Ask-Price = 0.9454
OrderSend failed with error #4109
-----------------------------------------------------


Warum sind dies Werte (Preise), die auf USDCHF passen, wo ich doch ausdrücklich EURUSD angebe ?

und warum #4109 ?
Was ist da falsch ?

Danke !

Alert("Bid-Price = ", Bid);// aktive chart
Alert("Bid-Price = ", MarketInfo("EURUSD",MODE_BID));// EURUSD chart

OrderSend("EURUSD",OP_BUY,1,MarketInfo("EURUSD",MO DE_ASK),30,0,0,"My order",16384,0,clrGreen);

Chton 26.05.15 21:06

Hallo,

ich glaube nun, dass mich der Tipp deutlich weitergebracht hat, pako !


Mein Script sieht nun folgendermaßen aus:

int start()
{
int ticket, iSlipPage, iSLPips, iTPPips;
double dStopLoss, dTakeProfit, dLots, dAskPrice, dBidPrice;
string sText,sArrow;

iSLPips=100; //Stop Loss in Pips
iTPPips=100; //Take Profit in Pips
dLots=0.01; //Amount of Lots
iSlipPage=5;
sText="My Order"; //Order Text
sArrow=CLR_NONE; //Order Arrow Color
dAskPrice=MarketInfo("EURUSD",MODE_ASK);
dBidPrice=MarketInfo("EURUSD",MODE_BID);

dStopLoss=(dAskPrice * 10000 - iSLPips) / 10000;
dTakeProfit=(dAskPrice * 10000 + iTPPips) / 10000;
ticket=OrderSend("EURUSD", OP_BUY, dLots, dBidPrice, iSlipPage, dStopLoss, dTakeProfit, sText, 000, 0, sArrow);
if(ticket<0)
{
Alert("OrderSend failed with error = #",GetLastError());
Alert("Order-Text = ", sText);
Alert("Lot-Size = ", dLots);
Alert("Ask-Price = ", dAskPrice);
Alert("Bid-Price = ", dBidPrice);
Alert("SL = ", dStopLoss);
Alert("TP = ", dTakeProfit);
Alert("SlipPage = ", iSlipPage);
}

return(0);
}



Es scheint mir saubere Werte zu liefern und auf den Ticker zu laufen, den ich möchte, nämlich EURUSD.

Nächstes Problem (da immer noch #4109 error):

Mein Broker ist wohl ein 5-digit-Broker (fxcc).

Die Alerts sagen mir aber:
TP: 1.0967
SL: 1.0767
Bid-Price: 1.0867
Ask-Price: 1.0867

was doch 4-digit ist, richtig ? (=Stellen nach dem Komma)

Wie bekomme ich es umgebaut, dass ich mit 5-digit-Werten arbeite ?

Oder liegt der Fehler noch woanders ?


Dankeee !

Chton 26.05.15 23:18

Wir mir scheint liefert

Alert("Digits after decimal point=",MarketInfo("EURUSD",MODE_DIGITS));

5 digits, so wie ich es brauche,

jedoch bekomme ich diesen Wert mit den 5 Nachkommastellen nicht in die
Variable dAskPrice hinein. Nach der Zuweisung habe ich dort wieder nur 4 Nachkommastellen.

Habe auch probiert einen String wie "0.12345" per StrToDouble umzuwandeln:
Zack bekomme ich wieder 0.1234

Eine double - Variable kann noch 0.12345 aufnehmen - oder ?

Was mache ich falsch ?

pako 26.05.15 23:23

Zitat:

Zitat von Chton (Beitrag 29875)

Oder liegt der Fehler noch woanders ?


Code:

//+------------------------------------------------------------------+
//|                                                        Chton.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                            https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version  "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
  int ticket,iSlipPage,iSLPips,iTPPips;
  double dStopLoss,dTakeProfit,dLots,dAskPrice,dBidPrice,dPoint;
  string sText;
  color cArrow;

  iSLPips=100; //Stop Loss in Pips
  iTPPips=100; //Take Profit in Pips
  dLots=0.01; //Amount of Lots
  iSlipPage=5;
  sText="My Order"; //Order Text
  cArrow=clrLime; //Order Arrow Color
  dAskPrice=MarketInfo("EURUSD",MODE_ASK);
  dBidPrice=MarketInfo("EURUSD",MODE_BID);
  dPoint  =MarketInfo("EURUSD",MODE_POINT);

  dStopLoss=(dAskPrice-iSLPips*dPoint);
  dTakeProfit=(dAskPrice+iTPPips*dPoint);
  ticket=OrderSend("EURUSD",OP_BUY,dLots,dAskPrice,iSlipPage,dStopLoss,dTakeProfit,sText,2345678,0,cArrow);
  if(ticket<0)
    {
      Alert("OrderSend failed with error = #",GetLastError());
      Alert("Order-Text = ",sText);
      Alert("Lot-Size = ",dLots);
      Alert("Ask-Price = ",dAskPrice);
      Alert("Bid-Price = ",dBidPrice);
      Alert("SL = ",dStopLoss);
      Alert("TP = ",dTakeProfit);
      Alert("SlipPage = ",iSlipPage);
    }
    else Alert("OrderSend successful  ticket = ",ticket);
  }
//+------------------------------------------------------------------+
// 4109 ERR_TRADE_NOT_ALLOWED  Trade is not allowed. Enable checkbox "Allow live trading" in the Expert Advisor properties


Chton 26.05.15 23:34

Und ja, ich kann Code für "5-digit-Brokers ergoogeln, da kommt aber mein nächstes Problem:

"Point" ist bei mir aus für mich unerfindlichen Gründen 0, also brauche ich damit wohl nix zu multiplizieren ...

zB.:Code for 5-digit brokers



//+------------------------------------------------------------------+
//| Tutorial15.mq4 |
//| Copyright 2014, ForexBoat |
//| Forex Trading Training Courses For Beginners - Learn The Basics and What It Is |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, ForexBoat"
#property link "http://www.forexboat.com"
#property version "1.00"
#property strict
#property script_show_inputs
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
extern int TakeProfit = 10;
extern int StopLoss = 10;

void OnStart()
{
double TakeProfitLevel;
double StopLossLevel;

TakeProfitLevel = Bid + TakeProfit*Point*10; //0.00001 * 10 = 0.0001
StopLossLevel = Bid - StopLoss*Point*10;

Alert("TakeProfitLevel = ", TakeProfitLevel);
Alert("StopLossLevel = ", StopLossLevel);

OrderSend("EURUSD", OP_BUY, 1.0, Ask, 10*10, StopLossLevel, TakeProfitLevel, "My 1st Order!"); //notice that slippage also has to be multiplied by 10

}
//+------------------------------------------------------------------+

Chton 26.05.15 23:39

// 4109 ERR_TRADE_NOT_ALLOWED Trade is not allowed. Enable checkbox "Allow live trading" in the Expert Advisor properties
[/CODE][/QUOTE]



Danke, aber wo das bei einem Script ?

Ist ja gerade kein EA.

pako 26.05.15 23:41

Zitat:

Zitat von Chton (Beitrag 29876)
Wir mir scheint liefert

Alert("Digits after decimal point=",MarketInfo("EURUSD",MODE_DIGITS));

5 digits, so wie ich es brauche,

jedoch bekomme ich diesen Wert mit den 5 Nachkommastellen nicht in die
Variable dAskPrice hinein. Nach der Zuweisung habe ich dort wieder nur 4 Nachkommastellen.

Habe auch probiert einen String wie "0.12345" per StrToDouble umzuwandeln:
Zack bekomme ich wieder 0.1234

Eine double - Variable kann noch 0.12345 aufnehmen - oder ?

Was mache ich falsch ?

Code:

//+------------------------------------------------------------------+
//|                                                        Chton.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                            https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version  "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
  int ticket,iSlipPage,iSLPips,iTPPips;
  double dStopLoss,dTakeProfit,dLots,dAskPrice,dBidPrice,dPoint;
  string sText;
  color cArrow;

  iSLPips=100; //Stop Loss in Pips
  iTPPips=100; //Take Profit in Pips
  dLots=0.01; //Amount of Lots
  iSlipPage=5;
  sText="My Order"; //Order Text
  cArrow=clrLime; //Order Arrow Color
  dAskPrice=NormalizeDouble(MarketInfo("EURUSD",MODE_ASK),5);
  dBidPrice=MarketInfo("EURUSD",MODE_BID);
  dPoint  =MarketInfo("EURUSD",MODE_POINT);

  dStopLoss=(dAskPrice-iSLPips*dPoint);
  dTakeProfit=(dAskPrice+iTPPips*dPoint);
  ticket=OrderSend("EURUSD",OP_BUY,dLots,dAskPrice,iSlipPage,dStopLoss,dTakeProfit,sText,2345678,0,cArrow);
  if(ticket<0)
    {
      Alert("OrderSend failed with error = #",GetLastError());
      Alert("Order-Text = ",sText);
      Alert("Lot-Size = ",dLots);
      Alert("Ask-Price = ",DoubleToString(dAskPrice,5));
      Alert("Bid-Price = ",dBidPrice);
      Alert("SL = ",dStopLoss);
      Alert("TP = ",dTakeProfit);
      Alert("SlipPage = ",iSlipPage);
    }
  else
    {
      Alert("OrderSend successful  ticket = ",ticket);
      Alert("Ask-Price = ",DoubleToString(dAskPrice,5));
    }
  }
//+------------------------------------------------------------------+


pako 26.05.15 23:49

Liste der Anhänge anzeigen (Anzahl: 1)
Zitat:

Zitat von Chton (Beitrag 29879)



Danke, aber wo das bei einem Script ?

Ist ja gerade kein EA.

in bild oder
#property show_inputs
Code:

//+------------------------------------------------------------------+
//|                                                        Chton.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                            https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version  "1.00"
#property strict
#property show_inputs
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
  int ticket,iSlipPage,iSLPips,iTPPips;
  double dStopLoss,dTakeProfit,dLots,dAskPrice,dBidPrice,dPoint;
  string sText;
  color cArrow;

  iSLPips=100; //Stop Loss in Pips
  iTPPips=100; //Take Profit in Pips
  dLots=0.01; //Amount of Lots
  iSlipPage=5;
  sText="My Order"; //Order Text
  cArrow=clrLime; //Order Arrow Color
  dAskPrice=NormalizeDouble(MarketInfo("EURUSD",MODE_ASK),5);
  dBidPrice=MarketInfo("EURUSD",MODE_BID);
  dPoint  =MarketInfo("EURUSD",MODE_POINT);

  dStopLoss=(dAskPrice-iSLPips*dPoint);
  dTakeProfit=(dAskPrice+iTPPips*dPoint);
  ticket=OrderSend("EURUSD",OP_BUY,dLots,dAskPrice,iSlipPage,dStopLoss,dTakeProfit,sText,2345678,0,cArrow);
  if(ticket<0)
    {
      Alert("OrderSend failed with error = #",GetLastError());
      Alert("Order-Text = ",sText);
      Alert("Lot-Size = ",dLots);
      Alert("Ask-Price = ",DoubleToString(dAskPrice,5));
      Alert("Bid-Price = ",dBidPrice);
      Alert("SL = ",dStopLoss);
      Alert("TP = ",dTakeProfit);
      Alert("SlipPage = ",iSlipPage);
    }
  else
    {
      Alert("OrderSend successful  ticket = ",ticket);
      Alert("Ask-Price = ",DoubleToString(dAskPrice,5));
    }
  }
//+------------------------------------------------------------------+


Chton 26.05.15 23:51

Leute, ich beiß gerade Stücke aus der Tischkante !!
 
in diesem Augenblick kam ein MT4 - Upgrade.

Ich installier' es ... und ab dem Zeitpunkt habe ich unter Optionen die Möglichkeit Live - Trading zu erlauben.

Vorher nicht, bitte glaubt es mir !!

Jetzt funzt mein Script (auch mit 4 digits), d.h. ich kann damit Positionen öffnen.

Sorry für's Nerven und 1000 Dank insbesondere an pako !!!!!!


Danke - Danke - Danke !


Alle Zeitangaben in WEZ +2. Es ist jetzt 13:05 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