Author: it-yy.site Copyright 2024
Orders Execution
Checks for the total of open orders
0 Views
0 Downloads
0 Favorites
showSwap
ÿþ//+------------------------------------------------------------------+

//|                                                     showSwap.mq4 |

//|                                                   Copyright 2024 |

//|                                                 eurweb@gmail.com |

//|                                                       it-yy.site |

//+------------------------------------------------------------------+

#property copyright "it-yy.site Copyright 2024"

#property link      "it-yy.site"

#property link      "eurweb@gmail.com"

#property version   "1.50"



#property indicator_chart_window

#property description   "show orders swap and swap info"

#property description   "Contact  eurweb@gmail.com"

#property description   "WARNING: Use this software at your own risk."

#property strict





sinput string SETTINGS1 = "====  General Settings ==== ";

input int MAGIC = 0; //MAGIC , if = 0 -> all

input int timer_period = 10;// 2@5<O >1=>2;5=8O 2 A5:



sinput string SETTINGS2 = "====  View Settings ==== ";

input int x = 30;// x coordinate 

input int y = 200;// y coordinate

input color textcolor = clrBlack;// text color

input color foncolor = clrGray;// fon color



//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

{

   initGui();

   //--- Amount of accrued swap for orders

   checkOrders();

   //--- information about current swaps

   getSwapInfo();

   

   EventSetTimer(timer_period);

   

   return(INIT_SUCCEEDED);

}



//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void OnTimer()

  {

    //---

    checkOrders(); 

    

    getSwapInfo(); 

    

  }





//+------------------------------------------------------------------+

//| getSwapInfo()                                                    |

//| shows SWAP on the chart                                          |

//+------------------------------------------------------------------+

void getSwapInfo()

{



  LabelTextChange("yy_ss_labelinfo_3",StringFormat("Market SWAP Buy: %.2f",SymbolInfoDouble(_Symbol,SYMBOL_SWAP_LONG)));

  LabelTextChange("yy_ss_labelinfo_4",StringFormat("Market SWAP Sell: %.2f",SymbolInfoDouble(_Symbol,SYMBOL_SWAP_SHORT)));

  

  //--- old version

  //LabelTextChange("yy_ss_labelinfo_3",  "Market SWAP Buy "+ Symbol() +":" + DoubleToStr(MarketInfo(Symbol(),MODE_SWAPLONG),2));

  //LabelTextChange("yy_ss_labelinfo_4",  "Market SWAP Sell "+ Symbol() +":" + DoubleToStr(MarketInfo(Symbol(),MODE_SWAPSHORT),2)); 



}



//+------------------------------------------------------------------+

//|   checkOrders                                                    |

//+------------------------------------------------------------------+

int checkOrders()

{

   ResetLastError();

   int co = OrdersTotal();

   double sellswap = 0;

   double buyswap  = 0;



   for (int i = co - 1; i >= 0; i--)

   {

       if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

       

       if(OrderSymbol() != Symbol()) continue;

       

       if(OrderMagicNumber() != MAGIC && 0 != MAGIC) continue;

       

       if (OrderType() == OP_BUY)

       {

          buyswap  += OrderSwap();

       }

       if (OrderType() == OP_SELL)

       {

          sellswap += OrderSwap();

       }

   }

   



   LabelTextChange("yy_ss_labelinfo_1",  "Orders Sell Swap: " + DoubleToStr(sellswap,2));

   LabelTextChange("yy_ss_labelinfo_2",  "Orders Buy Swap: "  + DoubleToStr(buyswap,2));

   LabelTextChange("yy_ss_labelinfo_5", (string) TimeCurrent());

  

   return 1;

}  

  

//+------------------------------------------------------------------+

//| initGui function                                                   |

//+------------------------------------------------------------------+  

void initGui()

