Komission von offenen Trades ablesen - Seite 2

 

Hallo,

es ist schon bisschen länger her, aber wer nach solchen Fragen sucht wird vielleicht hier Parr Infos holen. 

Hier ist der Beispielkode, wie man Kommissionen, Swaps und Gewinn auf den Chart platziert.

Sorry, dass es als EA programmiert wurde.

// input ulong      Magic = 12345;                     // Magic number (könnte man auch verwenden, dann unten in Funktion auch freischalten)
input double KommBetrag      =    7;                   // Kommission pro Lot
input double SwapLong        =    0;                   // SwapLong kosten pro lot
input double SwapShort       =    0;                   // SwapShort kosten pro lot
input datetime time_von      =    D'2018.06.10 12:00'; // Von Datum
input datetime time_bis      =    D'2024.02.10 12:00'; // Bis Datum


int OnInit() {

   string currency       = " "+AccountInfoString(ACCOUNT_CURRENCY);

   double SwapLongWert, SwapShortWert;
   if(SwapLong != 0) {
      SwapLongWert   = SymbolInfoDouble(_Symbol,SYMBOL_SWAP_LONG);
   } else {
      SwapLongWert = SwapLong;
   }

   if(SwapShort != 0) {
      SwapShortWert  = SymbolInfoDouble(_Symbol,SYMBOL_SWAP_SHORT);
   } else {
      SwapShortWert  = SwapShort;
   }

// Kommentar
   double CommKostenBuy  = (SymbolBuyVolumen() * -KommBetrag) / 10;
   double CommKostenSell = (SymbolSellVolumen() * -KommBetrag) / 10;
   double SwapKostenBuy  = (SwapLongWert * SymbolBuyVolumen()) / 10;
   double SwapKostenSell  = (SwapLongWert * SymbolSellVolumen()) / 10;
   double summe          = SymbolGesamtProfit()+CommKostenBuy + CommKostenSell + SwapKostenBuy + SwapKostenSell;


   Comment("GesamtNettoGewinn: "+DoubleToString(SymbolGesamtProfit(),2)+currency+
           "\n Anzahl Trades: "+(string)NumberDeals()+
           "\n Gesamt Buy volumen: "+DoubleToString(SymbolBuyVolumen(),2)+" Lot"
           "\n Gesamt Sell volumen: "+DoubleToString(SymbolSellVolumen(),2)+" Lot"
           "\n Gesamt Buy Kommission: "+DoubleToString(CommKostenBuy,2)+
           "\n Gesamt Sell Kommission: "+DoubleToString(CommKostenSell,2)+
           "\n Gesamt Buy Swap: "+DoubleToString(SwapKostenBuy,2)+
           "\n Gesamt Sell Swap: "+DoubleToString(SwapKostenSell,2)+
           "\n GesamtBruttoGewinn: "+DoubleToString(summe,2));

   return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {

   Comment("");

}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick() {

   string currency       = " "+AccountInfoString(ACCOUNT_CURRENCY);

   double SwapLongWert, SwapShortWert;
   if(SwapLong != 0) {
      SwapLongWert   = SymbolInfoDouble(_Symbol,SYMBOL_SWAP_LONG);
   } else {
      SwapLongWert = SwapLong;
   }

   if(SwapShort != 0) {
      SwapShortWert  = SymbolInfoDouble(_Symbol,SYMBOL_SWAP_SHORT);
   } else {
      SwapShortWert  = SwapShort;
   }

// Kommentar
   double CommKostenBuy  = (SymbolBuyVolumen() * -KommBetrag) / 10;
   double CommKostenSell = (SymbolSellVolumen() * -KommBetrag) / 10;
   double SwapKostenBuy  = (SwapLongWert * SymbolBuyVolumen()) / 10;
   double SwapKostenSell  = (SwapLongWert * SymbolSellVolumen()) / 10;
   double summe          = SymbolGesamtProfit()+CommKostenBuy + CommKostenSell + SwapKostenBuy + SwapKostenSell;


   Comment("GesamtNettoGewinn: "+DoubleToString(SymbolGesamtProfit(),2)+currency+
           "\n Anzahl Trades: "+(string)NumberDeals()+
           "\n Gesamt Buy volumen: "+DoubleToString(SymbolBuyVolumen(),2)+" Lot"
           "\n Gesamt Sell volumen: "+DoubleToString(SymbolSellVolumen(),2)+" Lot"
           "\n Gesamt Buy Kommission: "+DoubleToString(CommKostenBuy,2)+
           "\n Gesamt Sell Kommission: "+DoubleToString(CommKostenSell,2)+
           "\n Gesamt Buy Swap: "+DoubleToString(SwapKostenBuy,2)+
           "\n Gesamt Sell Swap: "+DoubleToString(SwapKostenSell,2)+
           "\n GesamtBruttoGewinn: "+DoubleToString(summe,2));
}
//------------- Brutto berechnen Funktion ---------------------------
double SymbolGesamtProfit() {

// HistorySelect(von_datum,zum_datum);
   HistorySelect(time_von,time_bis);
   double total_profit    = 0.0;
   uint   total           = HistoryDealsTotal();
   ulong  ticket          = 0;

//--- for all deals
   for(uint i=0; i<total; i++) {
      //--- Sucht nach Tickets die grösser als Null sind
      if((ticket=HistoryDealGetTicket(i))>0) {
         long entry=HistoryDealGetInteger(ticket,DEAL_ENTRY);
         if(entry==DEAL_ENTRY_IN)
            continue;

         string symbol          = HistoryDealGetString(ticket,DEAL_SYMBOL);
         long   order_magic     = HistoryDealGetInteger(ticket,DEAL_MAGIC);
         double deal_profit     = HistoryDealGetDouble(ticket,DEAL_PROFIT);
         double profit          = deal_profit;
         // if(order_magic==Magic) {
         //... processing of deal with some DEAL_MAGIC
         if(symbol ==_Symbol) {

            if(profit>0.0)
               total_profit+=profit;
            if(profit<0.0)
               total_profit+=profit;
         }
         // }
      }
   }
   return(total_profit);
}

//------------- Anzahl Orders Funktion ---------------------------
int NumberDeals() {

// HistorySelect(von_datum,zum_datum);
   HistorySelect(time_von,time_bis);
   int anzahl = 0;
   uint total=HistoryDealsTotal();
   ulong    ticket=0;

//--- for all deals
   for(uint i=0; i<total; i++) {
      //--- Sucht nach Tickets die grösser als Null sind
      if((ticket=HistoryDealGetTicket(i))>0) {
         long entry=HistoryDealGetInteger(ticket,DEAL_ENTRY);
         if(entry==DEAL_ENTRY_IN)
            continue;

         string          symbol = HistoryDealGetString(ticket,DEAL_SYMBOL);
         long       order_magic = HistoryDealGetInteger(ticket,DEAL_MAGIC);
         // if(order_magic ==Magic) {
         //... processing of deal with some DEAL_MAGIC
         if(symbol==_Symbol) {
            anzahl++;
         }
         // }
      }
   }
   return(anzahl);
}
//------------- Buyorders volumen Funktion ---------------------------
double SymbolBuyVolumen() {

// HistorySelect(von_datum,zum_datum);
   HistorySelect(time_von,time_bis);
   double anzahl = 0.0;
   uint total=HistoryDealsTotal();
   ulong    ticket=0;

   long OrderType;

//--- for all deals
   for(uint i=0; i<total; i++) {
      //--- Sucht nach Tickets die grösser als Null sind
      if((ticket=HistoryDealGetTicket(i))>0) {
         long entry=HistoryDealGetInteger(ticket,DEAL_ENTRY);
         if(entry==DEAL_ENTRY_IN)
            continue;

         OrderType = HistoryDealGetInteger(ticket,DEAL_TYPE);

         string          symbol = HistoryDealGetString(ticket,DEAL_SYMBOL);
         long       order_magic = HistoryDealGetInteger(ticket,DEAL_MAGIC);
         double    volumen      = HistoryDealGetDouble(ticket,DEAL_VOLUME);
         double anzahl_volumen  = volumen;
         // if(order_magic ==Magic) {
         //... processing of deal with some DEAL_MAGIC
         if(symbol==_Symbol) {
            if(OrderType==DEAL_TYPE_BUY) {
               anzahl+=anzahl_volumen;
            }

         }
         // }
      }
   }
   return(anzahl);
}
//------------- Sellorders volumen Funktion ---------------------------
double SymbolSellVolumen() {

// HistorySelect(von_datum,zum_datum);
   HistorySelect(time_von,time_bis);
   double anzahl = 0.0;
   uint total=HistoryDealsTotal();
   ulong    ticket=0;

   long OrderType;

//--- for all deals
   for(uint i=0; i<total; i++) {
      //--- Sucht nach Tickets die grösser als Null sind
      if((ticket=HistoryDealGetTicket(i))>0) {
         long entry=HistoryDealGetInteger(ticket,DEAL_ENTRY);
         if(entry==DEAL_ENTRY_IN)
            continue;

         OrderType = HistoryDealGetInteger(ticket,DEAL_TYPE);

         string          symbol = HistoryDealGetString(ticket,DEAL_SYMBOL);
         long       order_magic = HistoryDealGetInteger(ticket,DEAL_MAGIC);
         double    volumen      = HistoryDealGetDouble(ticket,DEAL_VOLUME);
         double anzahl_volumen  = volumen;
         // if(order_magic ==Magic) {
         //... processing of deal with some DEAL_MAGIC
         if(symbol==_Symbol) {
            if(OrderType==DEAL_TYPE_SELL) {
               anzahl+=anzahl_volumen;
            }

         }
         // }
      }
   }
   return(anzahl);
}
//------------- Kommission und Swap berechnen Funktion ---------------------------
double SymbolKommSwap() {

// HistorySelect(von_datum,zum_datum);
   HistorySelect(time_von,time_bis);
   double komm_swap    = 0.0;
   uint   total           = HistoryDealsTotal();
   ulong  ticket          = 0;

//--- for all deals
   for(uint i=0; i<total; i++) {
      //--- Sucht nach Tickets die grösser als Null sind
      if((ticket=HistoryDealGetTicket(i))>0) {
         long entry=HistoryDealGetInteger(ticket,DEAL_ENTRY);
         if(entry==DEAL_ENTRY_IN)
            continue;

         string symbol          = HistoryDealGetString(ticket,DEAL_SYMBOL);
         long   order_magic     = HistoryDealGetInteger(ticket,DEAL_MAGIC);
         double deal_commission = HistoryDealGetDouble(ticket,DEAL_COMMISSION);
         double deal_swap       = HistoryDealGetDouble(ticket,DEAL_SWAP);
         double profit=deal_commission+deal_swap;
         // if(order_magic==Magic) {
         //... processing of deal with some DEAL_MAGIC
         if(symbol ==_Symbol) {
            komm_swap+=profit;
            // }
         }
      }
   }
   return(komm_swap);
}
//+------------------------------------------------------------------+

Gruß Igor


PS: UPS. Kleine Rechenfehler

Grund der Beschwerde: