Zitat:
Zitat von traderdoc
Das kann nicht der ganze Code sein, denn der wäre nur mit Fehlern compilierbar. (z.B. total nicht deklariert, Benutzung von return(0) ohne Einsprungpunkt). Entscheidend für die Lebensdauer der Variablen ist der Ort der Deklaration.
Desweiteren baue an markanten Stellen die Funktion
Print() ein. In der Klammer dann Ausdrücke, die angezeigt werden sollen, z.B. Variablen oder Ergebnisse von Berechnungen oder Rückgabewerte von Funktionen.
Zur reinen Verfolgung, wo der EA hinläuft, reicht es auch aus zu schreiben:
Print("T");
Erscheint dann das T im Reiter Journal oder ExpertAdvisor, dann weißt Du, dass er da lang gelaufen ist.
So kannst Du immer weiter einengen, bis Du die Stelle gefunden hast, an der es lag.
traderdoc
|
Vielen Dank schonmal, das ist nur ein Teil, oben im EA habe ich alles deklariert. Die Sache ist villeicht die Position des Codes im EA, die er wahrscheinlich nicht durchläuft, wie soll ich das einbauen mit dem Print? direkt da runter? dann print("T") zum Beispiel?
Hier der komplette EA (bis auf eine kleine Berechnung):
Code:
//--------------------------------------------------------------------
#property copyright "Copyright © 2015"
//--------------------------------------------------------------- 1 --
#define MAGICMA 16384
extern double StopLoss =25; // SL for an opened order
extern double TakeProfit =20; // ТР for an opened order
extern double TrailingStop = 30;
extern double Lots =0.1; // Strictly set amount of lots
extern double Prots =0.07; // Percent of free margin
extern double Abweichung = 5;
extern int DaysToLookBack = 15;
extern color LineColor = Black;
extern int LineWidth = 1;
extern int LineStyle = STYLE_DOT;
int ShowComment = TRUE;
extern string LineNameUpper = "o";
extern string LineNameLower = "u";
bool Work=true; // EA will work.
string Symb=Symbol(); // Security name
//--------------------------------------------------------------- 2 --
//----- global variables ----------------------------------------------------------------------+
int slippage;
int digits, Total;
int ticket, total, tip=-1;
double point;
int my_digits;
double my_point;
int pips_digits;
int lots_digits;
double Min_Lot;
double Lot;
double maxlots, Free, One_Lot, Step, Lts, SL, TP,K;
string symbol;
double risk;
double maxSpreadWithCommission;
double rangeFilter;
bool gotCommissionPointsFromTrade;
double commissionPoints;
double spreadHistory[30];
int spreadHistoryCount = 0;
string objname_hline;
bool is_testing;
double main_sl;
double main_tp;
double OP;
double main_be_profit;
double main_be_offset;
static int account_number;
static bool is_ok;
bool
Ans =false, // Server response after closing
Cls_B=false, // Criterion for closing Buy
Cls_S=false, // Criterion for closing Sell
Opn_B=false, // Criterion for opening Buy
Opn_S=false; // Criterion for opening Sell
int init()
{
ArrayInitialize(spreadHistory,0.0);
is_testing = IsTesting();
symbol = Symbol();
digits = Digits;
point = Point;
ticket = OrderTicket();
tip = OrderType();
Lot = OrderLots();
SL =OrderStopLoss();
TP =OrderTakeProfit();
Total =OrdersTotal();
if(digits == 0)
{
my_point = 1.0;
my_digits = 0;
}
else
{
if(digits < 2)
{
my_point = 0.1;
my_digits = 1;
}
else
{
if(digits < 4)
{
my_point = 0.01;
my_digits = 2;
}
else
{
my_point = 0.0001;
my_digits = 4;
}
}
}
if(StringFind(symbol,"XAU") >= 0 || StringFind(symbol,"GOLD") >= 0)
{
my_point = 0.1;
my_digits = 1;
}
else
{
if(StringFind(symbol,"XAG") >= 0 || StringFind(symbol,"SILVER") >= 0)
{
my_point = 0.01;
my_digits = 2;
}
}
pips_digits = digits - my_digits;
double correction = MathPow(10,pips_digits);
// Lots = NormalizeDouble(Lots,lots_digits);
main_sl = NormalizeDouble(my_point * StopLoss,digits);
main_tp = NormalizeDouble(my_point * TakeProfit,digits);
OP = NormalizeDouble(my_point * Abweichung,digits);
return(0);
}
//---------------------------------------------------------------------------------------------+
//---- deinit ---------------------------------------------------------------------------------+
//---------------------------------------------------------------------------------------------+
int deinit()
{
if(ShowComment) Comment("");
if (ShowComment) Comment("");
ObjectDelete(LineNameUpper);
ObjectDelete(LineNameLower);
ObjectDelete("ObjName33");
ObjectDelete("ObjName213");
return(0);
}
//---------------------------------------------------------------------------------------------+
//---- start ----------------------------------------------------------------------------------+
//---------------------------------------------------------------------------------------------+
int start()
{
//
[Berechnungen für die Upper und Lower Range (diese Funktioniert)]
if (ObjectFind(LineNameUpper)<0) DrawLine(LineNameUpper, Upper);
else ObjectMove(LineNameUpper,0,TimeCurrent(),Upper);
if (ObjectFind(LineNameLower)<0) DrawLine(LineNameLower, Lower);
else ObjectMove(LineNameLower,0,TimeCurrent(),Lower);
ObjectCreate("ObjName33", OBJ_TEXT, 0, TimeCurrent(),DoubleToStr(Upper,Digits));
ObjectSetText("ObjName33"," o STB: "+DoubleToStr(Upper,Digits),10, "Verdana", DarkGray);
ObjectSet("ObjName33", OBJPROP_CORNER, 0);
ObjectSetInteger(0,"ObjName33",OBJPROP_ANCHOR,ANCHOR_LEFT);
ObjectCreate("ObjName213", OBJ_TEXT, 0, TimeCurrent(),DoubleToStr(LowerDigits));
ObjectSetText("ObjName213"," u STB: "+DoubleToStr(Lower,Digits),10, "Verdana", DarkGray);
ObjectSet("ObjName213", OBJPROP_CORNER, 0);
ObjectSetInteger(0,"ObjName213",OBJPROP_ANCHOR,ANCHOR_LEFT);
//--------------------------------------------------------------- 7 --
// Order value
RefreshRates(); // Refresh rates
Min_Lot=MarketInfo(NULL,MODE_MINLOT); // Minimal number of lots
Free =AccountFreeMargin(); // Free margin
One_Lot=MarketInfo(NULL,MODE_MARGINREQUIRED);// Price of 1 lot
Step =MarketInfo(NULL,MODE_LOTSTEP); // Step is changed
if (Lots < 0) // If lots are set,
Lts =Lots; // work with them
else // % of free margin
Lts=MathFloor(Free*Prots/One_Lot/Step)*Step;// For opening
if(Lts > Min_Lot) Lts=Min_Lot; // Not less than minimal
if (Lts*One_Lot > Free) // Lot larger than free margin
{
Alert(" Not enough money for ", Lts," lots");
return(0); // Exit start()
}
double mymagicnumber = 123456;
double closedProfit;
int lastorder;
int hstTotal = OrdersHistoryTotal();
for(int i = hstTotal -1; i >= 0; i--) {
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == mymagicnumber) {
closedProfit = OrderProfit();
lastorder = OrderType();
break;
}
}
}
//---- detect trading signal ---------------------------------------------------------------+
double close = NormalizeDouble(iClose(NULL,0,0),digits);
double open = NormalizeDouble(iOpen(NULL,0,0),digits);
double o = NormalizeDouble(Upper,digits);
double u = NormalizeDouble(Lower,digits);
total=OrdersTotal();
if(total<1)
{
static datetime tradingAllowed;
int newCount = HistoryTotal(); static int prevCount;
if (newCount != prevCount){ prevCount = newCount;
datetime lastClose;
for(int pos=newCount-1; pos >= 1; pos--) if (
OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/
&& OrderCloseTime() > lastClose
&& OrderTicket() == ticket
&& OrderSymbol() == Symbol()
&& OrderType() <= OP_SELL){
lastClose = OrderCloseTime();
}
datetime lastClosePlus24Hrs = lastClose + 2* 3600;
tradingAllowed = lastClosePlus24Hrs;
}
if (TimeCurrent() <= tradingAllowed) return(0);
if(AccountFreeMargin()<(1000*Lots))
{Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
//check for long position
if (closedProfit>=0)
{
if (iOpen(NULL,0,0) > u && iClose(NULL,0,0) < u)
{
RefreshRates(); // Refresh rates
SL=Bid + main_sl; // Calculating SL of opened
TP=Bid - main_tp; // Calculating TP of opened
ticket=OrderSend(Symb,OP_SELL,Lts,Bid,2,SL,TP,NULL,123456);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
} // Criterion for opening Sell
if (iOpen(NULL,0,0) < o && iClose(NULL,0,0) > o)
{
RefreshRates(); // Refresh rates
SL=Ask - main_sl; // Calculating SL of opened
TP=Ask + main_tp;
ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,SL,TP,NULL,123456);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
}
// Criterion for opening Sell
if (closedProfit < 0) {
// if(total < 1) { //was soll total sein???
if (lastorder == 0) {
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 2, StopLoss, TakeProfit, NULL, mymagicnumber);
}
if (lastorder == 1) {
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 2, StopLoss, TakeProfit, NULL, mymagicnumber);
}
}
return(0);
}
int maxDuration = 20 * 60; // 20 minutes
for(int posi = OrdersTotal()-1; posi >= 0 ; posi--) if (
OrderSelect(posi, SELECT_BY_POS) // Only my orders w/
&& OrderMagicNumber() == 123456 // my magic number
&& OrderSymbol() == Symbol() ){ // and period and symbol
int duration = TimeCurrent() - OrderOpenTime();
if (duration >= maxDuration)
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(),
2 * my_point);
}
return(0);
}
int New_Stop(int Parametr) // Checking stop levels
{
int Min_Dist=MarketInfo(NULL,MODE_STOPLEVEL);// Minimal distance
if (Parametr > Min_Dist) // If less than allowed
{
Parametr=Min_Dist; // Sett allowed
Alert("Increased distance of stop level.");
}
return(Parametr); // Returning value
}
void DrawLine(string LineName,double price1) {
ObjectCreate(LineName,OBJ_TREND,0,TimeCurrent(),price1,Time[40],price1);
ObjectSet(LineName,OBJPROP_COLOR,LineColor);
ObjectSet(LineName,OBJPROP_WIDTH,LineWidth);
ObjectSet(LineName,OBJPROP_STYLE,LineStyle);
ObjectSet(LineName,OBJPROP_RAY_RIGHT, false);
}
|