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)
-   -   EA - Gleitende Durchschnitte - Fehler (http://www.expert-advisor.com/forum/showthread.php?t=3331)

clixmadine 14.11.13 20:27

EA - Gleitende Durchschnitte - Fehler
 
hi.
mittlerweile bin ich völlig am verzweifeln, weil ich einfach keine lösung finde. die ganze zeit kommt die fehlermeldung 130 und die 1. als ich nachgeschaut habe, viel mir auf, das die variabel "DRANGE" eine 0 ausgibt. das ist natürlich käse. wo liegt in diesem code der fehler?! es wäre toll, wenn mir jemand weiterhelfen könnte!

Code:

//+------------------------------------------------------------------+
//|                  Handelssystem_Gleitende_Durchschnitte.mq4 |
//|                                                                Clixmadine |
//|                                                                                |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2013, Clixmadine"

// Extern Variables
extern double    LotSize=1.0;
extern int      MagicNumber=1606;

// Globale Variables
int BuyTicket, SellTicket, Order, Mod;
double CloseLots, ClosePrice, OpenPrice, SellStopLoss, BuyStopLoss, Trailingstop, Temp;
bool Closed, TicketMod;

//Handelssystem Variablen
extern int    Multiplikator  = 2;

double D_Close, HighPrice, LowPrice, CloseBuyPrice, CloseSellPrice, DRange, TrailingStoppShort, TrailingStoppLong, TodayClose;
double EMA1, EMA2;
double Day_Price[][6], Range[];


int start()
  {
  int total=OrdersTotal();
 
  // Reset, wenn S/L oder T/P ausgelöst wird bzw. wenn manuell geschlossen wird
  if (total == 0)
  {
      BuyTicket=0;
      SellTicket=0;
      Mod=0;
  }
 
  D_Close = iClose(Symbol(),PERIOD_D1,40);
  ArrayResize(Range,20);
 
  for(int i=1; i<=20; i++)
  {
      HighPrice  = Day_Price[i][3];
      LowPrice    = Day_Price[i][2];
      ClosePrice  = Day_Price[i+1][4];     
      Range[i]    = MathMax(HighPrice,ClosePrice) - MathMin(LowPrice,ClosePrice);
      Temp        = Temp + Range[i];
  }
     
  DRange        = (Temp/20)*Multiplikator;
  HighPrice      = Day_Price[1][3];
  LowPrice      = Day_Price[1][2];
  ClosePrice    = Day_Price[1][4];
     
  TrailingStoppLong    = LowPrice - DRange;
  TrailingStoppShort  = HighPrice + DRange;
     
  EMA1 = iMA(Symbol(),PERIOD_D1,13,0,1,0,0);
  EMA2 = iMA(Symbol(),PERIOD_D1,39,0,1,0,0);
  TodayClose = iClose(Symbol(), PERIOD_D1, 1);
 
  if(total == 0)           
  {
      if(EMA1 > EMA2 && ClosePrice > D_Close)
      {
        kaufen();
      } 
      else if(EMA1 < EMA2 && ClosePrice < D_Close)
      {
        verkaufen();
      }
  }         
  else if (total == 1)
  {
      if(BuyTicket != 0)
      {
        if(EMA1 < EMA2 && ClosePrice < D_Close)
        {
            CloseBuy();
        }
        else
        {
            BuyMod();
        }
      }
      else if (SellTicket != 0)
      {
        if(EMA1 > EMA2 && ClosePrice > D_Close)
        {
            CloseSell();
        }
        else
        {
            SellMod();
        }
      }
  } 
                 
  return(0);
}



void verkaufen()
{

  OrderSelect(SellTicket,SELECT_BY_TICKET);
  OpenPrice = Bid;
  SellTicket = OrderSend(Symbol(),OP_SELL,LotSize,OpenPrice,0,0,0,"Sell Order",MagicNumber,0,Green);       
  OrderSelect(SellTicket,SELECT_BY_TICKET);
  OpenPrice = OrderOpenPrice();
  SellStopLoss = NormalizeDouble(OpenPrice + DRange,5);
  Print(SellStopLoss);
  if(OrderStopLoss() == 0)
  {
      TicketMod = OrderModify(SellTicket,OrderOpenPrice(),SellStopLoss,0,0,CLR_NONE);
  }

  return(0);
}


void kaufen()
{
  OrderSelect(BuyTicket,SELECT_BY_TICKET);
  OpenPrice = Ask;
  BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize,OpenPrice,0,0,0,"Buy Order",MagicNumber,0,Green);
  OrderSelect(BuyTicket,SELECT_BY_TICKET);
  OpenPrice = OrderOpenPrice();
  BuyStopLoss = NormalizeDouble(OpenPrice - DRange,5);
  if(OrderStopLoss() == 0)
  {
      TicketMod = OrderModify(BuyTicket,OrderOpenPrice(),BuyStopLoss,0,0,CLR_NONE);
  }

  return(0);
}

