Hi Guys,
To start,I am not at all a coder but slowly learning to do what I need to be able to do for myself what I need.
I put together a trading panel for myself for scalping from a bunch of different code snippets found everywhere.
It looks like this :
Trade Panel.png
I already use it but want to improve the code so I can change the lots sizes more easily but ran into a problem with displaying an input from the setting windows on the actual button.
I have the same problem in many different places where I don't understand what is the correct way for me to get the correct info displayed.I am sure the answer is very simple I am just to "dumb" to see it and I don't want to pay a freelancer as I would rather like to understand it better if possible before I go that route.
The problem I have is in line 122 although it repeats for most of the buttons.
Code: Select all ObjectSetInteger(0,"PartialClose_EA",OBJPROP_STATE,false);
ObjectSetString(0,"PartialClose_EA",OBJPROP_TEXT,"Close0.02");
I want to change the "Close0.02" to: ,"Close " + LotsToClose_Big
like below but it gives me an error that I kind of understand but don't know how to fix
Code: Select all ObjectSetInteger(0,"PartialClose_EA",OBJPROP_STATE,false);
ObjectSetString(0,"PartialClose_EA",OBJPROP_TEXT,"Close " + LotsToClose_Big);
Complete code found below.
What do you guys think , what is the easiest way I might try to fix please?
Thanks for taking the time to read this far.
Rooi
Code: Select all //+------------------------------------------------------------------+
//| Trade Panel.mq4 |
//| Copyright 2014, BLA |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "The Martian on the moon";
#property link "http://www.MQL5.com"
#property description "Trade Panel that runs of a timer tick trigger.Has many buttons you can set for many different size functions"
#property strict
///////////////////////////////////////////////////////////////////////////////////
//----- Basic EA Settings
extern string Basic_Settings = " « Basic EA Settings » ";
input int SL=70;
input int TP=0;
input int Slippage=200;
input int X_Distance=80;
input int Y_Distance=30;
input ENUM_BASE_CORNER Corner=1;
input int MagicNumber=777;
input string EA_Comment="EA";
//----- Button Settings
extern string Order_Open_Settings = " « Order Open Buttons » ";
input double LotsBig = 0.06; // Higest Buttons with biggest lot size
input double LotsMeduim = 0.04; // Middle Buttons with meduim lot size
input double LotsSmall = 0.02; // Lower Buttons with smallest lot size
extern string Order_Close_Settings = " « Order Close Buttons » ";
input double LotsToCLose_Big = 0.02; // Lots to close for the bigger button ( ivory color )
input double LotsToCLose_Small = 0.01; // Lots to close for the smaller button ( grey color )
////////////////////////////////////////////////////////////////////////////////////
bool AllowOpen = false;
bool AllowClose = false;
int o,c;
int Orders;
int ticket=0;
bool allSymbols=false;
bool Partial=false , Partial_5=false ;
bool b_SELL=false,b_BUY=false,b_SELL12=false,b_BUY12=false,b_Close_all=false,b_SELL13,b_BUY13;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
EventSetMillisecondTimer(100);
Orders=OrdersTotal();
//---
LabelCreate("lpm_pips_realized",X_Distance+20,Y_Distance+270,Corner,"R",clrBlack,20);
ButtonCreate("SELL",X_Distance+90,Y_Distance,70,70,Corner,LotsBig,clrBlack,clrLightCoral,clrBlack); // Highest SELL Button ( LotsBig )
ButtonCreate("SELL12",X_Distance+90,Y_Distance+90,70,70,Corner,LotsMeduim,clrBlack,clrLightCoral,clrBlack); // Middle SELL Button ( LotsMeduim )
ButtonCreate("SELL13",X_Distance+90,Y_Distance+180,70,70,Corner,LotsSmall,clrBlack,clrLightCoral,clrBlack); // Lowest SELL Button ( LotsSmall )
ButtonCreate("BUY",X_Distance,Y_Distance,70,70,Corner,LotsBig,clrBlack,clrCornflowerBlue,clrBlack); // Highest BUY Button ( LotsBig )
ButtonCreate("BUY12",X_Distance,Y_Distance+90,70,70,Corner,LotsMeduim,clrBlack,clrCornflowerBlue,clrBlack); // Middle BUY Button ( LotsMeduim )
ButtonCreate("BUY13",X_Distance,Y_Distance+180,70,70,Corner,LotsSmall,clrBlack,clrCornflowerBlue,clrBlack); // Lowest BUY Button ( LotsSmall )
ButtonCreate("CLOSE_ALL",X_Distance+60,Y_Distance+320,100,30,Corner,"CLOSE ALL",clrBlack,clrLemonChiffon,clrBlack); // CLOSE ALL LOTS BUTTON
ButtonCreate("PartialClose_EA",X_Distance+60,Y_Distance+380,100,30,Corner,"Close "+LotsToCLose_Big,clrBlack,clrLemonChiffon,clrBlack); // Part Close Big Lot Button
ButtonCreate("PartialClose_EA_5",X_Distance+40,Y_Distance+440,60,30,Corner,"Close "+LotsToCLose_Big,clrBlack,clrLightGray,clrBlack); // Part Close Small Lot Button
ButtonCreate("HIDE",X_Distance-21,Y_Distance-30,40,20,Corner,"HIDE",clrBlack,clrLemonChiffon,clrBlack);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
EventKillTimer();
Comment("");
ObjectDelete(0,"PartialClose_EA");
ObjectDelete(0,"PartialClose_EA_5");
ObjectDelete(0,"SELL");
ObjectDelete(0,"SELL12");
ObjectDelete(0,"SELL13");
ObjectDelete(0,"BUY");
ObjectDelete(0,"BUY12");
ObjectDelete(0,"BUY13");
ObjectDelete(0,"CLOSE_ALL");
ObjectDelete("lpm_pips_realized");
ObjectDelete("lots");
ObjectDelete("HIDE");
}
//+------------------------------------------------------------------+
//| Expert PartialClose functions |
//+------------------------------------------------------------------+
// ---- Partail Close of LotsToCLose_Big
void PartialClose()
{
int result;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()==Symbol() && (OrderType()<2))
{
while(IsTradeContextBusy()) Sleep(50);
RefreshRates();
double lot=LotsToCLose_Big;
lot = MathMax(lot,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN));
lot = MathMin(lot,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX));
double volumeStep=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
int digits=(int)MathCeil(MathLog10(1/volumeStep));
lot=NormalizeDouble(lot,digits);
if(OrderType()==OP_BUY){result=OrderClose(OrderTicket(),lot,Bid,Slippage,clrGold);}
else if(OrderType()==OP_SELL){result=OrderClose(OrderTicket(),lot,Ask,Slippage,clrGold);}
}
}
ObjectSetInteger(0,"PartialClose_EA",OBJPROP_STATE,false);
ObjectSetString(0,"PartialClose_EA",OBJPROP_TEXT,"Close0.02"); // Need to figure out this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Partial=false;
}
//------
// ---- Partail Close of LotsToCLose_Small
void PartialClose_5()
{
int result;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()==Symbol() && (OrderType()<2))
{
while(IsTradeContextBusy()) Sleep(50);
RefreshRates();
double lot=LotsToCLose_Small;
lot = MathMax(lot,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN));
lot = MathMin(lot,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX));
double volumeStep=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
int digits=(int)MathCeil(MathLog10(1/volumeStep));
lot=NormalizeDouble(lot,digits);
if(OrderType()==OP_BUY){result=OrderClose(OrderTicket(),lot,Bid,Slippage,clrGold);}
else if(OrderType()==OP_SELL){result=OrderClose(OrderTicket(),lot,Ask,Slippage,clrGold);}
}
}
ObjectSetInteger(0,"PartialClose_EA_5",OBJPROP_STATE,false);
ObjectSetString(0,"PartialClose_EA_5",OBJPROP_TEXT,"Close0.01"); // Need to figure out this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Partial_5=false;
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Partial) PartialClose();
if(Partial_5) PartialClose_5();
if(b_SELL) SELL();
if(b_SELL12) SELL12();
if(b_SELL13) SELL13();
if(b_BUY) BUY();
if(b_BUY12) BUY12();
if(b_BUY13) BUY13();
if(b_Close_all) Close_all();
double realized,l_realized;
calcRealized(realized,l_realized,allSymbols);
ObjectSetText("lpm_pips_realized",sign(realized)+DoubleToStr(MathAbs(realized),0));
// ObjectSetText("lots",DoubleToString(Lots,2),0);
}
//+------------------------------------------------------------------+
//| Expert timer function |
//+------------------------------------------------------------------+
void OnTimer() // Is this only place to change ?
{
if(Partial) PartialClose();
if(Partial_5) PartialClose_5();
if(b_SELL) SELL();
if(b_SELL12) SELL12();
if(b_SELL13) SELL13();
if(b_BUY) BUY();
if(b_BUY12) BUY12();
if(b_BUY13) BUY13();
if(b_Close_all) Close_all();
}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//---
if(id==CHARTEVENT_OBJECT_CLICK && sparam=="HIDE")
{
if(ObjectGetInteger(0,"HIDE",OBJPROP_STATE)==true)
{
ObjectSetInteger(0,"HIDE",OBJPROP_STATE,true);
ObjectSetInteger(0,"PartialClose_EA",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
ObjectSetInteger(0,"PartialClose_EA_5",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
ObjectSetInteger(0,"lpm_pips_realized",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
ObjectSetInteger(0,"lots",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
ObjectSetInteger(0,"SELL",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
ObjectSetInteger(0,"SELL12",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
ObjectSetInteger(0,"SELL13",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
ObjectSetInteger(0,"BUY",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
ObjectSetInteger(0,"BUY12",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
ObjectSetInteger(0,"BUY13",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
ObjectSetInteger(0,"CLOSE_ALL",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
}
if(ObjectGetInteger(0,"HIDE",OBJPROP_STATE)==false)
{
ObjectSetInteger(0,"HIDE",OBJPROP_STATE,false);
ObjectSetInteger(0,"PartialClose_EA",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,"PartialClose_EA_5",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,"SELL",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,"lpm_pips_realized",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,"lots",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,"SELL12",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,"SELL13",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,"BUY",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,"BUY12",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,"BUY13",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,"CLOSE_ALL",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
}
}
if(id==CHARTEVENT_OBJECT_CLICK && sparam=="PartialClose_EA")
{
Partial=true;
ObjectSetString(0,"PartialClose_EA",OBJPROP_TEXT,"Wait...");
}
if(id==CHARTEVENT_OBJECT_CLICK && sparam=="PartialClose_EA_5")
{
Partial_5=true;
ObjectSetString(0,"PartialClose_EA_5",OBJPROP_TEXT,"Wait...");
}
if(id==CHARTEVENT_OBJECT_CLICK && sparam=="SELL")
{
b_SELL=true;
ObjectSetString(0,"SELL",OBJPROP_TEXT,"Wait...");
}
if(id==CHARTEVENT_OBJECT_CLICK && sparam=="SELL12")
{
b_SELL12=true;
ObjectSetString(0,"SELL12",OBJPROP_TEXT,"Wait...");
}
if(id==CHARTEVENT_OBJECT_CLICK && sparam=="SELL13")
{
b_SELL13=true;
ObjectSetString(0,"SELL13",OBJPROP_TEXT,"Wait...");
}
if(id==CHARTEVENT_OBJECT_CLICK && sparam=="BUY")
{
b_BUY=true;
ObjectSetString(0,"BUY",OBJPROP_TEXT,"Wait...");
}
if(id==CHARTEVENT_OBJECT_CLICK && sparam=="BUY12")
{
b_BUY12=true;
ObjectSetString(0,"BUY12",OBJPROP_TEXT,"Wait...");
}
if(id==CHARTEVENT_OBJECT_CLICK && sparam=="BUY13")
{
b_BUY13=true;
ObjectSetString(0,"BUY13",OBJPROP_TEXT,"Wait...");
}
if(id==CHARTEVENT_OBJECT_CLICK && sparam=="CLOSE_ALL")
{
b_Close_all=true;
ObjectSetString(0,"CLOSE_ALL",OBJPROP_TEXT,"Wait...");
}
}
//+------------------------------------------------------------------+ ////////////////////////////////
void SELL() // LotsBig , Higest Button
{
OrderSendN(3);
ObjectSetInteger(0,"SELL",OBJPROP_STATE,false);
ObjectSetString(0,"SELL",OBJPROP_TEXT,"SELL 0.04"); // Need to figure out this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
b_SELL=false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void SELL12() // LotsMeduim , Middle Button
{
OrderSendN(4);
ObjectSetInteger(0,"SELL12",OBJPROP_STATE,false);
ObjectSetString(0,"SELL12",OBJPROP_TEXT,"SELL 0.03"); // Need to figure out this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
b_SELL12=false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void SELL13() // LotsSmall , Lowest Button
{
OrderSendN(5);
ObjectSetInteger(0,"SELL13",OBJPROP_STATE,false);
ObjectSetString(0,"SELL13",OBJPROP_TEXT,"SELL 0.02"); // Need to figure out this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
b_SELL13=false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void BUY() // LotsBig , Higest Button
{
OrderSendN(1);
ObjectSetInteger(0,"BUY",OBJPROP_STATE,false);
ObjectSetString(0,"BUY",OBJPROP_TEXT,"BUY 0.04"); // Need to figure out this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
b_BUY=false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void BUY12() // LotsMeduim , Middle Button
{
OrderSendN(2);
ObjectSetInteger(0,"BUY12",OBJPROP_STATE,false);
ObjectSetString(0,"BUY12",OBJPROP_TEXT,"BUY 0.03"); // Need to figure out this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
b_BUY12=false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void BUY13() // LotsSmall , Lowest Button
{
OrderSendN(6);
ObjectSetInteger(0,"BUY13",OBJPROP_STATE,false);
ObjectSetString(0,"BUY13",OBJPROP_TEXT,"BUY 0.02"); // Need to figure out this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
b_BUY13=false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Close_all()
{
for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
bool close;
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
int ticket=OrderTicket();
double lots=OrderLots();
int Otype=OrderType();
if(OrderMagicNumber()==MagicNumber)
{
if(Otype==OP_BUY)
{
close=OrderClose(ticket,lots,NormalizeDouble(Bid,Digits),3);
}
if(Otype==OP_SELL)
{
close=OrderClose(ticket,lots,NormalizeDouble(Ask,Digits),3);
}
}
}
ObjectSetInteger(0,"CLOSE_ALL",OBJPROP_STATE,false);
ObjectSetString(0,"CLOSE_ALL",OBJPROP_TEXT,"CLOSE_ALL");
b_Close_all=false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OrderSendN(int Num)
{
int ticket=0;
double sl=0,tp=0;
double lot;
if(Num==1) // Buy LotsBig
{
lot=NormalizeDouble(LotsBig,Digits);
double pri=Ask;
if(SL==0){sl=0;}else{sl=pri-SL*_Point;}
if(TP==0){tp=0;}else{tp=pri+TP*_Point;}
ticket=OrderSend(Symbol(),OP_BUY,lot,pri,3,sl,tp,EA_Comment,MagicNumber,0,clrNONE);
}
if(Num==2) // Buy LotsMeduim
{
lot=NormalizeDouble(LotsMeduim,Digits);
double pri=Ask;
if(SL==0){sl=0;}else{sl=pri-SL*_Point;}
if(TP==0){tp=0;}else{tp=pri+TP*_Point;}
ticket=OrderSend(Symbol(),OP_BUY,lot,pri,3,sl,tp,EA_Comment,MagicNumber,0,clrNONE);
}
if(Num==6) // Buy LotsSmall
{
lot=NormalizeDouble(LotsSmall,Digits);
double pri=Ask;
if(SL==0){sl=0;}else{sl=pri-SL*_Point;}
if(TP==0){tp=0;}else{tp=pri+TP*_Point;}
ticket=OrderSend(Symbol(),OP_BUY,lot,pri,3,sl,tp,EA_Comment,MagicNumber,0,clrNONE);
}
if(Num==3) // Sell LotsBig
{
lot=NormalizeDouble(LotsBig,Digits);
double pri=Bid;
if(SL==0){sl=0;}else{sl=pri+SL*_Point;}
if(TP==0){tp=0;}else{tp=pri-TP*_Point;}
ticket=OrderSend(Symbol(),OP_SELL,lot,pri,3,sl,tp,EA_Comment,MagicNumber,0,clrNONE);
}
if(Num==4) // LotsMeduim
{
lot=NormalizeDouble(LotsMeduim,Digits);
double pri=Bid;
if(SL==0){sl=0;}else{sl=pri+SL*_Point;}
if(TP==0){tp=0;}else{tp=pri-TP*_Point;}
ticket=OrderSend(Symbol(),OP_SELL,lot,pri,3,sl,tp,EA_Comment,MagicNumber,0,clrNONE);
}
if(Num==5) // LotsSmall
{
lot=NormalizeDouble(LotsSmall,Digits);
double pri=Bid;
if(SL==0){sl=0;}else{sl=pri+SL*_Point;}
if(TP==0){tp=0;}else{tp=pri-TP*_Point;}
ticket=OrderSend(Symbol(),OP_SELL,lot,pri,3,sl,tp,EA_Comment,MagicNumber,0,clrNONE);
}
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string sign(double value)
{
if(value>0){return("+");}
if(value<0){return("-");}
return("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void calcRealized(double &out,double &l_out,bool _allSymbols=false)
{
double profit=0,t_lots=0;
double p=0,l=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(_allSymbols || OrderSymbol()==Symbol())
{
p=0;l=0;
if(OrderType()==OP_BUY)
{
p=(OrderClosePrice()-OrderOpenPrice()-0.00007)/Point;
l=OrderLots();
}
if(OrderType()==OP_SELL)
{
p=(OrderOpenPrice()-OrderClosePrice()-0.00007)/Point;
l=OrderLots();
}
profit+=p;
t_lots+=l;
}
}
}
out=profit;
l_out=t_lots;
}
//——————————————————————————————————————————————————|
string CloseOrders()
{
int tip;
string txt="";
if(!AllowOpen) return(txt);
for(c=OrdersHistoryTotal()-1; c>=0; c --)
{
if(OrderSelect(c,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol())
{
tip=OrderType();
if(tip == OP_BUY) txt = "Close Buy";
if(tip == OP_SELL) txt = "Close Sell";
ticket=OrderTicket();
return(txt);
}
}
}
return("");
}
//—————————————————————————————————————————————————|
string OpenOrders()
{
int tip;
string txt="";
if(!AllowClose) return(txt);
for(o=OrdersTotal()-1; o>=0; o --)
{
if(OrderSelect(o,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
tip=OrderType();
if(tip == OP_BUY) txt = "Open Buy";
if(tip == OP_SELL) txt = "Open Sell";
ticket=OrderTicket();
return(txt);
}
}
}
return("");
}
//————————————| end of the algorithm |—————————————|
//+------------------------------------------------------------------+
//| Create the button |
//+------------------------------------------------------------------+
bool ButtonCreate(const string name="Button", // button name
const int x=0, // X coordinate
const int y=0, // Y coordinate
const int width=50, // button width
const int height=18, // button height
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
const string text="Button", // text
const color clr=clrBlack, // text color
const color back_clr=C'236,233,216', // background color
const color border_clr=clrNONE)
{
ResetLastError();
if(!ObjectCreate(0,name,OBJ_BUTTON,0,0,0))
{
Print(__FUNCTION__,
": failed to create the button! Error code = ",GetLastError());
return(false);
}
ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
ObjectSetInteger(0,name,OBJPROP_XSIZE,width);
ObjectSetInteger(0,name,OBJPROP_YSIZE,height);
ObjectSetInteger(0,name,OBJPROP_CORNER,corner);
ObjectSetString(0,name,OBJPROP_TEXT,text);
ObjectSetString(0,name,OBJPROP_FONT,"Segoe UI");
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,8);
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
ObjectSetInteger(0,name,OBJPROP_BGCOLOR,back_clr);
ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,border_clr);
ObjectSetInteger(0,name,OBJPROP_BACK,false);
ObjectSetInteger(0,name,OBJPROP_STATE,false);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
return(true);
}
//+------------------------------------------------------------------+
//| Create a text label |
//+------------------------------------------------------------------+
bool LabelCreate(const string name="Label", // label name
const int x=0, // X coordinate
const int y=0, // Y coordinate
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
const string text="Label", // text
const color clr=clrRed,
const int size=12,
)
{
ResetLastError();
if(!ObjectCreate(0,name,OBJ_LABEL,0,0,0))
{
Print(__FUNCTION__,
": failed to create text label! Error code = ",GetLastError());
return(false);
}
ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
ObjectSetInteger(0,name,OBJPROP_CORNER,corner);
ObjectSetString(0,name,OBJPROP_TEXT,text);
ObjectSetString(0,name,OBJPROP_FONT,"Arial");
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,size);
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
ObjectSetInteger(0,name,OBJPROP_BACK,false);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
return(true);
}
|