Forex Expert Advisor long e short

EDGER - Un nuovo Forex EA doppio, cioè con una parte Long ed una Short che aiuta il trader a piazzare lo stoploss. Che cosa questo Forex Expert Advisor non è? Non è un metodo garantito per il successo! Ovviamente le perdite ci sono come sempre. Non è un sistema per le coperture o hedging. Questo Forex EA è uno strumento per piazzare ordini. Tuttavia, questo EA non effettuare ordini in base a qualsiasi altra cosa. Fermerà il suo lavoro dopo che questo scambio è finito. Quello che cerca questo tool.

 

Quello che cerca:

Si cerca di mettere "stop-loss-livello" più lontano di quanto si farebbe normalmente. Inoltre, essa cerca di evitare perdite più elevate anche se la stop-perdita è più lontano. Pertanto, con la creazione dell'ordine di una posizione di copertura viene creato all'interno dello stesso simbolo. La posizione viene creato ogni volta che il principale commercio raggiunge la sua "perdita-zone".
Ho volutamente scritto "cerca", perché il "metodo" ha i suoi difetti. Copertura di una posizione in un "livello zero loss" è difficile da raggiungere a causa della diffusione. Per compensare questo l'EA modifica automaticamente la copertura il più presto possibile equalizzare la diffusione della siepe. Sfortunatamente, questo non è sempre possibile. Se non ci riesce, si avrà un 2 * spread-perdita di ogni tempo.
Se la copertura non viene attivato (a causa di slittamento o il piccolo spazio tra la entry-prezzo e la posizione del trigger o l'al-livello zero fermato l'ex hedge), ci sono due possibilità inclusi per assicurare che le perdite non si ottiene troppo elevato:
"RiskSL": se non c'è copertura attiva, il livello di stop loss del principale-ordine sarà impostato automaticamente a una posizione definibile.
"RiskHedge": questo crea una nuova copertura in perdita-zona del commercio principale e circa 3 * diffondere lontano dal prezzo di entrata se la copertura normale non viene attivato. Questa possibilità permette di attaccare con la stop-loss predefinito, ma la stop-loss di questa siepe non crea perdite superiori a un normale farebbe. Se a causa di slittamento o di qualsiasi altra cosa questa siepe non viene creato lo stesso principio con "RiskSL" imposterà la stop-loss a un livello definibile.
"RiskSLN" imposterà la stop-loss-distanza in entrambi i casi. VALORE INTERO! Moltiplicato con i Punti. Ovviamente non è possibile attivare contemporaneamente entrambi i metodi. Questa è una delle ragioni per cui ho caricato il mio EA. Sia che si utilizzi uno o l'altro dipende da quale tempo-base è il commercio ed è una questione di esperienza. Ciò significa che questo EA richiede la conoscenza su come il commercio ! Come accennato prima: questo è uno strumento di ordine-placement! sarei molto grato se qualcuno potrebbe testare il mio EA e rispondere quello che funziona meglio in che cosa dimensioni per lui / lei.

Inoltre, l'EA cerca di minimizzare le perdite di un sistema di trascinamento . Per chiarire che subito: Questa funzione ha lo scopo di ridurre al minimo le perdite e non per fare profitto. Pertanto, la copertura non ha take-profit nell'ordine stesso. Il take-profit sarà attivato se l'ordine principale viene interrotta. A questo punto la differenza tra copertura e ordine principale è di circa 2 * diffusione. La EA ora cerca di "strascicare" il prezzo di mercato in una relativamente piccola distanza per guadagnare si spera almeno altri 2 punti. Per raggiungere questo obiettivo ci sono alcuni altri codici linee della EA, ma io non voglio entrare troppo nei dettagli. L'take-profit del main-ordine ha un sistema simile. proposito, la distanza è definibile . La copertura è regolata da NSL_21_Wert, il main-ordine da NewTP_21_Wert (Wert = valore) (double-Var, moltiplicato con * Point). Questo è il fine tuning. I valori possibili sono 1-9. I risultati possono a volte differire molto. Dal momento che si tratta di una statisticamente importa per ottenere il valore di lavorare meglio: se qualcuno tenta questa funzione per favore fatemelo sapere quale funziona meglio per voi in generale (differenze nei risultati possono essere facilmente visibile nel tester strategia).