void SellMod()
{
  OrderSelect(SellTicket,SELECT_BY_TICKET);
  SellStopLoss = OrderStopLoss();     
  // Calculation SL
  Temp = TrailingStoppShort;
  if(SellStopLoss > Temp || SellStopLoss == 0)
  {
      SellStopLoss = Temp;
      TicketMod = OrderModify(SellTicket,OrderOpenPrice(),SellStopLoss,0,0,CLR_NONE);
  } 
}

void BuyMod()
{
  OrderSelect(BuyTicket,SELECT_BY_TICKET);
  BuyStopLoss = OrderStopLoss();
  // Calculation SL
  Temp = TrailingStoppLong;
  if(BuyStopLoss < Temp || BuyStopLoss == 0)
  {
      BuyStopLoss = Temp;
      TicketMod = OrderModify(BuyTicket,OrderOpenPrice(),BuyStopLoss,0,0,CLR_NONE);
  } 
}

void CloseBuy ()
{
  OrderSelect(BuyTicket,SELECT_BY_TICKET); 
  CloseLots = OrderLots();
  CloseBuyPrice = Bid;
  Closed = OrderClose(BuyTicket,CloseLots,CloseBuyPrice,0,Red);
  BuyTicket = 0;
}

void CloseSell()
{
  OrderSelect(SellTicket,SELECT_BY_TICKET);
  CloseLots = OrderLots();
  CloseSellPrice = Ask;
  Closed = OrderClose(SellTicket,CloseLots,CloseSellPrice,0,Red);
  SellTicket = 0;
}


feelfree 14.11.13 21:25

1. Wenn DRange 0 ausgibt, was gibt dann Temp für einen Wert aus?

2. Gibt das wirklich ein sinnvolles Ergebnis?


Code:

BuyStopLoss = NormalizeDouble(OpenPrice - DRange,5);
Fehler 130 heißt ja invalid stops und auch ein - 0 würde ja noch den OpenPrice als Ergebnis ausgeben.

Also tippe ich auf die Konvertierung.

Ich würde es erst rechnen und dann auf die Digits anpassen.
Zur Sicherheit mit der Comment Funktion das Ergebnis prüfen.

Zitat:

double bsl = OpenPrice - DRange;
double BuyStoploss = NormalizeDouble(bsl,5);
Comment ("BuyStopLoss: ", BuyStopLoss) ;

clixmadine 14.11.13 21:31

hm... na aber ist das dann nicht "doppeltgemoppelt"? :)

clixmadine 14.11.13 21:35

"Temp" ist auf 0. das ist echt zum mäuse melken!!!
ich habe das gefühl, dass er in der schleife gar keine werte ermittelt.

feelfree 14.11.13 21:44

Zitat:

Zitat von clixmadine (Beitrag 24152)
hm... na aber ist das dann nicht "doppeltgemoppelt"? :)

Sollte auch so gehen:
Zitat:

NormalizeDouble((OpenPrice - DRange),5);
Was willst du mit deiner Schleife eigentlich ermitteln?

clixmadine 14.11.13 21:51

in der schleife möchte ich die wahre spanne der letzten 20 tage ermitteln, diese verwende ich dann für den stopp. ich habe die handelssystem aus dem buch von john hill, was ich ehrlich gesagt sehr gut finde. vielleicht kennst du es ja.

feelfree 14.11.13 22:27

Das Buch sagt mir jetzt nichts aber was ist denn die "wahre Spanne"?

Wenn du die Average Daily Range meinst geht das auch hiermit:

Zitat:


int R20 = 0;

for(i=1;i<=20;i++)
R20 = R20 + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;

R20 = R20/20;


clixmadine 14.11.13 22:41

der vortagsschluss wird in die berechnung mit einbezogen
wahre spanne = max(schluss(i+1),hoch(i))-min(schluss(i+1),tief(i))

feelfree 14.11.13 22:56

High, Low und Close werden in deinem EA falsch abgefragt.
Buffernummern funktionieren nur bei Indikatorabfragen.

Mach das mal mit iHigh, iLow und iClose.

clixmadine 15.11.13 12:55

stimmt!!! vielen dank! das wars!!! ;)


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