ButtonTradingV2 08
ButtonTradingV2 08
CreateButton("button7","Close",x,y,ButtonWidth,ButtonHeight,ButtonFontColor,CloseBu
ttonColor,ButtonOutlineColor,ButtonFontSize);//Buy
CreateButton("button8",
"HedgeNet",x2,y2,ButtonWidth,ButtonHeight,ButtonFontColor,HedgeButtonColor,ButtonOu
tlineColor,ButtonFontSize);//hedge
CreateButton("button9", "Net %
TP",x2,y2,ButtonWidth,ButtonHeight,ButtonFontColor,HedgeNetTPButtonColor,ButtonOutl
ineColor,ButtonFontSize);//hedge
CreateButton("button10", "Net %
SL",x2,y2,ButtonWidth,ButtonHeight,ButtonFontColor,HedgeNetTPButtonColor,ButtonOutl
ineColor,ButtonFontSize);//hedge
CreateButton("button11","Net %
BE",x2,y2,ButtonWidth,ButtonHeight,ButtonFontColor,HedgeNetTPButtonColor,ButtonOutl
ineColor,ButtonFontSize);//hedge
CreateButton("button12","Delete
TP",x2,y2,ButtonWidth,ButtonHeight,ButtonFontColor,HedgeNetTPButtonColor,ButtonOutl
ineColor,ButtonFontSize);//hedge
CreateButton("button13","Delete
SL",x2,y2,ButtonWidth,ButtonHeight,ButtonFontColor,HedgeNetTPButtonColor,ButtonOutl
ineColor,ButtonFontSize);//hedge
CreateButton("button14","Close",x2,y2,ButtonWidth,ButtonHeight,ButtonFontColor,Clos
eButtonColor,ButtonOutlineColor,ButtonFontSize);//hedge
CreateButton("button15","Sell
Net",x3,y3,ButtonWidth,ButtonHeight,ButtonFontColor,SellButtonColor,ButtonOutlineCo
lor,ButtonFontSize);
CreateButton("button16","Net %
TP",x3,y3,ButtonWidth,ButtonHeight,ButtonFontColor,SellNetTPButtonColor,ButtonOutli
neColor,ButtonFontSize);
CreateButton("button17","Net %
SL",x3,y3,ButtonWidth,ButtonHeight,ButtonFontColor,SellNetTPButtonColor,ButtonOutli
neColor,ButtonFontSize);
CreateButton("button18","Net %
BE",x3,y3,ButtonWidth,ButtonHeight,ButtonFontColor,SellNetTPButtonColor,ButtonOutli
neColor,ButtonFontSize);
CreateButton("button19","Delete
TP",x3,y3,ButtonWidth,ButtonHeight,ButtonFontColor,SellNetTPButtonColor,ButtonOutli
neColor,ButtonFontSize);
CreateButton("button20","Delete
SL",x3,y3,ButtonWidth,ButtonHeight,ButtonFontColor,SellNetTPButtonColor,ButtonOutli
neColor,ButtonFontSize);
CreateButton("button21","Close",x3,y3,ButtonWidth,ButtonHeight,ButtonFontColor,Clos
eButtonColor,ButtonOutlineColor,ButtonFontSize);
CreateButton("button22",versionName,x4,y4,ButtonWidth*7+gap*12,ButtonHeight,ButtonF
ontColor,VersionButtonColor,ButtonOutlineColor,ButtonFontSize);//title box
}
else
{
CreateButton("button1","Buy
Net",x,y,ButtonWidth,ButtonHeight,ButtonFontColor,BuyButtonColor,ButtonOutlineColor
,ButtonFontSize);//Buy
CreateButton("button8","HedgeNet",x,y,ButtonWidth,ButtonHeight,ButtonFontColor,Hedg
eButtonColor,ButtonOutlineColor,ButtonFontSize);//hedge
CreateButton("button15","Sell
Net",x,y,ButtonWidth,ButtonHeight,ButtonFontColor,SellButtonColor,ButtonOutlineColo
r,ButtonFontSize);//sell
CreateButton("button2","Net %
TP",x2,y2,ButtonWidth,ButtonHeight,ButtonFontColor,BuyNetTPButtonColor,ButtonOutlin
eColor,ButtonFontSize);//Buy;
CreateButton("button9","Net %
TP",x2,y2,ButtonWidth,ButtonHeight,ButtonFontColor,HedgeNetTPButtonColor,ButtonOutl
ineColor,ButtonFontSize);//hedge
CreateButton("button16","Net %
TP",x2,y2,ButtonWidth,ButtonHeight,ButtonFontColor,SellNetTPButtonColor,ButtonOutli
neColor,ButtonFontSize);//sell
CreateButton("button3","Net %
SL",x3,y3,ButtonWidth,ButtonHeight,ButtonFontColor,BuyNetTPButtonColor,ButtonOutlin
eColor,ButtonFontSize);//Buy;
CreateButton("button10","Net %
SL",x3,y3,ButtonWidth,ButtonHeight,ButtonFontColor,HedgeNetTPButtonColor,ButtonOutl
ineColor,ButtonFontSize);//hedge
CreateButton("button17","Net %
SL",x3,y3,ButtonWidth,ButtonHeight,ButtonFontColor,SellNetTPButtonColor,ButtonOutli
neColor,ButtonFontSize);//sell
CreateButton("button4","Net %
BE",x4,y4,ButtonWidth,ButtonHeight,ButtonFontColor,BuyNetTPButtonColor,ButtonOutlin
eColor,ButtonFontSize);//Buy
CreateButton("button11","Net %
BE",x4,y4,ButtonWidth,ButtonHeight,ButtonFontColor,HedgeNetTPButtonColor,ButtonOutl
ineColor,ButtonFontSize);//hedge
CreateButton("button18","Net %
BE",x4,y4,ButtonWidth,ButtonHeight,ButtonFontColor,SellNetTPButtonColor,ButtonOutli
neColor,ButtonFontSize);//sell
CreateButton("button5","Delete
TP",x5,y5,ButtonWidth,ButtonHeight,ButtonFontColor,BuyNetTPButtonColor,ButtonOutlin
eColor,ButtonFontSize);//Buy
CreateButton("button12","Delete
TP",x5,y5,ButtonWidth,ButtonHeight,ButtonFontColor,HedgeNetTPButtonColor,ButtonOutl
ineColor,ButtonFontSize);//hedge
CreateButton("button19","Delete
TP",x5,y5,ButtonWidth,ButtonHeight,ButtonFontColor,SellNetTPButtonColor,ButtonOutli
neColor,ButtonFontSize);//sell
CreateButton("button6","Delete
SL",x6,y6,ButtonWidth,ButtonHeight,ButtonFontColor,BuyNetTPButtonColor,ButtonOutlin
eColor,ButtonFontSize);//Buy
CreateButton("button13","Delete
SL",x6,y6,ButtonWidth,ButtonHeight,ButtonFontColor,HedgeNetTPButtonColor,ButtonOutl
ineColor,ButtonFontSize);//hedge
CreateButton("button20","Delete
SL",x6,y6,ButtonWidth,ButtonHeight,ButtonFontColor,SellNetTPButtonColor,ButtonOutli
neColor,ButtonFontSize);//sell
CreateButton("button7","Close",x7,y7,ButtonWidth,ButtonHeight,ButtonFontColor,Close
ButtonColor,ButtonOutlineColor,ButtonFontSize);//Buy
CreateButton("button14","Close",x7,y7,ButtonWidth,ButtonHeight,ButtonFontColor,Clos
eButtonColor,ButtonOutlineColor,ButtonFontSize);//hedge
CreateButton("button21","Close",x7,y7,ButtonWidth,ButtonHeight,ButtonFontColor,Clos
eButtonColor,ButtonOutlineColor,ButtonFontSize);//sell
CreateButton("button22",versionName,x8,y8,ButtonWidth*3+gap*4,ButtonHeight,ButtonFo
ntColor,VersionButtonColor,ButtonOutlineColor,ButtonFontSize);//title box
}
//+------------------------------------------------------------------+
//| Indicators Initialize |
//+------------------------------------------------------------------+
if(Digits==3 || Digits==5)
pt=10*Point;
else
pt=Point;
//-------------water marks
switch(Period())
{
case PERIOD_D1:
tf="d1";
break;
case PERIOD_H1:
tf="h1";
break;
case PERIOD_H4:
tf="h4";
break;
case PERIOD_M1:
tf="m1";
break;
case PERIOD_M15:
tf="m15";
break;
case PERIOD_M30:
tf="m30";
break;
case PERIOD_M5:
tf="m5";
break;
case PERIOD_MN1:
tf="mn1";
break;
case PERIOD_W1:
tf="w1";
break;
default:
tf="Unknown";
break;
}
if(tagRed>255 || tagGreen>255 || tagBlue>255 || sidRed>255 || sidGreen>255 ||
sidBlue>255)
{
Alert("Watermark Red/Green/Blue components must each be in range 0..255");
}
tagRGB=(tagBlue<<16);
tagRGB |= (tagGreen << 8);
tagRGB |= tagRed;
sidRGB=(sidBlue<<16);
sidRGB |= (sidGreen << 8);
sidRGB |= sidRed;
//-------------water marks
if(ShowWatermark)
{
double chartHi,chartLo;
double range;
static double prevRange;
chartHi = WindowPriceMax(0);
chartLo = WindowPriceMin(0);
range=chartHi-chartLo;
// need only draw the watermark if the chart range has changed
if(prevRange!=range)
{
ObjectsDeleteAll(0,OBJ_LABEL);
ObjectDelete(SID);
ObjectDelete(TAG);
prevRange=range;
watermark(SID,tf+Symbol(),sidFontSize,sidFontName,sidRGB,sidXPos,sidYPos);
if(tagDisplayText && StringLen(tagText)>0)
{
watermark(TAG,tagText,tagFontSize,tagFontName,tagRGB,tagXPos,tagYPos);
}
}
}
//-------------water marks
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0,OBJ_LABEL);
ObjectDelete(SID);
ObjectDelete(TAG);
//---
DeleteButtons();
}
//+------------------------------------------------------------------+
//| Expert tick function (Indicator) |
//+------------------------------------------------------------------+
void OnTick()
{
DisplayINFO();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CreateButton(string btnName,string btnText,int &x,int y,int w,int h,color
clrText,color clrBg,color clrBorder,int fontSize)
{
ObjectCreate(0,btnName,OBJ_BUTTON,0,0,0);
ObjectSetInteger(0,btnName,OBJPROP_XDISTANCE,x);
ObjectSetInteger(0,btnName,OBJPROP_YDISTANCE,y);
ObjectSetInteger(0,btnName,OBJPROP_XSIZE,w);
ObjectSetInteger(0,btnName,OBJPROP_YSIZE,h);
ObjectSetString(0,btnName,OBJPROP_TEXT,btnText);
ObjectSetInteger(0,btnName,OBJPROP_COLOR,clrText);
ObjectSetInteger(0,btnName,OBJPROP_BGCOLOR,clrBg);
ObjectSetInteger(0,btnName,OBJPROP_BORDER_COLOR,clrBorder);
ObjectSetInteger(0,btnName,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,btnName,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,btnName,OBJPROP_STATE,false);
ObjectSetInteger(0,btnName,OBJPROP_FONTSIZE,fontSize);
ObjectSetInteger(0,btnName,OBJPROP_BACK,false);
ObjectSetInteger(0,btnName,OBJPROP_CORNER,Corner_RIGHT_TOP);
x=x+w+10;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DeleteButtons()
{
for(i=ObjectsTotal()-1; i>-1; i--)
{
if(StringFind(ObjectName(i),"button")>=0)
ObjectDelete(ObjectName(i));
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string
&sparam)
{
if(sparam=="button1") // Buy Net
{
Action_Button1();
ObjectSetInteger(0,"button1",OBJPROP_STATE,false);
}
else
if(sparam=="button2") // Net % TP (Buy)
{
Action_Button2();
ObjectSetInteger(0,"button2",OBJPROP_STATE,false);
}
else
if(sparam=="button3") //Net % Sl (Buy)
{
Action_Button3();
ObjectSetInteger(0,"button3",OBJPROP_STATE,false);
}
else
if(sparam=="button4") //BreakEven Net (Buy)
{
Action_Button4();
ObjectSetInteger(0,"button4",OBJPROP_STATE,false);
}
else
if(sparam=="button5") // Delete TP (Buy)
{
Action_Button5();
ObjectSetInteger(0,"button5",OBJPROP_STATE,false);
}
else
if(sparam=="button6") // Delete SL (Buy)
{
Action_Button6();
ObjectSetInteger(0,"button6",OBJPROP_STATE,false);
}
else
if(sparam=="button7") // Close All (Buy)
{
Action_Button7();
ObjectSetInteger(0,"button7",OBJPROP_STATE,false);
}
else
if(sparam=="button8") // Hedge Net
{
Action_Button8();
ObjectSetInteger(0,"button8",OBJPROP_STATE,false);
}
else
if(sparam=="button9") // Net % TP (Hedge)
{
Action_Button9();
ObjectSetInteger(0,"button9",OBJPROP_STATE,false);
}
else
if(sparam=="button10") //Net % Sl (Hedge)
{
Action_Button10();
ObjectSetInteger(0,"button10",OBJPROP_STATE,false);
}
else
if(sparam=="button111") //BreakEven Net TP/Sl
(Hedge)
{
Action_Button11();
ObjectSetInteger(0,"button11",OBJPROP_STATE,false);
}
else
if(sparam=="button12") // Delete TP (Hedge)
{
Action_Button12();
ObjectSetInteger(0,"button12",OBJPROP_STATE,false);
}
else
if(sparam=="button13") // Delete SL (Hedge)
{
Action_Button13();
ObjectSetInteger(0,"button13",OBJPROP_STATE,false);
}
else
if(sparam=="button14") // Close All
(Hedge)
{
Action_Button14();
ObjectSetInteger(0,"button14",OBJPROP_STATE,false);
}
else
if(sparam=="button15") // Sell Net
{
Action_Button15();
ObjectSetInteger(0,"button15",OBJPROP_STATE,false);
}
else
if(sparam=="button16") // Net % TP
(Sell)
{
Action_Button16();
ObjectSetInteger(0,"button16",OBJPROP_STATE,false);
}
else
if(sparam=="button17") //Net %
Sl (Sell)
{
Action_Button17();
ObjectSetInteger(0,"button17",OBJPROP_STATE,false);
}
else
if(sparam=="button18")
//BreakEven Net TP/Sl (Sell)
{
Action_Button18();
ObjectSetInteger(0,"button18",OBJPROP_STATE,false);
}
else
if(sparam=="button19") //
Delete TP (Sell)
{
Action_Button19();
ObjectSetInteger(0,"button19",OBJPROP_STATE,false);
}
else
ObjectSetInteger(0,"button20",OBJPROP_STATE,false);
}
else
Action_Button21();
ObjectSetInteger(0,"button21",OBJPROP_STATE,false);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button1()
{
OrderBuyNet();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button2()
{
BuyNetTP();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button3()
{
BuyNetSL();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button4()
{
BuyNetBE();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button5()
{
BuyDeleteTP();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button6()
{
BuyDeleteSL();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button7()
{
CloseBuy();
if(ProfitPercen)
{
BuyNetTP();
}
if(StopPercen)
{
BuyNetSL();
}
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button8()
{
OrderBuyNet();
OrderSellNet();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button9()
{
BuyNetTP();
SellNetTP();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button10()
{
BuyNetSL();
SellNetSL();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button11()
{
BuyNetBE();
SellNetBE();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button12()
{
BuyDeleteTP();
SellDeleteTP();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button13()
{
BuyDeleteSL();
SellDeleteSL();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button14()
{
CloseBuy();
CloseSell();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button15()
{
OrderSellNet();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button16()
{
SellNetTP();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button17()
{
SellNetSL();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button18()
{
SellNetBE();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button19()
{
SellDeleteTP();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button20()
{
SellDeleteSL();
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Action_Button21()
{
CloseSell();
if(ProfitPercen)
{
SellNetTP();
}
if(StopPercen)
{
SellNetSL();
}
PlaySound("ok.wav");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//double RangeLayer_Extract = StrToDouble(ObjectGetString(0, "RangeLayer_Edit",
OBJPROP_TEXT, 0));
//double MaxLayer_Extract = StrToDouble(ObjectGetString(0, "RangeLayer_Edit",
OBJPROP_TEXT, 0));
void OrderBuyNet()
{
Total=OrdersTotal();
//+------------------------------------------------------------------+
double Bprofit=0,BLotsSymbol=0,SLprice=0,TPprice=0;
int TBuy=0,b_cnt=0,bl_cnt=0,bs_cnt=0,bm_cnt=0;
for(int j=0; j<OrdersTotal(); j++)
{
int ticket2=OrderSelect(j,SELECT_BY_POS,MODE_TRADES);
if(ticket2<0)//----added by tradercapaym
{
// Print("CL-849 , OrderSelect Error: ", GetLastError());
}
else
{
// Print("CL-853 , Order Select Successfully, Ticket # is : " +
OrderTicket());
}
if(OrderType()==0 && OrderSymbol()==Symbol())
{
Bprofit+=OrderProfit();
BLotsSymbol+=OrderLots();
TBuy++;
}
}
//+------------------------------------------------------------------+
AE=AccountEquity();
Credit=AccountCredit();
Balance=AccountBalance();
GetoLots=GetLots();
getpip();
StopPercentage=(Balance+Credit) *(StopPercent/100);
StopPipsMath=NormalizeDouble((StopPercentage-(Bprofit))/((BLotsSymbol+GetoLots)/
account_type),0);
ProfitPercentage=(Balance+Credit) *(ProfitPercent/100);
ProfitPipsMath=NormalizeDouble((ProfitPercentage-(Bprofit))/((BLotsSymbol+GetoLots)
/account_type),0);
Price=Bid;
double PendingRange=(PendingMaxLayer+1)*PendingRangePips;
if(StopPercen && StopPercent >0 )
SLprice=Price-StopPipsMath*pip;
if(StopPercen && StopPercent >0 && PendingRange>StopPipsMath &&
(PendingLimitON || PendingStopON || ManyLayerON) )
SLprice=Price-PendingRange*pip;
if(ProfitPercen && ProfitPercent>0 )
TPprice=Price+ProfitPipsMath*pip;
if(ProfitPercen && ProfitPercent>0 && PendingRange>ProfitPipsMath &&
(PendingLimitON || PendingStopON || ManyLayerON) )
TPprice=Price+PendingRange*pip;
//---------------buy order-------------
ticket=OrderSend(Symbol(),OP_BUY,GetoLots,Price,30,SLprice,TPprice,"BuyOrder-
L"+IntegerToString(TBuy+1),0,0,Green);
if(ticket<0)
{
err=GetLastError();
Alert(Symbol()+":BUY FAILED : ErrorDescription("+IntegerToString(err)+")");
}
else
{
Alert(Symbol()+":BUY at "+DoubleToStr(Price,Digits)+"
TP="+DoubleToStr(TPprice,Digits)+",SL="+DoubleToStr(SLprice,Digits));
}
//---------------pending order-------------
if(PendingLimitON && TBuy==0 )
{
int TradeOperation = 2;//[2]BuyLimit
double PriceBPL=Price-PendingRangePips*pip;
for(i=0; i<PendingMaxLayer; i++)
{
ticket=OrderSend(Symbol(),TradeOperation,GetLots(),PriceBPL,30,SLprice,TPprice,"Buy
Limit-L"+IntegerToString(bl_cnt+1),0,0,Green);
if(ticket<0)
{
err=GetLastError();
Alert(Symbol()+":BUY FAILED ("+IntegerToString(err)+"): ");
}
else
{
Alert(Symbol()+":BUY at "+DoubleToStr(PriceBPL,Digits)+"
TP="+DoubleToStr(TPprice,Digits)+",SL="+DoubleToStr(SLprice,Digits));
bl_cnt++;
getpip();
PriceBPL-=PendingRangePips*pip;
}
}
}
if(PendingStopON && TBuy==0 )
{
int TradeOperation = 4;//[4] BuyStop
double PriceBPS=Price+PendingRangePips*pip;
for(i=0; i<PendingMaxLayer; i++)
{
ticket=OrderSend(Symbol(),TradeOperation,GetLots(),PriceBPS,30,SLprice,TPprice,"Buy
Stop-L"+IntegerToString(bs_cnt+1),0,0,Green);
if(ticket<0)
{
err=GetLastError();
Alert(Symbol()+":BUY FAILED ("+IntegerToString(err)+"): ");
}
else
{
Alert(Symbol()+":BUY at "+DoubleToStr(Price,Digits)+"
TP="+DoubleToStr(TPprice,Digits)+",SL="+DoubleToStr(SLprice,Digits));
bs_cnt++;
getpip();
PriceBPS+=PendingRangePips*pip;
}
}
}
if(ManyLayerON && TBuy==0 )//open order at same price but different TP
{
int TradeOperation = 0;//[0]BuyOrder
double TPpriceBBO=TPprice+PendingRangePips*pip;;
double SLpriceBBO=SLprice;
bm_cnt=1;
for(i=1; i<PendingMaxLayer; i++)
{
ticket=OrderSend(Symbol(),TradeOperation,GetLots(),Price,30,SLpriceBBO,TPpriceBBO,"
BuyOrder-L"+IntegerToString(bm_cnt+1),0,0,Green);
if(ticket<0)
{
err=GetLastError();
Alert(Symbol()+":BUY FAILED ("+IntegerToString(err)+"): ");
}
else
{
Alert(Symbol()+":BUY at "+DoubleToStr(Price,Digits)+"
TP="+DoubleToStr(TPprice,Digits)+",SL="+DoubleToStr(SLprice,Digits));
bm_cnt++;
getpip();
TPpriceBBO=TPpriceBBO+PendingRangePips*pip;
}
}
}
//+-------------modified existing order----------------------------------+
if(Total>0)
{
for(i=Total-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && BLotsSymbol!=0)
{
int
ticket4=OrderModify(OrderTicket(),OrderOpenPrice(),SLprice,TPprice,OrderExpiration(
),CLR_NONE);
}
}
}
}
//+------------------------------------------------------------------+
Alert("--- END "+WindowExpertName()+" "+Symbol());
RefreshRates();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OrderSellNet()
{
Total=OrdersTotal();
//+------------------------------------------------------------------+
double Sprofit=0,SLotsSymbol=0,SLprice=0,TPprice=0;
int TSell=0, sl_cnt=0,ss_cnt=0,sm_cnt=0;
for(int j=0; j<OrdersTotal(); j++)
{
int ticket2=OrderSelect(j,SELECT_BY_POS,MODE_TRADES);
if(ticket2<0)//----added by tradercapaym
{
// Print("CL-849 , OrderSelect Error: ", GetLastError());
}
else
{
// Print("CL-853 , Order Select Successfully, Ticket # is : " +
OrderTicket());
}
if(OrderType()==1 && OrderSymbol()==Symbol())
{
Sprofit+=OrderProfit();
SLotsSymbol+=OrderLots();
TSell++;
}
}
//+------------------------------------------------------------------+
Credit=AccountCredit();
AE=AccountEquity();
Balance=AccountBalance();
GetoLots=GetLots();
getpip();
StopPercentage=(Balance+Credit) *(StopPercent/100);
StopPipsMath=NormalizeDouble((StopPercentage-(Sprofit))/((SLotsSymbol+GetoLots)/
account_type),0);
ProfitPercentage=(Balance+Credit) *(ProfitPercent/100);
ProfitPipsMath=NormalizeDouble((ProfitPercentage-(Sprofit))/((SLotsSymbol+GetoLots)
/account_type),0);
Price=Ask;
double PendingRange=(PendingMaxLayer+1)*PendingRangePips;
if(StopPercen && StopPercent >0 )
SLprice = Price+StopPipsMath*pip;
if(StopPercen && StopPercent >0 && PendingRange>StopPipsMath &&
(PendingLimitON || PendingStopON || ManyLayerON))
SLprice=Price+PendingRange*pip;
if(ProfitPercen && ProfitPercent>0 )
TPprice = Price-ProfitPipsMath*pip;
if(ProfitPercen && ProfitPercent>0 && PendingRange>ProfitPipsMath &&
(PendingLimitON || PendingStopON || ManyLayerON))
TPprice=Price-PendingRange*pip;
//------------sell order----------
ticket=OrderSend(Symbol(),OP_SELL,GetoLots,Price,30,SLprice,TPprice,"SellOrder-
L"+IntegerToString(TSell+1),0,0,Green);
if(ticket<0)
{
err=GetLastError();
Alert(Symbol()+":SELL FAILED : ErrorDescription("+IntegerToString(err)+"");
}
else
{
Alert(Symbol()+":SELL at "+DoubleToStr(Price,Digits)+"
TP="+DoubleToStr(TPprice,Digits)+",SL="+DoubleToStr(SLprice,Digits));
}
//------------pending order----------
if(PendingLimitON && TSell ==0 )
{
int TradeOperation = 3;//[3]SellLimit
double PriceSPL=Price+PendingRangePips*pip;
for(i=0; i<PendingMaxLayer; i++)
{
ticket=OrderSend(Symbol(),TradeOperation,GetLots(),PriceSPL,30,SLprice,TPprice,"Sel
lLimit-L"+IntegerToString(sl_cnt+1),0,0,Green);
if(ticket<0)
{
err=GetLastError();
Alert(Symbol()+":SELL FAILED ("+IntegerToString(err)+"): ");
}
else
{
Alert(Symbol()+":SELL at "+DoubleToStr(PriceSPL,Digits)+"
TP="+DoubleToStr(TPprice,Digits)+",SL="+DoubleToStr(SLprice,Digits));
sl_cnt++;
getpip();
PriceSPL+=PendingRangePips*pip;
}
}
}
if(PendingStopON && TSell==0 )
{
int TradeOperation = 5;//[5] SellStop
double priceSPS=Price-PendingRangePips*pip;
for(i=0; i<PendingMaxLayer; i++)
{
ticket=OrderSend(Symbol(),TradeOperation,GetLots(),priceSPS,30,SLprice,TPprice,"Sel
lStop-L"+IntegerToString(ss_cnt+1),0,0,Green);
if(ticket<0)
{
err=GetLastError();
Alert(Symbol()+":SELL FAILED ("+IntegerToString(err)+"): ");
}
else
{
Alert(Symbol()+":SELL at "+DoubleToStr(priceSPS,Digits)+"
TP="+DoubleToStr(TPprice,Digits)+",SL="+DoubleToStr(SLprice,Digits));
ss_cnt++;
getpip();
priceSPS-=PendingRangePips*pip;
}
}
}
if(ManyLayerON && TSell==0)//open order at same price but different TP
{
int TradeOperation = 1;//[1]SellOrder
double TPpriceSBO=TPprice-PendingRangePips*pip;
double SLpriceSBO=SLprice;
sm_cnt=1;
for(i=1; i<PendingMaxLayer; i++)
{
ticket=OrderSend(Symbol(),TradeOperation,GetLots(),Price,30,SLpriceSBO,TPpriceSBO,"
Sellmany-L"+IntegerToString(sm_cnt+1),0,0,Green);
if(ticket<0)
{
err=GetLastError();
Alert(Symbol()+":SELL FAILED ("+IntegerToString(err)+"): ");
}
else
{
Alert(Symbol()+":SELL at "+DoubleToStr(Price,Digits)+"
TP="+DoubleToStr(TPprice,Digits)+",SL="+DoubleToStr(SLprice,Digits));
sm_cnt++;
getpip();
TPpriceSBO=TPpriceSBO-PendingRangePips*pip;
}
}
}
//+-------------modified existing order----------------------------------+
if(Total>0)
{
for(i=Total-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
//+------------------------------------------------------------------+
double Sprofit=0,SLotsSymbol=0,SL2=0,TP2=0;
for(int j=0; j<OrdersTotal(); j++)
{
int ticket2=OrderSelect(j,SELECT_BY_POS,MODE_TRADES);
if(ticket2<0)//----added by tradercapaym
{
// Print("CL-849 , OrderSelect Error: ", GetLastError());
}
else
{
// Print("CL-853 , Order Select Successfully, Ticket # is : " +
OrderTicket());
}
if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
{
Sprofit+=OrderProfit();
SLotsSymbol+=OrderLots();
}
}
//+------------------------------------------------------------------+
getpip();
AE=AccountEquity();
Credit=AccountCredit();
Balance=AccountBalance();
double StopPercentage2=(Balance+Credit) *(StopPercent/100);
double
StopPipsMath2=NormalizeDouble((StopPercentage2-(Sprofit))/((SLotsSymbol)/
account_type),0);
double Price2=Ask;
if(StopPercent >0)
SL2 = Price2+StopPipsMath2*pip;
//+------------------------------------------------------------------+
if(Total>0)
{
for(i=Total-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
ObjectSetText("PipsB4MCvalue",""+DoubleToStr(PipsB4MCvalue,0)+"",FontSize,FontType,
Red);
ObjectSet("PipsB4MCvalue",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("PipsB4MCvalue",OBJPROP_XDISTANCE,-60+Adjust_Side_to_side);
ObjectSet("PipsB4MCvalue",OBJPROP_YDISTANCE,45+Shift_UP_DN);
//Total Hedge lot = Buy Lot - Sell Lot
double TPLots=BLotsSymbol-SLotsSymbol;
if(TLots>0)
{
color_HedgLOT=clrLime;
}
if(TLots<0)
{
color_HedgLOT=clrRed;
}
if(TLots==0)
{
color_HedgLOT=clrDimGray;
}
ObjectCreate("HedgLOT",OBJ_LABEL,0,0,0);
ObjectSetText("HedgLOT","HedgeLOT",FontSize,FontType,CommentLabel_color);
ObjectSet("HedgLOT",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("HedgLOT",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("HedgLOT",OBJPROP_YDISTANCE,55+Shift_UP_DN);
ObjectCreate("TLotsV",OBJ_LABEL,0,0,0);
ObjectSetText("TLotsV",""+DoubleToStr(TLots,2)+"",FontSize,FontType,color_HedgLOT);
ObjectSet("TLotsV",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("TLotsV",OBJPROP_XDISTANCE,-60+Adjust_Side_to_side);
ObjectSet("TLotsV",OBJPROP_YDISTANCE,55+Shift_UP_DN);
//Total Pair LOT
if(TPLots>0)
{
color_TPLOT=clrLime;
}
if(TPLots<0)
{
color_TPLOT=clrRed;
}
if(TPLots==0)
{
color_TPLOT=clrDimGray;
}
ObjectCreate("PairLOT",OBJ_LABEL,0,0,0);
ObjectSetText("PairLOT","Pair_ _LOT",FontSize,FontType,CommentLabel_color);
ObjectSet("PairLOT",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("PairLOT",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("PairLOT",OBJPROP_YDISTANCE,65+Shift_UP_DN);
ObjectCreate("PairPLOTs",OBJ_LABEL,0,0,0);
ObjectSetText("PairPLOTs",""+DoubleToStr(TPLots,2)+"",FontSize,FontType,color_TPLOT
);
ObjectSet("PairPLOTs",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("PairPLOTs",OBJPROP_XDISTANCE,-60+Adjust_Side_to_side);
ObjectSet("PairPLOTs",OBJPROP_YDISTANCE,65+Shift_UP_DN);
//Buy Net Profit
double BuyNet=NormalizeDouble(percentBProfit,2);
if(BuyNet>0)
{
color_Bnet=clrLime;
}
if(BuyNet<0)
{
color_Bnet=clrRed;
}
if(BuyNet==0)
{
color_Bnet=clrDimGray;
}
ObjectCreate("BuyNet%",OBJ_LABEL,0,0,0);
ObjectSetText("BuyNet%","Buy___Net",FontSize,FontType,CommentLabel_color);
ObjectSet("BuyNet%",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("BuyNet%",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("BuyNet%",OBJPROP_YDISTANCE,125+Shift_UP_DN);
ObjectCreate("BuyNet%v",OBJ_LABEL,0,0,0);
ObjectSetText("BuyNet%v",""+(DoubleToStr(percentBProfit,1))+"
%",FontSize,FontType,color_Bnet);
ObjectSet("BuyNet%v",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("BuyNet%v",OBJPROP_XDISTANCE,-136+Adjust_Side_to_side);
ObjectSet("BuyNet%v",OBJPROP_YDISTANCE,125+Shift_UP_DN);
ObjectCreate("BuyNet%v$",OBJ_LABEL,0,0,0);
ObjectSetText("BuyNet%v$",""+(DoubleToStr(BProfit,2))+"
$",FontSize,FontType,color_Bnet);
ObjectSet("BuyNet%v$",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("BuyNet%v$",OBJPROP_XDISTANCE,-70+Adjust_Side_to_side);
ObjectSet("BuyNet%v$",OBJPROP_YDISTANCE,125+Shift_UP_DN);
//Buy Profit
double BProfitNet=NormalizeDouble(BProfitOnly,2);
double BProfitperctTarget=BProfitNet /(SBalance+Credit)*100;
if(BProfitNet>0)
{
color_BProfitNet=clrLime;
}
if(BProfitNet<0)
{
color_BProfitNet=clrRed;
}
if(BProfitNet==0)
{
color_BProfitNet=clrDimGray;
}
ObjectCreate("BProfitNet%",OBJ_LABEL,0,0,0);
ObjectSetText("BProfitNet%","Buy_Profit",FontSize,FontType,CommentLabel_color);
ObjectSet("BProfitNet%",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("BProfitNet%",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("BProfitNet%",OBJPROP_YDISTANCE,135+Shift_UP_DN);
ObjectCreate("BProfitNet%v",OBJ_LABEL,0,0,0);
ObjectSetText("BProfitNet%v",""+(DoubleToStr(BProfitperctTarget,1))+"
%",FontSize,FontType,color_BProfitNet);
ObjectSet("BProfitNet%v",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("BProfitNet%v",OBJPROP_XDISTANCE,-136+Adjust_Side_to_side);
ObjectSet("BProfitNet%v",OBJPROP_YDISTANCE,135+Shift_UP_DN);
ObjectCreate("BProfitNet%v$",OBJ_LABEL,0,0,0);
ObjectSetText("BProfitNet%v$",""+(DoubleToStr(BProfitNet,2))+"
$",FontSize,FontType,color_BProfitNet);
ObjectSet("BProfitNet%v$",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("BProfitNet%v$",OBJPROP_XDISTANCE,-70+Adjust_Side_to_side);
ObjectSet("BProfitNet%v$",OBJPROP_YDISTANCE,135+Shift_UP_DN);
//Sell Net Profit
double SellNet=NormalizeDouble(percentSProfit,2);
if(SellNet>0)
{
color_Snet=clrLime;
}
if(SellNet<0)
{
color_Snet=clrRed;
}
if(SellNet==0)
{
color_Snet=clrDimGray;
}
ObjectCreate("SellNet%",OBJ_LABEL,0,0,0);
ObjectSetText("SellNet%","Sell___Net",FontSize,FontType,CommentLabel_color);
ObjectSet("SellNet%",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("SellNet%",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("SellNet%",OBJPROP_YDISTANCE,145+Shift_UP_DN);
ObjectCreate("SellNet%v",OBJ_LABEL,0,0,0);
ObjectSetText("SellNet%v",""+(DoubleToStr(percentSProfit,1))+"
%",FontSize,FontType,color_Snet);
ObjectSet("SellNet%v",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("SellNet%v",OBJPROP_XDISTANCE,-136+Adjust_Side_to_side);
ObjectSet("SellNet%v",OBJPROP_YDISTANCE,145+Shift_UP_DN);
ObjectCreate("SellNet%v$",OBJ_LABEL,0,0,0);
ObjectSetText("SellNet%v$",""+(DoubleToStr(SProfit,2))+"
$",FontSize,FontType,color_Snet);
ObjectSet("SellNet%v$",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("SellNet%v$",OBJPROP_XDISTANCE,-70+Adjust_Side_to_side);
ObjectSet("SellNet%v$",OBJPROP_YDISTANCE,145+Shift_UP_DN);
//Sell profit
double SProfitNet=NormalizeDouble(SProfitOnly,2);
double SProfitperctTarget=SProfitNet /(SBalance+Credit)*100;
if(SProfitNet>0)
{
color_SProfitNet=clrLime;
}
if(SProfitNet<0)
{
color_SProfitNet=clrRed;
}
if(SProfitNet==0)
{
color_SProfitNet=clrDimGray;
}
ObjectCreate("SProfitNet%",OBJ_LABEL,0,0,0);
ObjectSetText("SProfitNet%","Sell_Profit",FontSize,FontType,CommentLabel_color);
ObjectSet("SProfitNet%",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("SProfitNet%",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("SProfitNet%",OBJPROP_YDISTANCE,155+Shift_UP_DN);
ObjectCreate("SProfitNet%v",OBJ_LABEL,0,0,0);
ObjectSetText("SProfitNet%v",""+(DoubleToStr(SProfitperctTarget,1))+"
%",FontSize,FontType,color_SProfitNet);
ObjectSet("SProfitNet%v",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("SProfitNet%v",OBJPROP_XDISTANCE,-136+Adjust_Side_to_side);
ObjectSet("SProfitNet%v",OBJPROP_YDISTANCE,155+Shift_UP_DN);
ObjectCreate("SProfitNet%v$",OBJ_LABEL,0,0,0);
ObjectSetText("SProfitNet%v$",""+(DoubleToStr(SProfitNet,2))+"
$",FontSize,FontType,color_SProfitNet);
ObjectSet("SProfitNet%v$",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("SProfitNet%v$",OBJPROP_XDISTANCE,-70+Adjust_Side_to_side);
ObjectSet("SProfitNet%v$",OBJPROP_YDISTANCE,155+Shift_UP_DN);
//Total Net
double TotalNet=NormalizeDouble(SProfit+BProfit,2);
if(TotalNet>0)
{
color_Tnet=clrLime;
}
if(TotalNet<0)
{
color_Tnet=clrRed;
}
if(TotalNet==0)
{
color_Tnet=clrDimGray;
}
ObjectCreate("TotalNet%",OBJ_LABEL,0,0,0);
ObjectSetText("TotalNet%","Total__Net",FontSize,FontType,CommentLabel_color);
ObjectSet("TotalNet%",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("TotalNet%",OBJPROP_XDISTANCE,-15+Adjust_Side_to_side);
ObjectSet("TotalNet%",OBJPROP_YDISTANCE,165+Shift_UP_DN);
ObjectCreate("TotalNet%v",OBJ_LABEL,0,0,0);
ObjectSetText("TotalNet%v",""+DoubleToStr(perctTarget,1)+"
%",FontSize,FontType,color_Tnet);
ObjectSet("TotalNet%v",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("TotalNet%v",OBJPROP_XDISTANCE,-136+Adjust_Side_to_side);
ObjectSet("TotalNet%v",OBJPROP_YDISTANCE,165+Shift_UP_DN);
ObjectCreate("TotalNet%v$",OBJ_LABEL,0,0,0);
ObjectSetText("TotalNet%v$",""+(DoubleToStr(TotalNet,2))+"
$",FontSize,FontType,color_Tnet);
ObjectSet("TotalNet%v$",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("TotalNet%v$",OBJPROP_XDISTANCE,-70+Adjust_Side_to_side);
ObjectSet("TotalNet%v$",OBJPROP_YDISTANCE,165+Shift_UP_DN);
//Net Profit
double ProfitNet=NormalizeDouble(SProfitOnly+BProfitOnly,2);
double ProfitperctTarget=ProfitNet /(SBalance+Credit)*100;
if(ProfitNet>0)
{
color_ProfitNet=clrLime;
}
if(ProfitNet<0)
{
color_ProfitNet=clrRed;
}
if(ProfitNet==0)
{
color_ProfitNet=clrDimGray;
}
ObjectCreate("ProfitNet%",OBJ_LABEL,0,0,0);
ObjectSetText("ProfitNet%","Net_Profit",FontSize,FontType,CommentLabel_color);
ObjectSet("ProfitNet%",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("ProfitNet%",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("ProfitNet%",OBJPROP_YDISTANCE,175+Shift_UP_DN);
ObjectCreate("ProfitNet%v",OBJ_LABEL,0,0,0);
ObjectSetText("ProfitNet%v",""+(DoubleToStr(ProfitperctTarget,1))+"
%",FontSize,FontType,color_ProfitNet);
ObjectSet("ProfitNet%v",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("ProfitNet%v",OBJPROP_XDISTANCE,-136+Adjust_Side_to_side);
ObjectSet("ProfitNet%v",OBJPROP_YDISTANCE,175+Shift_UP_DN);
ObjectCreate("ProfitNet%v$",OBJ_LABEL,0,0,0);
ObjectSetText("ProfitNet%v$",""+(DoubleToStr(ProfitNet,2))+"
$",FontSize,FontType,color_ProfitNet);
ObjectSet("ProfitNet%v$",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("ProfitNet%v$",OBJPROP_XDISTANCE,-70+Adjust_Side_to_side);
ObjectSet("ProfitNet%v$",OBJPROP_YDISTANCE,175+Shift_UP_DN);
//Balance
double PerctBalvalue = NormalizeDouble(PerctBal*100/100,1);
double dollarBalvalue=NormalizeDouble(t_profit,2);
if(PerctBalvalue > 0)
{
color_ProfitBal = clrLime;
}
if(PerctBalvalue < 0)
{
color_ProfitBal = clrRed;
}
if(PerctBalvalue == 0)
{
color_ProfitBal = clrDimGray;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
ObjectCreate("AllTime%",OBJ_LABEL,0,0,0);
ObjectSetText("AllTime%","Balance",FontSize,FontType,CommentLabel_color);
ObjectSet("AllTime%",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("AllTime%",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("AllTime%",OBJPROP_YDISTANCE,185+Shift_UP_DN);
ObjectCreate("DollarTotalBAL$",OBJ_LABEL,0,0,0);
ObjectSetText("DollarTotalBAL$",""+DoubleToStr(dollarBalvalue,2)+"
$",FontSize,FontType,color_ProfitBal);
ObjectSet("DollarTotalBAL$",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("DollarTotalBAL$",OBJPROP_XDISTANCE,-70+Adjust_Side_to_side);
ObjectSet("DollarTotalBAL$",OBJPROP_YDISTANCE,185+Shift_UP_DN);
ObjectCreate("ProfitTotalBAL%",OBJ_LABEL,0,0,0);
ObjectSetText("ProfitTotalBAL%",""+DoubleToStr(PerctBalvalue,1)+"
%",FontSize,FontType,color_ProfitBal);
ObjectSet("ProfitTotalBAL%",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("ProfitTotalBAL%",OBJPROP_XDISTANCE,-136+Adjust_Side_to_side);
ObjectSet("ProfitTotalBAL%",OBJPROP_YDISTANCE,185+Shift_UP_DN);
//Equity
double PerctEQvalue =NormalizeDouble(PerctBalEA*100/100,1);
double dollarEQvalue=NormalizeDouble(balance+profit,2);
if(PerctEQvalue > 0)
{
color_ProfitEq = clrLime;
}
if(PerctEQvalue < 0)
{
color_ProfitEq = clrRed;
}
if(PerctEQvalue == 0)
{
color_ProfitEq = clrDimGray;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
ObjectCreate("ReturnProfit",OBJ_LABEL,0,0,0);
ObjectSetText("ReturnProfit","Equity",FontSize,FontType,CommentLabel_color);
ObjectSet("ReturnProfit",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("ReturnProfit",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("ReturnProfit",OBJPROP_YDISTANCE,195+Shift_UP_DN);
ObjectCreate("DollarTotalEQ$",OBJ_LABEL,0,0,0);
ObjectSetText("DollarTotalEQ$",""+DoubleToStr(dollarEQvalue,2)+"
$",FontSize,FontType,color_ProfitEq);
ObjectSet("DollarTotalEQ$",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("DollarTotalEQ$",OBJPROP_XDISTANCE,-70+Adjust_Side_to_side);
ObjectSet("DollarTotalEQ$",OBJPROP_YDISTANCE,195+Shift_UP_DN);
ObjectCreate("ProfitTotalEQ%",OBJ_LABEL,0,0,0);
ObjectSetText("ProfitTotalEQ%",""+DoubleToStr(PerctEQvalue,1)+"
%",FontSize,FontType,color_ProfitEq);
ObjectSet("ProfitTotalEQ%",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("ProfitTotalEQ%",OBJPROP_XDISTANCE,-136+Adjust_Side_to_side);
ObjectSet("ProfitTotalEQ%",OBJPROP_YDISTANCE,195+Shift_UP_DN);
//Profit %
ObjectCreate("Profit%",OBJ_LABEL,0,0,0);
ObjectSetText("Profit%","Profit___%",FontSize,FontType,CommentLabel_color);
ObjectSet("Profit%",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("Profit%",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("Profit%",OBJPROP_YDISTANCE,95+Shift_UP_DN);
ObjectCreate("Profit%v",OBJ_LABEL,0,0,0);
ObjectSetText("Profit%v",""+(DoubleToStr((ProfitPercent),2))+"
%",FontSize,FontType,clrWhite);
ObjectSet("Profit%v",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("Profit%v",OBJPROP_XDISTANCE,-73+Adjust_Side_to_side);
ObjectSet("Profit%v",OBJPROP_YDISTANCE,95+Shift_UP_DN);
//Target $/%
ObjectCreate("Target $",OBJ_LABEL,0,0,0);
ObjectSetText("Target $","Target_-_$",FontSize,FontType,CommentLabel_color);
ObjectSet("Target $",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("Target $",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("Target $",OBJPROP_YDISTANCE,105+Shift_UP_DN);
ObjectCreate("TargetLots2",OBJ_LABEL,0,0,0);
ObjectSetText("TargetLots2",""+DoubleToStr(tp_m,2)+"
$",FontSize,FontType,clrYellow);
ObjectSet("TargetLots2",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("TargetLots2",OBJPROP_XDISTANCE,-70+Adjust_Side_to_side);
ObjectSet("TargetLots2",OBJPROP_YDISTANCE,105+Shift_UP_DN);
//TP pips
double pipsMath=NormalizeDouble((tp_m)/(GetiLots/account_type),0);
ObjectCreate("TP=Pips",OBJ_LABEL,0,0,0);
ObjectSetText("TP=Pips","TP == Pips",FontSize,FontType,CommentLabel_color);
ObjectSet("TP=Pips",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("TP=Pips",OBJPROP_XDISTANCE,-13+Adjust_Side_to_side);
ObjectSet("TP=Pips",OBJPROP_YDISTANCE,115+Shift_UP_DN);
ObjectCreate("pipsMathv",OBJ_LABEL,0,0,0);
ObjectSetText("pipsMathv",""+DoubleToStr(pipsMath,0)+"",FontSize,FontType,clrYellow
);
ObjectSet("pipsMathv",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("pipsMathv",OBJPROP_XDISTANCE,-60+Adjust_Side_to_side);
ObjectSet("pipsMathv",OBJPROP_YDISTANCE,115+Shift_UP_DN);
if(BTP_points != 0)
BTP= BTP_points-Bid;
else
BTP = 0;
BTPipsValue = NormalizeDouble(BTP*10000,0);
if(TB!=0)
BTP_color = clrLime;
else
BTP_color = clrGray;
ObjectCreate("BTPointsV",OBJ_LABEL,0,0,0);
ObjectSetText("BTPointsV",""+DoubleToStr(BTPipsValue,0)+"
Gap",FontSize,FontType,BTP_color);
ObjectSet("BTPointsV",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("BTPointsV",OBJPROP_XDISTANCE,-148+Adjust_Side_to_side);
ObjectSet("BTPointsV",OBJPROP_YDISTANCE,75+Shift_UP_DN);
//Gap Sell TP
if(STP_points != 0)
{
STP= STP_points-Ask;
}
else
{
STP = 0;
}
STPipsValue = NormalizeDouble(STP*10000,0);
if(TS!=0)
{
STP_color = clrRed;
}
else
{
STP_color = clrGray;
}
ObjectCreate("STPointsV",OBJ_LABEL,0,0,0);
ObjectSetText("STPointsV",""+DoubleToStr(STPipsValue,0)+"
Gap",FontSize,FontType,STP_color);
ObjectSet("STPointsV",OBJPROP_CORNER,Corner_of_Chart_RIGHT_TOP);
ObjectSet("STPointsV",OBJPROP_XDISTANCE,-148+Adjust_Side_to_side);
ObjectSet("STPointsV",OBJPROP_YDISTANCE,115+Shift_UP_DN);
//----
if(ShowComment)
{
line_1 =" Total Layer =
"+IntegerToString(T)
+" | Total Lot = "+DoubleToStr(TLots,2)+" | Total BLot =
"+DoubleToStr(BLots,2)+" | Total SLot = "+DoubleToStr(SLots,2)+"\n";
line_2 =" Equity = $
"+DoubleToStr(AE,2)+" | Spread = "+DoubleToStr((Ask-Bid)/pt,2)+" | Total Buy =
"+IntegerToString(TB)+" | Total Sell = "+IntegerToString(TS)+"\n";
line_3 =" Balance = $
"+DoubleToStr(SBalance,2)+" | Credit = $ "+DoubleToStr(Credit,2)+" | Deposit =
$ "+DoubleToStr(getDepo,2)+"\n";
line_4 =" Profit $ =
"+DoubleToStr(balance+profit,2)+" / "+DoubleToStr(t_profit,2)+" | Withdrawal =
$ "+DoubleToStr(getDWD,2)+" \n";
line_5 =" Profit % =
"+DoubleToStr(MathRound(PerctBalEA*100)/100,1)+" /
"+DoubleToStr(MathRound(PerctBal*100)/100,1)+" \n";
line_6 =" Target $ =
"+DoubleToStr(tp_m2,2)+" / "+DoubleToStr(tp_m,2)+"\n";
line_7 =" Target % =
"+DoubleToStr(perctTarget,2)+" / "+DoubleToStr(ProfitPercent,2)+"\n";
line_8 =" Profit Buy = $
"+DoubleToStr(BProfit,2)+" | "+DoubleToStr(percentBProfit,2)+" %\n";
line_9 =" Profit Sell = $
"+DoubleToStr(SProfit,2)+" | "+DoubleToStr(percentSProfit,2)+" %\n";
line_10=" #Buy =
"+IntegerToString(TBsymbol)+" LotBuy = "+DoubleToStr(BLotsSymbol,2)+" | #Sell =
"+IntegerToString(TSsymbol)+" LotSell = "+DoubleToStr(SLotsSymbol,2)+" |
TPairLot = "+DoubleToStr(TPLots,2)+"\n";
Comment(line_1,line_2,line_3,line_4,line_5,line_6,line_7,line_8,line_9,line_10);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double getDeposit()
{
int total,cnt;
double deposits=0;
total=OrdersHistoryTotal();
for(cnt=0; cnt<total; cnt++)
{
ticket=OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY);
if(ticket<0)//----added by tradercapaym
{
// Print("CL-493 , OrderSelect Error: ", GetLastError());
}
else
{
// Print("CL-497 , Order Select Successfully, Ticket # is : " +
OrderTicket());
}
if(OrderType()==6 && OrderProfit()>0)
{
deposits+=OrderProfit();
}
}
return(deposits);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double getWithdrawal()
{
int total,cnt;
double withdrawal=0;
total=OrdersHistoryTotal();
for(cnt=0; cnt<total; cnt++)
{
ticket=OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY);
if(ticket<0)//----added by tradercapaym
{
// Print("CL-493 , OrderSelect Error: ", GetLastError());
}
else
{
// Print("CL-497 , Order Select Successfully, Ticket # is : " +
OrderTicket());
}
if(OrderType()==6 && OrderProfit()<0)
{
withdrawal+=OrderProfit();
}
}
return(withdrawal);
}
//+------------------------------------------------------------------+
//| Alert Notifications |
//+------------------------------------------------------------------+
bool AlertDelay()
{
static datetime last_time;
if(TimeCurrent()-last_time<TimeDelayAlertinSec)
{
// delay for 60 seconds
return(false);
}
else
{
last_time=TimeCurrent();
return(true);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void getpip()
{
if(Digits==2 || Digits==4)
{
pip=Point;
}
if(Digits==3 || Digits==5)
{
pip = 10*Point;
}
if(Digits==6)
{
pip = 100*Point;
}
}
//+------------------------------------------------------------------+
//| Money Management |
//+------------------------------------------------------------------+
//Only suitable for Forex (major, minor and exortic pair)...
//GetLots() calculation not not supported for metals and CFD/USDX/Oil
double GetLots()
{
double MM_lots=0;
Credit=AccountCredit();
Balance=AccountBalance();
double MM_minlot = MarketInfo(Symbol(), MODE_MINLOT);
double MM_maxlot = MarketInfo(Symbol(), MODE_MAXLOT);
double MM_leverage= AccountLeverage();
double MM_lotsize = MarketInfo(Symbol(),MODE_LOTSIZE);
double MM_stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
double xecn=1;
if(Digits==5 || Digits==3)
{
xecn=10;
}
//+------------------------------------------------------------------+
//Percentage Lots but Lot fixed with balance and only decrease/increase if balance
changed
MM_lots=NormalizeDouble(((Balance+Credit)*MM_leverage*MM_Risk_Percent_Lots*Point*xe
cn*100/(Ask*MM_lotsize*MM_minlot)*MM_minlot),2);
if(MM_lots < MM_minlot)
MM_lots = MM_minlot;
if(MM_lots > MM_maxlot)
MM_lots = MM_maxlot;
if(AccountFreeMargin()<Ask*MM_lots*MM_lotsize/MM_leverage)
{
Print("We have no money. Lots = ",MM_lots," , Free Margin =
",AccountFreeMargin());
Comment("We have no money. Lots = ",MM_lots," , Free Margin =
",AccountFreeMargin());
}
return(MM_lots);
}
//+------------------------------------------------------------------+