Das vorherige Problem konnte ich lösen, indem ich die Variablen vor der Start-Funktion nannte und in dieser dann definierte.
Allerdings bin ich jetzt auf ein neues großes Problem gestoßen:
Ich kriege, egal was ich mache, immer einen Fehler Error 4107.
F1 oder Google haben nicht geholfen. Ich habe versucht es durch *Point oder auch durch NormalizeDouble(stoploss,Digits()) probiert, aber ich kriege ihn immernoch.
Der Code ist sehr umfangreich, ich werde ihn trotzdem mal anheften. Ansonsten sind hier die Dinge, die mit dem Stoploss zu tun haben:
Code:
int start(){
....
//---Stoplossdefinition
if(OrderType() == OP_BUY || OrderType() == OP_BUYSTOP) stoploss = st1_long - abst;
if(OrderType() == OP_SELL || OrderType() == OP_SELLSTOP) stoploss = st1_short + abst;
NormalizeDouble(stoploss,Digits());
//--- Trailingstoploss
if(OrdersTotal() > 0){Trailingstoploss();}
if(OrdersTotal() > 0){ClosingTrades();}
OpenLongOrderatBBModify();
OpenShortOrderatBBModify();
}
void OpenLongOrderatBB(){
new_del();
ordersend = OrderSend(NULL,OP_BUYSTOP,Lots,NormalizeDouble(BBUP,Digits()),slippage,stoploss*Point,takeprofit,"Open Pending Long Order at upper Bollinger Band",magicnumber,0,Green);
if(ordersend < 0) Alert("OrderSend ERROR LongOrder at BB NOT opened! ", GetLastError());
else Print("Opened LongOrder: ",OrderMagicNumber()," on ",OrderSymbol(), "Lots: ",OrderLots()," StopLoss: ",OrderStopLoss()," TakeProfit: ",OrderTakeProfit());
}
....
void OpenLongOrderatBBModify(){
for(int i=0;i<=total-1;i++) {
if(OrderSelect(i,SELECT_BY_TICKET)
&& OrderType() == OP_BUYSTOP
&& OrderSymbol() == Symbol()
&& OrderCloseTime()==0
&& OrderType()==OP_BUYSTOP ) {
if(OrderOpenPrice() < BBUP) {
ordermodify = OrderModify(OrderTicket(),NormalizeDouble(BBUP,Digits()),stoploss*Point,takeprofit,0);
if (ordermodify == false)
Print("Stoploss ",OrderTicket()," NICHT nachgezogen! ERROR!");
else
Print("StopLoss ",OrderTicket()," nachgezogen");
}
}
}
}
//--- Dieser Teil löscht unausgeführte Pending Orders.
int new_del()
{
int i,a;
int total = OrdersTotal();
string comentario,par;
for (i=total-1; i >=0; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_BUY || OrderType()==OP_SELL)
{
for (a=total-1; a >=0; a--)
{
OrderSelect(a,SELECT_BY_POS,MODE_TRADES);
comentario=OrderComment();
par=StringSubstr(comentario,0,6);
if(OrderType()==OP_SELLSTOP)// && comentario==Symbol())
{
OrderDelete(OrderTicket());
Print("Deleting SELL_STOP"," Ordertype:",OrderType());
return(1);
}
if(OrderType()==OP_BUYSTOP)// && par==Symbol())
{
OrderDelete(OrderTicket());
Print("Deleting BUY_STOP"," Ordertype:",OrderType());
return(1);
}
}
}
}
return(1);
}
Vielleicht habt ihr noch eine Idee?
LG