Einzelnen Beitrag anzeigen
  #6 (permalink)  
Alt 25.05.20
berndao berndao ist offline
Neues Mitglied
 
Registriert seit: May 2020
Beiträge: 18
berndao befindet sich auf einem aufstrebenden Ast
Standard

Und gleich die nächste Inkompetenz meinerseits:

hier der Code
Code:
//+------------------------------------------------------------------+
//|                                                     10 20 EA.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

input int pipsStopLoss=18;
input double lotsize=0.01;
int BuyTrade;
int SellTrade;

//for TradeUpdate Function
double NewStopLoss;

#include <Allerlei 1.mqh>

datetime LastActiontime;
//used to determine if a new bar has been formed



void InitializeVariables(){
  BuyTrade=0;
  SellTrade=0;
}


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(){
//---
  Print("Start Time is= ",TimeCurrent());
  LastActiontime=Time[1];
  //Print("die Zahl ",1.23456789," gerundet auf die ",_Digits,"te Nachkommastelle ergibt ", roundD(1.23456789));
  //Print("");
  //Print( DoubleToString(Wert, _Digits) );
  
  InitializeVariables();
  
   
//---
   return(INIT_SUCCEEDED);
}
  
  

  
  
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
  RefreshRates();
  //only allows action if a new bar has formed
  if(LastActiontime==Time[1]){
    ActionsOncePerTick();
    return;
  }
  else
  {
    ActionsOncePerTick();
    ActionsOncePerBar();
    LastActiontime=Time[1];
    return;
  }  
//+------------------------------------------------------------------+
}


void ActionsOncePerBar(){

  //Print("Last Bar Time is= ",Time[1], "and last Close Price is= ",DoubleToString(Close[1],_Digits));
  Print("At the previous Bar, are the Bollinger Bands contracting? ", BBcontract() );
  Print("by how much compared to the previous bar? ", DoubleToString(BBContpercent(),2));
  Print("");
  


}

void ActionsOncePerTick(){
  RefreshRates();

  CheckTrades();
  return;
}

void CheckTrades(){
  RefreshRates();
  if(OrdersTotal()==0){
    InitializeVariables();
    OpenTrades();
  }
  else{
    UpdateTrades();
  }
}

void OpenTrades(){
 OpenBuyTrade();
 OpenSellTrade();
  
}


void OpenBuyTrade(){
  RefreshRates();
  double stoploss=NormalizeDouble(Bid-Point*pipsStopLoss,Digits);
  RefreshRates();
  BuyTrade=OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,stoploss,0);

}


void OpenSellTrade(){
  RefreshRates();
  double stoploss=NormalizeDouble(Ask+Point*pipsStopLoss,Digits);
  RefreshRates();
  SellTrade=OrderSend(Symbol(),OP_SELL,lotsize,Bid,3,stoploss,0);

}


//Update Trades
void UpdateTrades(){
  RefreshRates();
  
//+------------------------------------------------------------------+
//| Buy Trade                                                        |
//+------------------------------------------------------------------+
  OrderSelect(BuyTrade,SELECT_BY_TICKET);
  NewStopLoss=OrderStopLoss();
  
  RefreshRates();
  //berechne neuen StopLoss
  if(OrderStopLoss()<Bid-Point*pipsStopLoss){
    NewStopLoss=NormalizeDouble(Bid-Point*pipsStopLoss,Digits);
  }
  
  //nur Stoploss anpassen
  RefreshRates();
  OrderModify(OrderTicket(),OrderOpenPrice(),NewStopLoss,0,0,Blue);
     
  
  
  
  

//+------------------------------------------------------------------+
//| Sell Trade                                                       |
//+------------------------------------------------------------------+
  

  OrderSelect(BuyTrade,SELECT_BY_TICKET);
  NewStopLoss=OrderStopLoss();
  
  RefreshRates();
  //berechne neuen StopLoss
  if(OrderStopLoss()>Ask+Point*pipsStopLoss){
    NewStopLoss=NormalizeDouble(Ask+Point*pipsStopLoss,Digits);
  }
  
  //nur Stoploss anpassen
  RefreshRates();
  OrderModify(OrderTicket(),OrderOpenPrice(),NewStopLoss,0,0,Blue);
     
  
 
}

Soll an sich einfahc nur, wenn keine Trades auf sind, einen Buy und eine n Sell Trade gleichzeitig aufmachen.
kein Takeprofit, sondern bei Beidem nur StopLoss.
Jene StopLoss sollen dann, wenn der aktuelle Preis sich vom StopLoss entfernt hat (sprich: der Abstand zwischen aktuellem Preis und Stoploss größer geworden ist), nachgezogen werden (ein manuell gebauter TralingStopLoss).

Nun erhalt eich wiederum andere Errors, die irgendwie mit den Ordernummern nun Probleme haben:

Code:
2020.05.25 16:22:11.603	EURGBP,H4: 235692 tick events (144 bars, 236693 bar states) processed in 0:00:44.328 (total time 0:00:52.484)
2020.05.25 16:22:11.603	2020.04.02 23:58:09  Tester: order #84 is closed
2020.05.25 16:22:11.603	2020.04.02 23:58:09  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:58:09  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function
2020.05.25 16:22:11.602	2020.04.02 23:58:09  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:58:09  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function
2020.05.25 16:22:11.602	2020.04.02 23:58:07  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:58:07  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function
2020.05.25 16:22:11.602	2020.04.02 23:58:07  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:58:07  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function
2020.05.25 16:22:11.602	2020.04.02 23:57:30  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:57:30  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function
2020.05.25 16:22:11.602	2020.04.02 23:57:30  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:57:30  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function
2020.05.25 16:22:11.602	2020.04.02 23:56:52  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:56:52  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function
2020.05.25 16:22:11.602	2020.04.02 23:56:52  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:56:52  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function
2020.05.25 16:22:11.602	2020.04.02 23:56:15  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:56:15  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function
2020.05.25 16:22:11.602	2020.04.02 23:56:15  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:56:15  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function
2020.05.25 16:22:11.602	2020.04.02 23:55:37  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:55:37  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function
2020.05.25 16:22:11.602	2020.04.02 23:55:37  10 0 EA EURGBP,H4: OrderModify error 4108
2020.05.25 16:22:11.602	2020.04.02 23:55:37  10 0 EA EURGBP,H4: unknown ticket 83 for OrderModify function