Troppe perdite? Stop

Un'altra funzione di EA è quello di porre fine al commercio se le siepi producono troppo perdite. Questo può essere disattivata. Tuttavia, se k_aktivieren = true (aktivieren = attivare), la funzione viene attivata e si concluderà l'intero commercio se le siepi hanno prodotto perdite di quattro volte. Non si fermerà tutto e subito, ma un take-profit per l'ordine principale sarà fissata a una distanza di 7 * diffusione di ottenere almeno un po 'di soldi.
L'ultima funzione è la regola 75-50. E 'disabilitato di default, ma può essere attivato attraverso Regel_75_50 (Regel = regola). Questa regola misura la distanza tra il take-profit e l'entry-prezzo dell'ordine principale. Se il prezzo di mercato raggiunge il 75% di quella distanza il main-ordine-stoploss sarà modificato e impostato al 50% di quella distanza.

Importante:

Questo EA lavora con OrderSelect -> "Seleziona da posizione" ordini! Questo significa che non puoi avere altri ordini (in corso) nel terminale! In caso contrario, sarà sicuramente causare problemi! Forse cambierò che a volte, ma non ho il tempo al momento.

Si noti inoltre che questo EA manca di qualche messa a punto e non si pensa che sia del tutto definitiva in questo momento! (Funziona, però, ma non posso dire con certezza se ci potrebbero essere alcuni problemi lasciati. Se siete interessati a questo EA, si prega di consultare sempre gli aggiornamenti).
E se avete intenzione di usare questo programma: testare questo fondo prima ancora di considerare di utilizzare questo per reali trading-situazioni. Ho appena provato questo con un conto demo fino ad ora, quindi non posso darti consigli "vita reale" qui e non so come andrà a andare avanti con requote e slippage.
Anche considerare il rapporto rischio-opportunità. È possibile uscire dalla copertura senza perdite. Ma questo non funziona per tutto il tempo. Normalmente si dovrà accettare perdite minori dovuti alle chiude copertura; tenere a mente. Si noti che è ho avvertito qui e che non posso garantire una funzione di negoziazione a tutti!

Nota: la rimozione l'esperto chiude tutti gli ordini aperti e cancella tutti gli ordini in sospeso!
Essa, inoltre, non ha molta importanza quale arco di tempo si usa (vedi punto precedente). Ma, si prega di essere consapevoli del fatto che gli ordini sono chiuse se si modifica il periodo di tempo in un commercio attivo. Pertanto, assicurarsi di inserire l'EA in una finestra aggiuntiva, al fine di andare avanti con le vostre analisi. Ci sono due Forex EA collegati. Hedger_Short è per ordini short e viceversa.

EDGER SHORT

//Author: Markus Haberzettl
//This does not guarantee successful trades or any trading functionality at all!!
 
 
extern double Preis = 0;            //Preis = Price
extern double StopLoss = 0;
extern double TakeProfit = 0;
extern double Lots = 0.1;
extern double NSL_21_Wert = 5;
extern double NewTP_21_Wert = 5;
extern bool RiskHedge = false;         // 2x (2/5 Ђ besser) // "/" als Trennstrich, nur gerundete int-Werte
extern bool RiskSL = true;             // 1x (11  Ђ besser)
extern int RiskSLN = 100;
extern bool Regel_75_50 = false;
extern bool k_aktivieren = true;
 
int init ()
{
  if (RiskSL == true && RiskHedge == true) return(0);
  double spread=MarketInfo(Symbol(),MODE_SPREAD)*Point;  
         OrderSend(Symbol(),OP_SELLLIMIT,Lots,Preis,0,StopLoss,0,"Selbst gesetzte Short-Order",0,CLR_NONE);       //TP = 0 wg. 6.
         OrderSend(Symbol(),OP_BUYSTOP,Lots,Preis+spread,0,Preis-spread,0,"Hedge zur Short-Order",0,CLR_NONE);    //TP = 0 wg. 5.  
return(0);
}
 
 
bool OM_1, OM_3, aktiv_1, aktiv_2, aktiv_4, aktiv_5, aktiv_6, k_aktiv, aktiv_RiskHedge, aktiv_72, aktiv_RiskHedgeSL, a, d, k_multiplier;
int i_2, k, hst_total;
double NewSL_21, NewTP_21;
 
 
 
