Zero Lines v12

Author: Pete V.
Price Data Components
Orders Execution
Checks for the total of open orders
0 Views
0 Downloads
0 Favorites
Zero Lines v12
ÿþ//+------------------------------------------------------------------+

//|                                                   Zero Lines.mq4 |

//|                                                          Pete V. |

//|                      https://www.mql5.com/ru/users/m0rg4n/seller |

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

#property copyright "Pete V."

#property link      "https://www.mql5.com/ru/users/m0rg4n/seller"

#property version   "12.00"

#property strict

#property indicator_chart_window

//--- input parameters

input bool     B=true; // B

input bool     S=true; // S

input bool     BS=true; // B+S

extern color   BColor=MediumSeaGreen; // B color

extern color   SColor=IndianRed; // S color

extern color   BSColor=CornflowerBlue; // B+S color



bool b;

double tbBS=0,tbB=0,tbS=0;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   ObjectCreate("ZL B",1,0,0,0);   ObjectSet("ZL B", 6,BColor);

   ObjectCreate("ZL S",1,0,0,0);   ObjectSet("ZL S", 6,SColor);

   ObjectCreate("ZL BS",1,0,0,0);   ObjectSet("ZL BS", 6,BSColor); 

   

   if (BS==true){tbBS=tbBS();   ObjectMove("ZL BS", 0, 1, tbBS);}

   if (B==true){tbB=tbB();      ObjectMove("ZL B", 0, 1, tbB);}

   if (S==true){tbS=tbS();      ObjectMove("ZL S", 0, 1, tbS);}

   

   

   Print("B=",tbB,"   S=",tbS,"   BS=",tbBS);

   

   

//---

   return(INIT_SUCCEEDED);

  }

void OnDeinit(const int reason)

  {

//---

   ObjectDelete("ZL B");

   ObjectDelete("ZL S");

   ObjectDelete("ZL BS");

   Comment("");



  }

  

  

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

//| 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[])

  {

//---

   if (BS==true){tbBS=tbBS();   ObjectMove("ZL BS", 0, 1, tbBS);}

   if (B==true){tbB=tbB();      ObjectMove("ZL B", 0, 1, tbB);}

   if (S==true){tbS=tbS();      ObjectMove("ZL S", 0, 1, tbS);}

   

   Print("B=",tbB,"   S=",tbS,"   BS=",tbBS);

   

   

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

   return(rates_total);

  }

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

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



double tbBS()

{

int i=0,            

    k=1;            

double P=0,         

       L=0,         

       sumL=0,      

       sumLP=0,     

       tbr=0,       

       sumSW=0;     



i=OrdersTotal();

if (i==0){return(0);}

while (i!=0)

   {

   b=OrderSelect(i-1,SELECT_BY_POS);

   if (OrderSymbol()==Symbol()&& (OrderType()==OP_BUY ||OrderType()==OP_SELL ) )

   {

    if (OrderType()==OP_BUY ){k=1; }

    if (OrderType()==OP_SELL){k=-1;}

    P=OrderOpenPrice();

    L=OrderLots();

    sumLP=sumLP+k*L*P;

    sumL=sumL+k*L;

    

    sumSW=sumSW+OrderCommission()+OrderSwap();



    

   }

   i=i-1;

   }

if (sumL==0){return(0);}  

tbr=MathAbs(sumLP/sumL);



if (sumL>0){tbr=tbr-(sumSW/MathAbs(sumL)*Point());}

if (sumL<0){tbr=tbr+(sumSW/MathAbs(sumL)*Point());}



return(NormalizeDouble(tbr,Digits));

}



//*******************************************************************

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



double tbB()

{

int i=0,            

    k=1;            

double P=0,         

       L=0,         

       sumL=0,      

       sumLP=0,     

       tbr=0,       

       sumSW=0;     

        

  

i=OrdersTotal();

if (i==0){return(0);}

while (i!=0)

   {

   b=OrderSelect(i-1,SELECT_BY_POS);

   if (OrderSymbol()==Symbol()&& (OrderType()==OP_BUY ) )

   {

    

    k=1; 

    P=OrderOpenPrice();

    L=OrderLots();

    sumLP=sumLP+k*L*P;

    sumL=sumL+k*L;

    

    sumSW=sumSW+OrderCommission()+OrderSwap();



    

    

   }

   i=i-1;

   }

if (sumL==0){return(0);}  

tbr=MathAbs(sumLP/sumL);





tbr=tbr-(sumSW/MathAbs(sumL)*Point());





return(NormalizeDouble(tbr,Digits));

}



//*******************************************************************

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



double tbS()

{

int i=0,            

    k=1;            

double P=0,         

       L=0,         

       sumL=0,      

       sumLP=0,     

       tbr=0,       

       sumSW=0;    





i=OrdersTotal();

if (i==0){return(0);}

while (i!=0)

   {

   b=OrderSelect(i-1,SELECT_BY_POS);

   if (OrderSymbol()==Symbol()&& (OrderType()==OP_SELL ) )

   {

    k=-1;

    //BorS=BorS-1;}

    P=OrderOpenPrice();

    L=OrderLots();

    sumLP=sumLP+k*L*P;

    sumL=sumL+k*L;

    

    sumSW=sumSW+OrderCommission()+OrderSwap();

    

   }

   i=i-1;

   }

if (sumL==0){return(0);}  

tbr=MathAbs(sumLP/sumL);



tbr=tbr+(sumSW/MathAbs(sumL)*Point());



return(NormalizeDouble(tbr,Digits));

}



//*******************************************************************

Comments