Membre très actif
140 messages
- Inscrit le :
- 14 Jun 2020
- Genre :
- m
- Trading :
- Réel
Fonction ATR Trend complémentaire.
Code
//+------------------------------------------------------------------+
//| SuperTrendPLUS.mq4 |
//| MQLTA/aRka3579 |
//+------------------------------------------------------------------+
#property copyright "18/05/2022"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 clrDodgerBlue
#property indicator_color2 clrFireBrick
#property indicator_width1 1
#property indicator_width2 1
//| Custom indicator initialization function |
bool ALERT(){
bool Alert_ = false;
if(ALERT_ON) Alert_ = true;
return(Alert_);}
enum ENUM_CUSTOMTIMEFRAMES{
CURRENT=PERIOD_CURRENT, //CURRENT PERIOD
M1=PERIOD_M1, //M1
M5=PERIOD_M5, //M5
M15=PERIOD_M15, //M15
M30=PERIOD_M30, //M30
H1=PERIOD_H1, //H1
H4=PERIOD_H4, //H4
D1=PERIOD_D1, //D1
W1=PERIOD_W1, //W1
MN1=PERIOD_MN1, //MN1
};
enum ENUM_ACCURACY{
HIGH=1, //HIGH
MEDIUM=2, //MEDIUM
LOW=3, //LOW
};
enum ENUM_THICKNESS{
ONE=1, //1
TWO=2, //2
THREE=3, //3
FOUR=4, //4
FIVE=5, //5
};
enum ENUM_WHENNOTIFY{
TRENDING=0, //WHEN TRENDING
UNCERTAIN=1, //WHEN UNCERTAIN
CHANGE=2, //WHEN CONDITION CHANGE
TOTREND=3, //WHEN CHANGING TO TRENDING
TOUNCERTAIN=4, //WHEN CHANGING TO UNCERTAIN
};
enum ENUM_NOTIFICATION_INTERVAL_TIME{
MIN1=1, //1 MINUTE
MIN5=5, //5 MINUTES
MIN15=15, //15 MINUTES
};
extern string IndicatorName="SuperTrendPro+PLUS"; //Indicator Name (to name the objects)
extern bool ALERT_ON = True;
input bool PUSH = true; // Push Notification
extern bool EnableNotify_Buy = true; //Enable Notifications feature
extern bool EnableNotify_Sell = true; //Enable Notifications feature
input string _1="===================="; //Indicator Settings
sinput ENUM_TIMEFRAMES TF_Alert = PERIOD_CURRENT;// Timeframe
extern int BK_Turtle = 20;
extern bool StrictEntry = true;
input int MA_Mode = 0; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma
extern int MA_Open = 20;
input int BB_period = 50;
input double BB_deviation = 1.9;
extern double ATRMultiplier = 2.4; //ATR Multiplier
input string _2="===================="; //Enabled Timeframes
extern bool TFM1=false; //Enable Timeframe M1
extern bool TFM5=false; //Enable Timeframe M5
extern bool TFM15=false; //Enable Timeframe M15
extern bool TFM30=true; //Enable Timeframe M30
extern bool TFH1=false; //Enable Timeframe H1
extern bool TFH4=false; //Enable Timeframe H4
extern bool TFD1=false; //Enable Timeframe D1
extern bool TFW1=false; //Enable Timeframe W1
extern bool TFMN1=false; //Enable Timeframe MN1
input string _3="===================="; //Notification Options
extern ENUM_WHENNOTIFY WhenNotify=TOTREND; //Notify When
//input ENUM_NOTIFICATION_INTERVAL_TIME NotInterval=MIN60; //Notification Interval
extern bool SendAlert=true; //Send Alert Notification
extern bool SendApp=true; //Send Notification to Mobile
extern bool SendEmail=true; //Send Notification via Email
input int WaitTimeNotify=5; //Wait time between notifications (Minutes)
input string _4="===================="; //Graphical Objects
extern bool DrawWindowEnabled=true; //Draw Window
extern int Xoff=3; //Horizontal spacing for the control panel
extern int Yoff=150; //Vertical spacing for the control panel
double rhigh = iHigh(Symbol(),Period(),iHighest(Symbol(), Period(), MODE_HIGH, BK_Turtle,1+1));
double rlow = iLow(Symbol(),Period(),iLowest(Symbol(), Period(), MODE_LOW, BK_Turtle, 1+1));
double CLOSE = iClose(Symbol(),0, 1);
double HIGH2 = iHigh(Symbol(),0, 1);
double LOW2 = iLow(Symbol(),0, 1);
double TrendUp[], TrendDown[];
double TrendUpTmp[], TrendDownTmp[];
int changeOfTrend;
int MaxBars=1400;
double Array[];
int CalculatedBars=0;
double LevelAbove=0;
double LevelBelow=0;
int DistanceFromSupport=0;
int DistanceFromResistance=0;
int MinDistance=0;
//int NotificationInterval=NotInterval*60;
bool Notified=false;
int EnabledCount=0;
int UpCount=0;
int DownCount=0;
bool UpTrend=false;
bool DownTrend=false;
int CurrentTrend=0;
bool ToTrend=false;
bool ToUncerain=false;
bool TrendChanged=false;
bool TFEnabled[9];
int TFValues[9];
string TFText[9];
int TFTrend[9];
double BufferZero[1];
double BufferOne[1];
double BufferTwo[1];
double BufferThree[1];
double BufferFour[1];
double BufferFive[1];
double BufferSix[1];
double BufferSeven[1];
int OnInit(){
string ls_01 = " Levier: " + AccountLeverage()
+ "\n"
+ "\n"
+ " Heure du Server: " + TimeToStr(TimeCurrent(), TIME_SECONDS)
+ "\n";
string ls_02 = "-------------------------------------\n"+"\n";
string ls_07 = " Solde : " + AccountBalance()
+ "\n";
string ls_08 = " Equity : " + AccountEquity()
+ "\n";
string ls_09 = " Account Profits : " + AccountProfit()
+ "\n";
string ls_10 = " Symbol : " + Symbol()
+ "\n";
string ls_11 = " Profit : " + OrderProfit()
+ "\n";
Comment( ls_01 + ls_02 + ls_07 + ls_08 + ls_09 + ls_10 + ls_11 );
IndicatorSetString(INDICATOR_SHORTNAME,IndicatorName);
CleanChart();
CalculatedBars=0;
Notified=false;
CurrentTrend=0;
ToTrend=false;
ToUncerain=false;
//LastNotification=TimeCurrent()-NotInterval*60;
TFEnabled[0]=TFM1;
TFEnabled[1]=TFM5;
TFEnabled[2]=TFM15;
TFEnabled[3]=TFM30;
TFEnabled[4]=TFH1;
TFEnabled[5]=TFH4;
TFEnabled[6]=TFD1;
TFEnabled[7]=TFW1;
TFEnabled[8]=TFMN1;
TFValues[0]=PERIOD_M1;
TFValues[1]=PERIOD_M5;
TFValues[2]=PERIOD_M15;
TFValues[3]=PERIOD_M30;
TFValues[4]=PERIOD_H1;
TFValues[5]=PERIOD_H4;
TFValues[6]=PERIOD_D1;
TFValues[7]=PERIOD_W1;
TFValues[8]=PERIOD_MN1;
TFText[0]="M1";
TFText[1]="M5";
TFText[2]="M15";
TFText[3]="M30";
TFText[4]="H1";
TFText[5]="H4";
TFText[6]="D1";
TFText[7]="W1";
TFText[8]="MN1";
EnabledCount=0;
UpCount=0;
DownCount=0;
UpTrend=false;
DownTrend=false;
ArrayInitialize(TFTrend,0);
SetIndexBuffer(2,BufferZero);
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(0,TrendUp);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexLabel(0,"Trend Up");
SetIndexBuffer(1,TrendDown);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
SetIndexLabel(1,"Trend Down");
CalculateLevels();
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 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(CalculatedBars!=prev_calculated){
CalculateLevels();
CalculatedBars=prev_calculated;
}
//Print(CalculatedBars," ",prev_calculated," ",iBars(Symbol(),SRTimeframe));
CalculatedBars=prev_calculated;
FillBuffers();
CalculateSuperTrend();
if(EnableNotify_Buy)
if (PUSH)
if((((CLOSE > rhigh && 1 > 0) || (HIGH2 > rhigh)) && StrictEntry == true) && (iMA(NULL,TF_Alert,MA_Open,0,MA_Mode,PRICE_CLOSE,1) > iBands(NULL,TF_Alert,BB_period,BB_deviation,0,PRICE_OPEN,MODE_UPPER,1)))
if (iMA(NULL,TF_Alert,1,0,MODE_SMA,PRICE_CLOSE,1) > iMA(NULL,TF_Alert,MA_Open,0,MA_Mode,PRICE_CLOSE,1) && (ALERT()))
SendNotification("Alerte BUY : " + Symbol() + " " + DoubleToStr(Bid,Digits) + " " + "\n" + TimeToStr(TimeCurrent(),TIME_SECONDS)+" "+TimeToStr(TimeCurrent(),TIME_DATE));
{
Notify();
}
if(EnableNotify_Sell)
if (PUSH)
if((((CLOSE < rlow && 1 > 0) || (LOW < rlow)) && StrictEntry == true) && (iMA(NULL,TF_Alert,MA_Open,0,MA_Mode,PRICE_CLOSE,1) < iBands(NULL,TF_Alert,BB_period,BB_deviation,0,PRICE_OPEN,MODE_UPPER,1)))
if (iMA(NULL,TF_Alert,1,0,MODE_SMA,PRICE_CLOSE,1) < iMA(NULL,TF_Alert,MA_Open,0,MA_Mode,PRICE_CLOSE,1) && (ALERT()))
SendNotification("Alerte SELL : " + Symbol() + " " + DoubleToStr(Bid,Digits) + " " + "\n" + TimeToStr(TimeCurrent(),TIME_SECONDS)+" "+TimeToStr(TimeCurrent(),TIME_DATE));
{
Notify();
}
if(DrawWindowEnabled) DrawPanel();
return(rates_total);
}
void OnDeinit(const int reason){
CleanChart();
RemoveArrows();
}
void CleanChart(){
int Window=0;
for(int i=ObjectsTotal(ChartID(),Window,-1)-1;i>=0;i--){
if(StringFind(ObjectName(i),IndicatorName,0)>=0){
ObjectDelete(ObjectName(i));
}
}
}
datetime NewCandleTime=TimeCurrent();
bool IsNewCandle(){
if(NewCandleTime==iTime(Symbol(),0,0)) return false;
else{
NewCandleTime=iTime(Symbol(),0,0);
return true;
}
}
void CalculateLevels(){
EnabledCount=0;
UpCount=0;
DownCount=0;
UpTrend=false;
DownTrend=false;
MaxBars=1400;
ArrayInitialize(TFTrend,0);
for(int i=0;i<ArraySize(TFTrend);i++){
if(!TFEnabled[i]) continue;
if(iBars(Symbol(),TFValues[i])<MaxBars){
MaxBars=iBars(Symbol(),TFValues[i]);
Print("Please Load More Historical Candles, Calculation on only ",MaxBars," Bars for Timeframe ",TFText[i]);
if(MaxBars<0){
break;
}
}
EnabledCount++;
int TFValue=TFValues[i];
string TFDesc=TFText[i];
double ATRTrend=GetATRTrend(Symbol(),TFValue,0);
if(ATRTrend==0){
Print("Not enough historical data, please load more candles for ",TFDesc);
}
if(iClose(Symbol(),TFValues[i],0)>ATRTrend){
TFTrend[i]=1;
UpCount++;
}
if(iClose(Symbol(),TFValues[i],0)<ATRTrend){
TFTrend[i]=-1;
DownCount++;
}
}
if(UpCount==EnabledCount) UpTrend=true;
if(DownCount==EnabledCount) DownTrend=true;
}
double GetATRTrend(string Instrument=NULL, int Timeframe=0, int shift=0){
ArrayResize(TrendDownTmp,1400,0);
ArrayInitialize(TrendDownTmp,0);
ArrayResize(TrendUpTmp,1400,0);
ArrayInitialize(TrendUpTmp,0);
if(Instrument==NULL) Instrument=Symbol();
if(Timeframe==0) Timeframe=Period();
CalculateSupertrendTmp(Timeframe);
//Print(ATRMaxBars," ",Shift);
double ATRTrend1=TrendUpTmp[shift];
double ATRTrend2=TrendDownTmp[shift];
//Print(Timeframe," ",ATRTrend1," ",ATRTrend2);
if(ATRTrend1>(iClose(Instrument,Timeframe,shift)*2)){
return NormalizeDouble(ATRTrend2,(int)MarketInfo(Instrument,MODE_DIGITS));
}
if(ATRTrend2>(iClose(Instrument,Timeframe,shift)*2)){
return NormalizeDouble(ATRTrend1,(int)MarketInfo(Instrument,MODE_DIGITS));
}
if(ATRTrend1==0){
Print("Please Check That you Have Installed the Indicator MQLTA Supertrend Line");
}
return 0;
}
void FillBuffers(){
if(UpTrend) BufferZero[0]=1;
if(DownTrend) BufferZero[0]=-1;
if(!UpTrend && !DownTrend) BufferZero[0]=0;
//Print("Trend:",BufferZero[0]);
BufferOne[0]=0;
BufferTwo[0]=0;
BufferThree[0]=0;
BufferFour[0]=0;
BufferFive[0]=0;
BufferSix[0]=0;
BufferSeven[0]=0;
TrendChangedCheck();
}
void TrendChangedCheck(){
TrendChanged=false;
ToTrend=false;
ToUncerain=false;
if(CurrentTrend!=BufferZero[0]){
CurrentTrend = (int)BufferZero[0];
if(CurrentTrend==0){
ToUncerain=true;
ToTrend=false;
}
else{
ToUncerain=false;
ToTrend=true;
}
TrendChanged=true;
}
else TrendChanged=false;
}
datetime LastNotification=TimeCurrent()-WaitTimeNotify*60;
void Notify(){
if(!EnableNotify_Buy || TimeCurrent()<(LastNotification+WaitTimeNotify*60)) return;
if(!EnableNotify_Sell || TimeCurrent()<(LastNotification+WaitTimeNotify*60)) return;
if(!SendAlert && !SendApp && !SendEmail) return;
//if(LastNotification>(TimeCurrent()-NotInterval*60)) return;
//Print(MinDistance," ",SafeDistance);
if(WhenNotify==CHANGE && !TrendChanged) return;
if(WhenNotify==TRENDING && !UpTrend && !DownTrend) return;
if(WhenNotify==UNCERTAIN && (UpTrend || DownTrend)) return;
if(WhenNotify==TOTREND && !ToTrend) return;
if(WhenNotify==TOUNCERTAIN && !ToUncerain) return;
string TrendString="NO TREND";
if(UpTrend) TrendString="UPTREND";
if(DownTrend) TrendString="DOWNTREND";
string EmailSubject=IndicatorName+" "+Symbol()+" Notification ";
string EmailBody="\r\n"+AccountCompany()+" - "+AccountName()+" - "+IntegerToString(AccountNumber())+"\r\n\r\n"+IndicatorName+" Notification for "+Symbol()+"\r\n\r\n";
if(WhenNotify==TRENDING) EmailBody+="The Pair is currently in a Trend - "+TrendString+"\r\n\r\n";
if(WhenNotify==UNCERTAIN) EmailBody+="The Pair is NOT Trending\r\n\r\n";
if(WhenNotify==CHANGE || WhenNotify==TOTREND || WhenNotify==TOUNCERTAIN) EmailBody+="The Pair changed the Trend Status - "+TrendString+"\r\n\r\n";
string AlertText=IndicatorName+" - "+Symbol()+" Notification\r\n";
if(WhenNotify==TRENDING) AlertText+="The Pair is currently in a Trend - "+TrendString+"";
if(WhenNotify==UNCERTAIN) AlertText+="The Pair is NOT Trending";
if(WhenNotify==CHANGE || WhenNotify==TOTREND || WhenNotify==TOUNCERTAIN) AlertText+="The Pair changed the Trend Status - "+TrendString+"\r\n\r\n";
string AppText=AccountCompany()+" - "+AccountName()+" - "+IntegerToString(AccountNumber())+" - "+IndicatorName+" - "+Symbol()+" - ";
if(WhenNotify==TRENDING) AppText+="The Pair is currently in a Trend - "+TrendString+"";
if(WhenNotify==UNCERTAIN) AppText+="The Pair is NOT Trending";
if(WhenNotify==CHANGE || WhenNotify==TOTREND || WhenNotify==TOUNCERTAIN) AppText+="The Pair changed the Trend Status - "+TrendString+"";
if(SendAlert) Alert(AlertText);
if(SendEmail){
if(!SendMail(EmailSubject,EmailBody)) Print("Error sending email "+IntegerToString(GetLastError()));
}
if(SendApp){
if(!SendNotification(AppText)) Print("Error sending notification "+IntegerToString(GetLastError()));
}
Notified=true;
LastNotification=TimeCurrent();
Print(IndicatorName+"-"+Symbol()+" last notification sent "+TimeToString(LastNotification));
}
int SignalWidth=0;
void CalculateSuperTrend(){
int limit, i, flag, flagh, trend[10000];
double up[10000], dn[10000], medianPrice, atr;
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return;
if(counted_bars > 0) counted_bars--;
limit=Bars-counted_bars;
MaxBars=1400;
if(Bars<MaxBars+2+14) MaxBars=Bars-2-14;
if(MaxBars<=0){
Print("Need more historical data to calculate the Supertrend, Currently have only ",Bars," Bars");
return;
}
for(i=MaxBars;i>=0;i--) {
//Print(Bars," ",i);
TrendUp[i]=EMPTY_VALUE;
TrendDown[i]=EMPTY_VALUE;
atr=iATR(NULL,0,14,i);
//Print("atr: "+atr[i]);
medianPrice = (High[i]+Low[i])/2;
//Print("medianPrice: "+medianPrice[i]);
up[i]=medianPrice+(ATRMultiplier*atr);
//Print("up: "+up[i]);
dn[i]=medianPrice-(ATRMultiplier*atr);
//Print("dn: "+dn[i]);
trend[i]=1;
if (Close[i]>up[i+1]) {
trend[i]=1;
if (trend[i+1] == -1) changeOfTrend = 1;
//Print("trend: "+trend[i]);
}
else if (Close[i]<dn[i+1]) {
trend[i]=-1;
if (trend[i+1] == 1) changeOfTrend = 1;
//Print("trend: "+trend[i]);
}
else if (trend[i+1]==1) {
trend[i]=1;
changeOfTrend = 0;
}
else if (trend[i+1]==-1) {
trend[i]=-1;
changeOfTrend = 0;
}
if (trend[i]<0 && trend[i+1]>0) {
flag=1;
//Print("flag: "+flag);
}
else {
flag=0;
//Print("flagh: "+flag);
}
if (trend[i]>0 && trend[i+1]<0) {
flagh=1;
//Print("flagh: "+flagh);
}
else {
flagh=0;
//Print("flagh: "+flagh);
}
if (trend[i]>0 && dn[i]<dn[i+1])
dn[i]=dn[i+1];
if (trend[i]<0 && up[i]>up[i+1])
up[i]=up[i+1];
if (flag==1)
up[i]=medianPrice+(ATRMultiplier*atr);
if (flagh==1)
dn[i]=medianPrice-(ATRMultiplier*atr);
//-- Draw the indicator
if (trend[i]==1) {
TrendUp[i]=dn[i];
if (changeOfTrend == 1) {
TrendUp[i+1] = TrendDown[i+1];
changeOfTrend = 0;
}
}
else if (trend[i]==-1) {
TrendDown[i]=up[i];
if (changeOfTrend == 1) {
TrendDown[i+1] = TrendUp[i+1];
changeOfTrend = 0;
}
}
}
WindowRedraw();
}
void RemoveArrowCurr(){
datetime ArrowDate=iTime(Symbol(),0,0);
string ArrowName=IndicatorName+"-ARWS-"+IntegerToString(ArrowDate);
ObjectDelete(0,ArrowName);
}
void RemoveArrows(){
int Window=-1;
for(int i=ObjectsTotal(ChartID(),Window,-1)-1;i>=0;i--){
if(StringFind(ObjectName(i),IndicatorName+"-ARWS-",0)>=0){
ObjectDelete(ObjectName(i));
}
}
}
void CalculateSupertrendTmp(int Timeframe){
MaxBars=1400;
int limit, i, flag, flagh, trend[10000];
double up[10000], dn[10000], medianPrice, atr;
int counted_bars = 0;
if(counted_bars < 0) return;
if(counted_bars > 0) counted_bars--;
limit=iBars(Symbol(),Timeframe)-counted_bars-1;
MaxBars--;
if(iBars(Symbol(),Timeframe)<MaxBars+2+14) MaxBars=iBars(Symbol(),Timeframe)-2-14;
if(MaxBars<=0){
Print("Need more historical data to calculate the Supertrend, Currently have only ",iBars(Symbol(),Timeframe)," Bars");
return;
}
for(i=MaxBars;i>=0;i--) {
//Print(Bars," ",i);
TrendUpTmp[i]=EMPTY_VALUE;
TrendDownTmp[i]=EMPTY_VALUE;
atr=iATR(Symbol(),Timeframe,14,i);
//Print("atr: "+atr[i]);
medianPrice = (iHigh(Symbol(),Timeframe,i)+iLow(Symbol(),Timeframe,i))/2;
//Print("medianPrice: "+medianPrice[i]);
up[i]=medianPrice+(ATRMultiplier*atr);
//Print("up: "+up[i]);
dn[i]=medianPrice-(ATRMultiplier*atr);
//Print("dn: "+dn[i]);
trend[i]=1;
if (iClose(Symbol(),Timeframe,i)>up[i+1]) {
trend[i]=1;
if (trend[i+1] == -1) changeOfTrend = 1;
//Print("trend: "+trend[i]);
}
else if (iClose(Symbol(),Timeframe,i)<dn[i+1]) {
trend[i]=-1;
if (trend[i+1] == 1) changeOfTrend = 1;
//Print("trend: "+trend[i]);
}
else if (trend[i+1]==1) {
trend[i]=1;
changeOfTrend = 0;
}
else if (trend[i+1]==-1) {
trend[i]=-1;
changeOfTrend = 0;
}
if (trend[i]<0 && trend[i+1]>0) {
flag=1;
//Print("flag: "+flag);
}
else {
flag=0;
//Print("flagh: "+flag);
}
if (trend[i]>0 && trend[i+1]<0) {
flagh=1;
//Print("flagh: "+flagh);
}
else {
flagh=0;
//Print("flagh: "+flagh);
}
if (trend[i]>0 && dn[i]<dn[i+1])
dn[i]=dn[i+1];
if (trend[i]<0 && up[i]>up[i+1])
up[i]=up[i+1];
if (flag==1)
up[i]=medianPrice+(ATRMultiplier*atr);
if (flagh==1)
dn[i]=medianPrice-(ATRMultiplier*atr);
//-- Draw the indicator
if(i==MaxBars) continue;
if (trend[i]==1) {
TrendUpTmp[i]=dn[i];
if (changeOfTrend == 1) {
TrendUpTmp[i+1] = TrendDownTmp[i+1];
changeOfTrend = 0;
}
}
else if (trend[i]==-1) {
TrendDownTmp[i]=up[i];
if (changeOfTrend == 1) {
TrendDownTmp[i+1] = TrendUpTmp[i+1];
changeOfTrend = 0;
}
}
}
WindowRedraw();
}
string PanelBase=IndicatorName+"-P-BAS";
string PanelLabel=IndicatorName+"-P-LAB";
string PanelDAbove=IndicatorName+"-P-DABOVE";
string PanelDBelow=IndicatorName+"-P-DBELOW";
string PanelSig=IndicatorName+"-P-SIG";
int PanelMovX=50;
int PanelMovY=20;
int PanelLabX=102;
int PanelLabY=PanelMovY;
int PanelRecX=PanelLabX+4;
void DrawPanel(){
CleanPanel();
int Rows=1;
ObjectCreate(0,PanelBase,OBJ_RECTANGLE_LABEL,0,0,0);
ObjectSet(PanelBase,OBJPROP_XDISTANCE,Xoff);
ObjectSet(PanelBase,OBJPROP_YDISTANCE,Yoff);
ObjectSetInteger(0,PanelBase,OBJPROP_XSIZE,PanelRecX);
ObjectSetInteger(0,PanelBase,OBJPROP_YSIZE,(PanelMovY+2)*1+2);
ObjectSetInteger(0,PanelBase,OBJPROP_BGCOLOR,White);
ObjectSetInteger(0,PanelBase,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,PanelBase,OBJPROP_STATE,false);
ObjectSetInteger(0,PanelBase,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,PanelBase,OBJPROP_FONTSIZE,8);
ObjectSet(PanelBase,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,PanelBase,OBJPROP_COLOR,clrBlack);
ObjectCreate(0,PanelLabel,OBJ_EDIT,0,0,0);
ObjectSet(PanelLabel,OBJPROP_XDISTANCE,Xoff+2);
ObjectSet(PanelLabel,OBJPROP_YDISTANCE,Yoff+2);
ObjectSetInteger(0,PanelLabel,OBJPROP_XSIZE,PanelLabX);
ObjectSetInteger(0,PanelLabel,OBJPROP_YSIZE,PanelLabY);
ObjectSetInteger(0,PanelLabel,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,PanelLabel,OBJPROP_STATE,false);
ObjectSetInteger(0,PanelLabel,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,PanelLabel,OBJPROP_READONLY,true);
ObjectSetInteger(0,PanelLabel,OBJPROP_ALIGN,ALIGN_CENTER);
ObjectSetString(0,PanelLabel,OBJPROP_TOOLTIP,"Drag to Move");
ObjectSetString(0,PanelLabel,OBJPROP_TEXT,"TrendPLUS");
ObjectSetString(0,PanelLabel,OBJPROP_FONT,"ARIAL");
ObjectSetInteger(0,PanelLabel,OBJPROP_FONTSIZE,11);
ObjectSet(PanelLabel,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,PanelLabel,OBJPROP_COLOR,clrBlack);
ObjectSetInteger(0,PanelLabel,OBJPROP_BGCOLOR,clrWhiteSmoke);
ObjectSetInteger(0,PanelLabel,OBJPROP_BORDER_COLOR,clrBlack);
for(int i=0;i<ArraySize(TFTrend);i++){
if(!TFEnabled[i]) continue;
string TrendRowText=IndicatorName+"-P-TREND-"+TFText[i];
string TrendRowValue=IndicatorName+"-P-TREND-V-"+TFText[i];
string TrendDirectionText=TFText[i];
string TrendDirectionValue="";
color TrendBackColor=clrWhite;
color TrendTextColor=clrNavy;
if(TFTrend[i]==1){
TrendDirectionValue="UP";
TrendBackColor=clrDodgerBlue;
TrendTextColor=clrBlack;
}
if(TFTrend[i]==-1){
TrendDirectionValue="DOWN";
TrendBackColor=clrFireBrick;
TrendTextColor=clrWhite;
}
if(TFTrend[i]==0){
TrendDirectionValue="-";
}
ObjectCreate(0,TrendRowText,OBJ_EDIT,0,0,0);
ObjectSet(TrendRowText,OBJPROP_XDISTANCE,Xoff+2);
ObjectSet(TrendRowText,OBJPROP_YDISTANCE,Yoff+(PanelMovY+1)*Rows+2);
ObjectSetInteger(0,TrendRowText,OBJPROP_XSIZE,PanelMovX);
ObjectSetInteger(0,TrendRowText,OBJPROP_YSIZE,PanelLabY);
ObjectSetInteger(0,TrendRowText,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,TrendRowText,OBJPROP_STATE,false);
ObjectSetInteger(0,TrendRowText,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,TrendRowText,OBJPROP_READONLY,true);
ObjectSetInteger(0,TrendRowText,OBJPROP_FONTSIZE,8);
ObjectSetString(0,TrendRowText,OBJPROP_TOOLTIP,"Trend Detected in the Timeframe");
ObjectSetInteger(0,TrendRowText,OBJPROP_ALIGN,ALIGN_CENTER);
ObjectSetString(0,TrendRowText,OBJPROP_FONT,"Consolas");
ObjectSetString(0,TrendRowText,OBJPROP_TEXT,TrendDirectionText);
ObjectSet(TrendRowText,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,TrendRowText,OBJPROP_COLOR,clrNavy);
ObjectSetInteger(0,TrendRowText,OBJPROP_BGCOLOR,clrWhite);
ObjectSetInteger(0,TrendRowText,OBJPROP_BORDER_COLOR,clrBlack);
ObjectCreate(0,TrendRowValue,OBJ_EDIT,0,0,0);
ObjectSet(TrendRowValue,OBJPROP_XDISTANCE,Xoff+PanelMovX+4);
ObjectSet(TrendRowValue,OBJPROP_YDISTANCE,Yoff+(PanelMovY+1)*Rows+2);
ObjectSetInteger(0,TrendRowValue,OBJPROP_XSIZE,PanelMovX);
ObjectSetInteger(0,TrendRowValue,OBJPROP_YSIZE,PanelLabY);
ObjectSetInteger(0,TrendRowValue,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,TrendRowValue,OBJPROP_STATE,false);
ObjectSetInteger(0,TrendRowValue,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,TrendRowValue,OBJPROP_READONLY,true);
ObjectSetInteger(0,TrendRowValue,OBJPROP_FONTSIZE,9);
ObjectSetString(0,TrendRowValue,OBJPROP_TOOLTIP,"Trend Detected in the Timeframe");
ObjectSetInteger(0,TrendRowValue,OBJPROP_ALIGN,ALIGN_CENTER);
ObjectSetString(0,TrendRowValue,OBJPROP_FONT,"ARIAL");
ObjectSetString(0,TrendRowValue,OBJPROP_TEXT,TrendDirectionValue);
ObjectSet(TrendRowValue,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,TrendRowValue,OBJPROP_COLOR,TrendTextColor);
ObjectSetInteger(0,TrendRowValue,OBJPROP_BGCOLOR,TrendBackColor);
ObjectSetInteger(0,TrendRowValue,OBJPROP_BORDER_COLOR,clrBlack);
Rows++;
}
string SigText="";
color SigColor=clrNavy;
color SigBack=clrWhite;
if(UpTrend){
SigText="TREND UP";
SigColor=clrWhite;
SigBack=clrDodgerBlue;
}
if(DownTrend){
SigText="TREND DOWN";
SigColor=clrWhite;
SigBack=clrDarkRed;
}
if(!UpTrend && !DownTrend){
SigText="PATIENCE..";
}
ObjectCreate(0,PanelSig,OBJ_EDIT,0,0,0);
ObjectSet(PanelSig,OBJPROP_XDISTANCE,Xoff+2);
ObjectSet(PanelSig,OBJPROP_YDISTANCE,Yoff+(PanelMovY+1)*Rows+2);
ObjectSetInteger(0,PanelSig,OBJPROP_XSIZE,PanelLabX);
ObjectSetInteger(0,PanelSig,OBJPROP_YSIZE,PanelLabY);
ObjectSetInteger(0,PanelSig,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,PanelSig,OBJPROP_STATE,false);
ObjectSetInteger(0,PanelSig,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,PanelSig,OBJPROP_READONLY,true);
ObjectSetInteger(0,PanelSig,OBJPROP_FONTSIZE,8);
ObjectSetInteger(0,PanelSig,OBJPROP_ALIGN,ALIGN_CENTER);
ObjectSetString(0,PanelSig,OBJPROP_FONT,"Consolas");
ObjectSetString(0,PanelSig,OBJPROP_TOOLTIP,"Trend Detected Considering All Timeframes");
ObjectSetString(0,PanelSig,OBJPROP_TEXT,SigText);
ObjectSet(PanelSig,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,PanelSig,OBJPROP_COLOR,SigColor);
ObjectSetInteger(0,PanelSig,OBJPROP_BGCOLOR,SigBack);
ObjectSetInteger(0,PanelSig,OBJPROP_BORDER_COLOR,clrBlack);
Rows++;
ObjectSetInteger(0,PanelBase,OBJPROP_XSIZE,PanelRecX);
ObjectSetInteger(0,PanelBase,OBJPROP_YSIZE,(PanelMovY+1)*Rows+3);
}
void CleanPanel(){
int Window=0;
for(int i=ObjectsTotal(ChartID(),Window,-1)-1;i>=0;i--){
if(StringFind(ObjectName(i),IndicatorName+"-P-",0)>=0){
ObjectDelete(ObjectName(i));
}
}
}