lot_rebate_calculator
Download scriptThis script serves as an automated reporting tool designed to calculate and display your accumulated trading rebates based on your historical order data. Its primary function is to aggregate the total volume of trades you have executed within a specific timeframe and convert that volume into a monetary rebate value.
How the Logic Works
1. Filtering Historical Data The script begins by scanning your account's trade history. It looks specifically for completed "Buy" or "Sell" orders that were closed on or after a specific date provided by the user (the "Start Date"). By ignoring trades made before this date, it allows you to isolate your trading activity for a specific period, such as a month or a year.
2. Volume Calculation As the script identifies these eligible trades, it adds up the total number of "Lots" traded. It treats every completed transaction in the filtered history as part of a running total, ensuring that all relevant trading volume is accounted for.
3. Rebate Computation Once the script has determined the total lot volume, it applies a secondary calculation. It takes the "Rebate Per Lot" value (a dollar amount defined by the user) and multiplies it by the total lots traded. This produces your final rebate earnings.
4. Visual Reporting Finally, instead of just performing the math in the background, the script generates a visual dashboard directly on your trading chart. It creates a clear text display that shows four key pieces of information:
- The designated Start Date used for the calculation.
- The Total Lots traded since that date.
- The specific Rebate rate per lot being used.
- The final calculated "My Rebate" amount.
Summary of Purpose
Essentially, this tool acts as a performance tracker. It automates the tedious task of manually summing up trade volumes from your history and instantly translates those numbers into a dollar value, providing you with a real-time summary of your earned rebates directly on your screen.
//+------------------------------------------------------------------+
//| Lot Calculator.mq4 |
//| Copyright © 2015, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property show_confirm
#property show_inputs
extern string StartDate="2016.04.01";
extern double RebatePerLot=6;
extern color TColor=clrRed;
int ticket;
int OpType;
double asbid,TP;
double JarLevel;
double totlots;
//+------------------------------------------------------------------+
//| script "send pending order with expiration data" |
//+------------------------------------------------------------------+
int start()
{
datetime iStart=StringToTime(StartDate);
totlots=0;
for(int cnt=0; cnt<OrdersHistoryTotal(); cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==True)
{
if(OrderTicket()>0 && OrderCloseTime()>=iStart && (OrderType()==OP_BUY || OrderType()==OP_SELL))
{
totlots=totlots+OrderLots();
}
}
}
double myRebate=RebatePerLot*totlots;
// Comment("\n\n\n. . . TOTAL LOTS : ",totlots,
// "\n. . . Rebte/Lots : $ ",RebatePerLot,
// "\n. . . my Rebate : $ ",myRebate);
dpkfx();
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void dpkfx()
{
int ipos=3;
int xpos=30;
double myRebate=RebatePerLot*totlots;
int st=1;
stats("d","Start Date : "+StartDate,9,"Arial",TColor,ipos,xpos-1,65);
stats("a","TOTAL LOTS : "+DoubleToStr(totlots,2),9,"Arial",TColor,ipos,xpos-1,50);
stats("b","Rebate / Lots : $ "+DoubleToStr(RebatePerLot,2),9,"Arial",TColor,ipos,xpos,35);
stats("c","my Rebate : $ "+DoubleToStr(myRebate,2),9,"Arial",TColor,ipos,xpos-1,20);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void stats(string tname,string word,int fsize,string ftype,color tcolor,int posxy,int posx,int posy)
{
ObjectCreate(tname,OBJ_LABEL,0,0,0);
ObjectSetText(tname,word,fsize,ftype,tcolor);
ObjectSet(tname,OBJPROP_CORNER,posxy);
ObjectSet(tname,OBJPROP_XDISTANCE,posx);
ObjectSet(tname,OBJPROP_YDISTANCE,posy);
}
//+------------------------------------------------------------------+
Comments