int start ()
{
 
Comment(
"\n", "Preis:      ", Preis,
"\n", "StopLoss:   ", StopLoss,
"\n", "TakeProfit: ", TakeProfit,
"\n", "75_50:      ", Regel_75_50,
"\n", "RiskSL:     ", RiskSL,
"\n", "RiskSLN:    ", RiskSLN,
"\n", "RiskHedge:  ", RiskHedge
);
 
 
double spread=MarketInfo(Symbol(),MODE_SPREAD)*Point;
int total=OrdersTotal();
 
      //if (aktiv_RiskHedgeSL == true && total == 1) aktiv_RiskHedgeSL = false;
     
      //Beenden des Trades, wenn Hedge 4x Verlust gemacht hat
      //if (total == 1 && aktiv_RiskHedge == true && aktiv_RiskHedgeSL == false) k++;
      if (total == 1 && aktiv_RiskHedge == true && k_multiplier == false) {k++; k_multiplier = true;}
 
      if (k == 3 && k_aktiv == false && k_aktivieren == true) {
         OrderSelect(0,SELECT_BY_POS);
         if (OrderType() == OP_SELL) bool OM_E=OrderModify(OrderTicket(),0,StopLoss,Preis - 7*spread,0,CLR_NONE);
         if (OM_E == true) Print ("Ende initiiert");
         k_aktiv = true;
      }
   
      //2.
      if (Bid>(Preis+spread) && total == 2 && aktiv_2 == false && aktiv_5 == false && aktiv_RiskHedge == false) 
      {
         Print ("2. aktiviert");
         OrderSelect(1,SELECT_BY_POS);
         if (OrderType() == OP_BUY) OM_1=OrderModify(OrderTicket(),0,Preis+spread,0,0,CLR_NONE);
         if (OM_1 == true) aktiv_2 = true;
      }
      
      //3.+4.+1.
      if (total == 1) OrderSelect(0,SELECT_BY_POS);
      if (total == 1 && OrderType() == OP_SELL && Ask < Preis) {  
         Print ("3.+4.+1. aktiviert");
         if (aktiv_2 == false) k++;
         OrderSend(Symbol(),OP_BUYSTOP,Lots,Preis+spread,0,Preis-spread,0,"Hedge zur Short-Order",0,CLR_NONE);
         if (OrdersTotal() == 2) {
            aktiv_4 = true;
            aktiv_2 = false;
            aktiv_RiskHedge = false;
            k_multiplier = false;
            if (aktiv_72 == true) {
               OrderSelect(0,SELECT_BY_POS);
               if (OrderType() == OP_SELL) OrderModify(OrderTicket(),0,StopLoss,0,0,CLR_NONE);
            }
            aktiv_72 = false;
            Print ("k: ", k);
         }
      }
      
      //5. Trailing-Hedge beim SL-Eintritt der NO     
      //5.1 Hedge-SL wird auf ursprьnglich geplanten TP gezogen
      double NewSL = StopLoss-1.1*spread; //Normal wдre StopLoss-spread der TP des Hedges //geht das auf dauer??? durchtesten, da eigentlich zu knapp (wohl eher 1.1*spread oder so
      if (Ask >= StopLoss && aktiv_5 == false && total > 0)  {
         Print ("5.1 aktiviert");
         OrderSelect(0,SELECT_BY_POS);
         if (OrderType() == OP_BUY) {
            aktiv_5=OrderModify(OrderTicket(),0,NewSL,0,0,CLR_NONE);
            }
      }      
      //5.2 Trailing-SL
      if (aktiv_5 == true && total > 0) {
         Print ("5.2 aktiviert");
         OrderSelect(0,SELECT_BY_POS);
         if (OrderType() == OP_BUY) {
            if (Bid >= StopLoss && a == false) {
               bool OM_52=OrderModify(OrderTicket(),0,StopLoss,0,0,CLR_NONE);
               if (OM_52 == true) a = true;
            }
            if (Bid > (OrderStopLoss()+spread) && a == true) {
               NewSL_21 = OrderStopLoss() + (Bid - OrderStopLoss() - NSL_21_Wert*Point);  //Wert darf 1 nicht ьberschreiten, da nдchster SL sonst niegriger liegen wьrde!! 
               //Statistisch bester Wert (Wert x Anzahl): 0.8x1 0.4x1 0.6x1 0.5x1 0.1x1
               NormalizeDouble(NewSL_21,Digits);
               if (NewSL_21 > OrderStopLoss()) {  
                  OrderModify(OrderTicket(),0,NewSL_21,0,0,CLR_NONE);
               }
            }
         }          
      } //schlieЯen von if (aktiviere 5)     
      
      //6. Trailing-TP bei TP-Eintritt der NO
      
      double NewTP = TakeProfit + 0.5*spread; //NewTP zieht SL nach!!!  //hier nicht das Problem von 5., da TP = Bid ist und vorher auch schon war
      if (Ask <= TakeProfit && aktiv_6 == false && total > 0)  {        //                                    //
         OrderSelect(0,SELECT_BY_POS);                                  //
         if (OrderType() == OP_SELL) {   
            Print ("6.1 aktiviert");                                  //
            aktiv_6=OrderModify(OrderTicket(),0,NewTP,0,0,CLR_NONE);    //an TP = SL denken!!
            }
      }      
      //6.2 Trailing-SL
      if (aktiv_6 == true && total > 0) {                               //
         OrderSelect(0,SELECT_BY_POS);                                  //
         if (OrderType() == OP_SELL) {   
            if (Ask < (OrderStopLoss()-spread)) {   
               Print ("6.2 aktiviert");                                       //
               NewTP_21 = OrderStopLoss() - (OrderStopLoss() - Ask - NewTP_21_Wert*Point); //
               NormalizeDouble(NewTP_21,Digits);                        //
               if (NewTP_21 < OrderStopLoss()) {                        //
                  OrderModify(OrderTicket(),0,NewTP_21,0,0,CLR_NONE);   //
               }
            }
         }          
      } //schlieЯen von if (aktiviere 6)
      
   //75-50-Regel
   OrderSelect(0,SELECT_BY_POS);
   if (OrderType() == OP_SELL && d == false && Regel_75_50 == true) {
      double b,c;
      b = (Preis - TakeProfit)*0.75;
      c = Preis - ((Preis - TakeProfit)*0.5);
      if (Ask <= (Preis - b)) d=OrderModify(OrderTicket(),0,c,0,0,CLR_NONE);
      if (d == true) Print ("75-50 aktiv");
   }
    
   //7.1 RisikominimierungsHedge
   if (RiskHedge == true) {
      OrderSelect(0,SELECT_BY_POS);
      if (total == 1 && OrderType() == OP_SELL && aktiv_2 == true && Ask > (Preis+3*spread)) {
         OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Preis+spread,0,"RiskHedge",0,0,CLR_NONE); 
         aktiv_RiskHedge = true;
      }
   }
 /*
   if (aktiv_RiskHedge == true && aktiv_RiskHedgeSL == false) { //Zieht SL des Hedges auf 0-Niveau nach
      OrderSelect(1,SELECT_BY_POS);
      if (OrderType() == OP_BUY && Bid > OrderOpenPrice() && total == 2) {    
         aktiv_RiskHedgeSL=OrderModify(OrderTicket(),0,OrderOpenPrice()-spread,0,0,CLR_NONE);
      }
   }
   */
      //7.1.1 RiskSL-Absicherung fьr RiskHedge
      //sollte wegen Ask > (Preis+3*spread) eigentlich nie greifen
   if (RiskHedge == true && OrdersTotal() == 1 && Ask > Preis+RiskSLN*Point*spread) {
      OrderSelect(0,SELECT_BY_POS);
      if (OrderType() == OP_SELL) OrderClose(OrderTicket(),Lots,Ask,1,CLR_NONE);
   }
   
   //7.2 SL der NO nachziehen anstatt Risikohedge
   if (RiskSL == true && aktiv_72 == false) {
      OrderSelect(0,SELECT_BY_POS);
      if (k_aktiv == false && total == 1 && OrderType() == OP_SELL && aktiv_2 == true && StopLoss >= Preis+RiskSLN*Point*spread) bool OM_RSL1=OrderModify(OrderTicket(),0,Preis+RiskSLN*Point*spread,0,0,CLR_NONE);
      if (OM_RSL1 == true) aktiv_72 = true;
      if (k_aktiv == true && total == 1 && OrderType() == OP_SELL && aktiv_2 == true && StopLoss >= Preis+RiskSLN*Point*spread) bool OM_RSL2=OrderModify(OrderTicket(),0,Preis+RiskSLN*Point*spread,Preis - 7*spread,0,CLR_NONE);
      if (OM_RSL2 == true) aktiv_72 = true; 
   }
  
   //Lцschen offener Pending-Order, wenn NO rausfliegt
   if (total > 0) OrderSelect(0,SELECT_BY_POS);
   if (aktiv_4 ==  true && OrderType() != OP_SELL && total != 0 && OrderType() != OP_BUY) OrderDelete(OrderTicket());
 