{

    DrawBox("yy_ss_box1",x, 190, y, 130, foncolor, clrLightGray);

    PutLabel("yy_ss_labelinfo_1","",x + 4 ,y + 5,  textcolor);

    PutLabel("yy_ss_labelinfo_2","", x + 4 ,y + 30, textcolor);

    PutLabel("yy_ss_labelinfo_3","",x + 4 ,y + 55,  textcolor);

    PutLabel("yy_ss_labelinfo_4","", x + 4 ,y + 80, textcolor);

    PutLabel("yy_ss_labelinfo_5","", x + 4 ,y + 105, textcolor);   

}





//+------------------------------------------------------------------+

//| LabelTextChange                                                  |

//+------------------------------------------------------------------+

void LabelTextChange(string name,string text)

{



   if(!ObjectSetString(0,name,OBJPROP_TEXT,text))

   {

      Print(__FUNCTION__,": Error = = ",GetLastError());

   }

}





//+------------------------------------------------------------------+

//|   PutLabel                                                       |

//+------------------------------------------------------------------+

void PutLabel(string name,string text,int _x,int _y, color clr , int corner = CORNER_LEFT_UPPER)

{

   if(ObjectFind(0,name) > -1) return;

   

   ObjectCreate(0,name,OBJ_LABEL,0,0,0);

   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,_x);

   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,_y);

   ObjectSetInteger(0,name,OBJPROP_CORNER,0);

   ObjectSetString(0,name,OBJPROP_TEXT,text);

   ObjectSetString(0,name,OBJPROP_FONT,"Arial");

   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,9);

   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);

   

   ObjectSetInteger(0,name,OBJPROP_CORNER,corner);

}







//+------------------------------------------------------------------+

//|   DrawBox                                                        |

//+------------------------------------------------------------------+

void DrawBox(string nm, int _x, int xsize, int _y, int ysize,  

         color BackColor = clrBlack, color BorderColor = clrBlack, int corner = CORNER_LEFT_UPPER )

{



  if(ObjectFind(0,nm) > -1) return;

  if(!ObjectCreate(0, nm, OBJ_RECTANGLE_LABEL, 0, 1, 1, 1, 1))

  {

    Print(__FUNCTION__,": =5 C40;>AL A>740BL ?@O<>C3>;L=8:! >4 >H81:8 = ", GetLastError());

    return;

  }



  ObjectSetInteger(0, nm, OBJPROP_XDISTANCE, _x);

  ObjectSetInteger(0, nm, OBJPROP_YDISTANCE, _y);

  ObjectSetInteger(0, nm, OBJPROP_XSIZE, xsize);

  ObjectSetInteger(0, nm, OBJPROP_YSIZE, ysize);

  ObjectSetInteger(0, nm, OBJPROP_BGCOLOR, BackColor); // F25B D>=0

  ObjectSetInteger(0, nm, OBJPROP_BORDER_TYPE, BORDER_FLAT); // B8? 3@0=8FK

  ObjectSetInteger(0, nm, OBJPROP_CORNER, corner); // C3>; ?@82O7:8

  ObjectSetInteger(0, nm, OBJPROP_BORDER_COLOR, BorderColor); // F25B @0<:8

  ObjectSetInteger(0, nm, OBJPROP_BACK, false); // =0 704=5< ?;0=5 - true

  ObjectSetInteger(0, nm, OBJPROP_SELECTABLE, false); // ?5@5<5I5=85 <5B:8 <KILN, true - <>6=>

  ObjectSetInteger(0, nm, OBJPROP_SELECTED, false); // 2K45;5=85 <5B:8 <KHLN, true - <>6=>

  ObjectSetInteger(0, nm, OBJPROP_HIDDEN, true); // A:@KBL 2 A?8A:5 >1J5:B>2 - true

}  

  

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

   

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+





//+------------------------------------------------------------------+

//| Indicator deinitialization function                              |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {



//--- delete the labels

   ObjectsDeleteAll(0, "yy_ss_");

//--- destroy the timer after completing the work

   EventKillTimer();

   

  }

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---