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