return(0);
}
 
 
 
int deinit ()
{
   while (OrdersTotal()>0) {
      OrderSelect(0,SELECT_BY_POS);
      if (OrderType() == OP_BUY) OrderClose(OrderTicket(),Lots,Bid,1,CLR_NONE);
      if (OrderType() == OP_SELL)OrderClose(OrderTicket(),Lots,Ask,1,CLR_NONE);
      if (OrderType() != OP_BUY && OrderType() != OP_SELL) OrderDelete(OrderTicket(),CLR_NONE);
   }        
 
return(0);
}

 

 

EDGER LONG

//Author: Markus Haberzettl
//This does not guarantee successful trades or any trading functionality at all!!
 
 
extern double Preis = 0;            //Preis = Price
extern double StopLoss = 0;
extern double TakeProfit = 0;
extern double Lots = 0.1;
extern double NSL_21_Wert = 5;
extern double NewTP_21_Wert = 5;
extern bool RiskHedge = false;         
extern bool RiskSL = true;             
extern int RiskSLN = 100;
extern bool Regel_75_50 = false;
extern bool k_aktivieren = true;
 
int init ()
{
  if (RiskSL == true && RiskHedge == true) return(0);
  double spread=MarketInfo(Symbol(),MODE_SPREAD)*Point;  
         OrderSend(Symbol(),OP_BUYLIMIT,Lots,Preis,0,StopLoss,0,"Selbst gesetzte Long-Order",0,0,CLR_NONE);         //TP = 0 wg. 6.
         OrderSend(Symbol(),OP_SELLSTOP,Lots,Preis-spread,0,Preis+spread,0,"Hedge zur Long-Order",0,0,CLR_NONE);    //TP = 0 wg. 5.      
return(0);
}
 
 
bool OM_1, OM_3, aktiv_1, aktiv_2, aktiv_4, aktiv_5, aktiv_6, k_aktiv, aktiv_RiskHedge, aktiv_72, aktiv_RiskHedgeSL, a, d, k_multiplier;
int i_2, k;
double NewSL_21, NewTP_21;
 
 
 
int start ()
{
 
Comment(
"\n", "Preis:      ", Preis,
"\n", "StopLoss:   ", StopLoss,
"\n", "TakeProfit: ", TakeProfit,
"\n", "Lots:       ", Lots,
"\n", "75_50:      ", Regel_75_50,
"\n", "RiskSL:     ", RiskSL
);
 
 
double spread=MarketInfo(Symbol(),MODE_SPREAD)*Point;
int total=OrdersTotal();
  
      if (total == 1 && aktiv_RiskHedge == true && k_multiplier == false) {k++; k_multiplier = true;}
    
      //Beenden des Trades, wenn Hedge 4x Verlust gemacht hat
      if (total == 1 && aktiv_RiskHedge == true && aktiv_RiskHedgeSL == false) k++;
      if (k == 4 && k_aktiv == false && k_aktivieren == true) {
         OrderSelect(0,SELECT_BY_POS);
         if (OrderType() == OP_BUY) bool OM_E=OrderModify(OrderTicket(),0,StopLoss,Preis + 7*spread,0,CLR_NONE);
         if (OM_E == true) Print ("Ende initiiert");
         k_aktiv = true;
      }
   
      //2.
      
      if (Ask < (Preis-spread) && total == 2 && aktiv_2 == false && aktiv_5 == false && aktiv_RiskHedge == false) 
      {
         Print ("2. aktiviert");
         OrderSelect(1,SELECT_BY_POS);
         if (OrderType() == OP_SELL) OM_1=OrderModify(OrderTicket(),0,Preis-spread,0,0,CLR_NONE);
         if (OM_1 == true) aktiv_2 = true;
      }
      
      //3.+4.+1.
      if (total == 1) OrderSelect(0,SELECT_BY_POS);
      if (total == 1 && OrderType() == OP_BUY && Bid > Preis) {  
         Print ("3.+4.+1. aktiviert");
         if (aktiv_2 == false) k++;
         OrderSend(Symbol(),OP_SELLSTOP,Lots,Preis-spread,0,Preis+spread,0,"Hedge zur Long-Order",0,CLR_NONE);
         if (OrdersTotal() == 2) {
            aktiv_4 = true;
            aktiv_2 = false;
            aktiv_RiskHedge = false;
            k_multiplier = false;
            if (aktiv_72 == true) {
               OrderSelect(0,SELECT_BY_POS);
               if (OrderType() == OP_BUY) OrderModify(OrderTicket(),0,StopLoss,0,0,CLR_NONE);
            }
            aktiv_72 = false;
            Print ("k: ", k);
         }
      }
      
      //5. Trailing-Hedge beim SL-Eintritt der NO     
      //5.1 Hedge-SL wird auf ursprьnglich geplanten TP gezogen
      double NewSL = StopLoss+1.1*spread; //Normal wдre StopLoss-spread der TP des Hedges //geht das auf dauer??? durchtesten, da eigentlich zu knapp (wohl eher 1.1*spread oder so
      if (Bid <= StopLoss && aktiv_5 == false && total > 0)  {
         Print ("5.1 aktiviert");
         OrderSelect(0,SELECT_BY_POS);
         if (OrderType() == OP_SELL) {
            aktiv_5=OrderModify(OrderTicket(),0,NewSL,0,0,CLR_NONE);
            }
      }      
      //5.2 Trailing-SL
      if (aktiv_5 == true && total > 0) {
         Print ("5.2 aktiviert");
         OrderSelect(0,SELECT_BY_POS);
         if (OrderType() == OP_SELL) {
            if (Ask <= StopLoss && a == false) {
               bool OM_52=OrderModify(OrderTicket(),0,StopLoss,0,0,CLR_NONE);
               if (OM_52 == true) a = true;
            }
            if (Ask < (OrderStopLoss()-spread) && a == true) {
               NewSL_21 = OrderStopLoss() - (OrderStopLoss() - Ask - NSL_21_Wert*Point);  //Wert darf 1 nicht ьberschreiten, da nдchster SL sonst niegriger liegen wьrde!! 
               //Statistisch bester Wert (Wert x Anzahl): 
               NormalizeDouble(NewSL_21,Digits);
               if (NewSL_21 < OrderStopLoss()) {  
                  OrderModify(OrderTicket(),0,NewSL_21,0,0,CLR_NONE);
               }
            }
         }          
      } //schlieЯen von if (aktiviere 5)     
      
      //6. Trailing-TP bei TP-Eintritt der NO
      
      double NewTP = TakeProfit - 0.5*spread; //NewTP zieht SL nach!!!  //hier nicht das Problem von 5., da TP = Bid ist und vorher auch schon war
      if (Bid >= TakeProfit && aktiv_6 == false && total > 0)  {        //                                    //
         OrderSelect(0,SELECT_BY_POS);                                  //
         if (OrderType() == OP_BUY) {   
            Print ("6.1 aktiviert");                                  //
            aktiv_6=OrderModify(OrderTicket(),0,NewTP,0,0,CLR_NONE);    //an TP = SL denken!!
            }
      }      
      //6.2 Trailing-SL
      if (aktiv_6 == true && total > 0) {                               //
         OrderSelect(0,SELECT_BY_POS);                                  //
         if (OrderType() == OP_BUY) {   
            if (Bid > (OrderStopLoss()+spread)) {   
               Print ("6.2 aktiviert");                                       //
               NewTP_21 = OrderStopLoss() + (Bid - OrderStopLoss() - NewTP_21_Wert*Point); //
               NormalizeDouble(NewTP_21,Digits);                        //
               if (NewTP_21 > OrderStopLoss()) {                        //
                  OrderModify(OrderTicket(),0,NewTP_21,0,0,CLR_NONE);   //
               }
            }
         }          
      } //schlieЯen von if (aktiviere 6)
      
   //75-50-Regel
   OrderSelect(0,SELECT_BY_POS);
   if (OrderType() == OP_BUY && d == false && Regel_75_50 == true) {
      double b,c;
      b = (TakeProfit - Preis)*0.75;
      c = Preis + ((TakeProfit - Preis)*0.5);
      if (Bid >= (Preis + b)) d=OrderModify(OrderTicket(),0,c,0,0,CLR_NONE);
   }
   
   //7.1 RisikominimierungsHedge
   if (RiskHedge == true) {
      OrderSelect(0,SELECT_BY_POS);
      if (total == 1 && OrderType() == OP_BUY && aktiv_2 == true && Bid < (Preis-3*spread)) {
         OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Preis-spread,0,"RiskHedge",0,0,CLR_NONE); 
         aktiv_RiskHedge = true;
      }
   }
 /*
   if (aktiv_RiskHedge == true && aktiv_RiskHedgeSL == false) { //Zieht SL des Hedges auf 0-Niveau nach
      OrderSelect(1,SELECT_BY_POS);
      if (OrderType() == OP_SELL && Ask < OrderOpenPrice() && total == 2) {    
         aktiv_RiskHedgeSL=OrderModify(OrderTicket(),0,OrderOpenPrice()+spread,0,0,CLR_NONE);
      }
   }
   */
 
        
      //7.1.1 RiskSL-Absicherung fьr RiskHedge
   if (RiskHedge == true && OrdersTotal() == 1 && Bid < Preis-RiskSLN*Point*spread) {
      OrderSelect(0,SELECT_BY_POS);
      if (OrderType() == OP_BUY) OrderClose(OrderTicket(),Lots,Bid,1,CLR_NONE);
   }
   
   //7.2 SL der NO nachziehen anstatt Risikohedge
   if (RiskSL == true && aktiv_72 == false) {
      OrderSelect(0,SELECT_BY_POS);
      if (k_aktiv == false && total == 1 && OrderType() == OP_BUY && aktiv_2 == true && StopLoss <= Preis-RiskSLN*Point*spread) bool OM_RSL1=OrderModify(OrderTicket(),0,Preis-RiskSLN*Point*spread,0,0,CLR_NONE);
      if (OM_RSL1 == true) aktiv_72 = true;
      if (k_aktiv == true && total == 1 && OrderType() == OP_BUY && aktiv_2 == true && StopLoss <= Preis-RiskSLN*Point*spread) bool OM_RSL2=OrderModify(OrderTicket(),0,Preis-RiskSLN*Point*spread,Preis + 7*spread,0,CLR_NONE);
      if (OM_RSL2 == true) aktiv_72 = true; 
   }
  
   //Lцschen offener Pending-Order, wenn NO rausfliegt
   if (total > 0) OrderSelect(0,SELECT_BY_POS);
   if (aktiv_4 ==  true && OrderType() != OP_SELL && total != 0 && OrderType() != OP_BUY) OrderDelete(OrderTicket());
 
return(0);
}
 
 
int deinit ()
{
   while (OrdersTotal()>0) {
      OrderSelect(0,SELECT_BY_POS);
      if (OrderType() == OP_BUY) OrderClose(OrderTicket(),Lots,Bid,1,CLR_NONE);
      if (OrderType() == OP_SELL)OrderClose(OrderTicket(),Lots,Ask,1,CLR_NONE);
      if (OrderType() != OP_BUY && OrderType() != OP_SELL) OrderDelete(OrderTicket(),CLR_NONE);
   }        
 
return(0);
}