ProRealCode - Trading & Coding with ProRealTime™
Buongiorno, ho letto in diversi forum che ci sono persone che traducono gratuitamente i codici da altri linguaggi a prorealcode.
Vorrei fare la stessa cosa se è possibile, grazie mille in anticipo a chiunque si renda disponibile.
In più avrei una domanda, è possibile eventualmente utilizzare questo codice del mio indicatore, progettato per individuare particolari condizioni di mercato, e trasformarlo in un market screener in modo da rendere il tutto molto più efficiente sulla ricerca in cross multipli?
Questo è il codice in MQL4:
#property copyright “Copyright 2024, MetaQuotes Ltd.”
#property link “https://www.mql5.com”
#property version “1.00”
#property strict
#property indicator_chart_window
#property indicator_buffers 4
extern int History = 500;
ENUM_TIMEFRAMES Time_Frame_Main = PERIOD_CURRENT;
extern ENUM_TIMEFRAMES Time_Frame_Sub = PERIOD_M5; // Timeframe Higher TF
extern string Sel_1 = “——————–Super Trend Settings——————–“;
extern int Super_Trend_Period = 10;
extern double Super_Trend_Multiplier = 3;
extern string Sel_2 = “———————William % Settings———————“;
extern int William_Percent_Period = 140;
extern double William_Over_Bought_Level = -20;
extern double William_Middle_Level = -50;
extern double William_Over_Sold_Level = -80;
datetime tm;
//**************************************************************************//
//*** Custom indicator buffers ***
//**************************************************************************//
double Trend_William1[],Trend_William2[];
double Buy_Case1[],Buy_Case2[];
double Sell_Case1[],Sell_Case2[];
double Super_Trend_Red[],Super_Trend_Green[];
//**************************************************************************//
//*** Custom indicator initialization function ***
//**************************************************************************//
extern string Sep_2 = “———————Arrow Color and NotificaitonSettings———————“;
extern color Buy1_Color = clrGreen;
extern color Buy2_Color = clrYellow;
extern color Sell1_Color = clrRed;
extern color Sell2_Color = clrYellow;
extern bool Use_Pop_Up_Alerts = true;
extern bool Use_Push_Notifications = true;
extern string Sep_3 = “————————–Timer Notificaiton Settings————————-“;
extern double X_Axis = 0;
extern double Y_Axis = 50;
extern color Clr = clrGreen;
int Font_Size = 12;
int Chart_Y_Increament = 1;
int Factor1 = 2;
int Factor2 = 3;
datetime last_alert_time=0;
int init()
{
IndicatorBuffers(4); //IndicatorDigits(Digits); // if (Digits==3 || Digits==5) IndicatorDigits(Digits-1);
SetIndexBuffer(0,Buy_Case1);
SetIndexBuffer(1,Buy_Case2);
SetIndexBuffer(2,Sell_Case1);
SetIndexBuffer(3,Sell_Case2);
SetIndexStyle(0,DRAW_ARROW, STYLE_SOLID,4,Buy1_Color);
SetIndexArrow(0,233);
SetIndexStyle(1,DRAW_ARROW, STYLE_SOLID,4,Buy2_Color);
SetIndexArrow(1,233);
SetIndexStyle(2,DRAW_ARROW, STYLE_SOLID,4,Sell1_Color);
SetIndexArrow(2,234);
SetIndexStyle(3,DRAW_ARROW, STYLE_SOLID,4,Sell2_Color);
SetIndexArrow(3,234);
SetIndexEmptyValue(0,1);
SetIndexEmptyValue(1,1);
SetIndexEmptyValue(2,0);
SetIndexEmptyValue(3,0);
LabelCreate(“Timer”,X_Axis, Y_Axis, Clr, Font_Size);
LabelUpdate(“Timer”,”–“);
// LabelCreate(“Timer_Name”,X_Axis,Y_Axis+Chart_Y_Increament+((Font_Size/Factor1)*Factor2), Clr, Font_Size);
//LabelUpdate(“Timer_Name”,” Time”);
//—//—//—
return(0);
}
//**************************************************************************//
//*** Custom indicator deinitialization function ***
//**************************************************************************//
int deinit()
{
LabelDelete(0,”Timer”);
//LabelDelete(0,”Timer_Name”);
return(0);
}
//**************************************************************************//
//*** Custom indicator iteration function ***
//**************************************************************************//
int start()
{
LabelUpdate(“Timer”,(string)TimeCurrent());
int limit = BarCount();
bool flag = false;
for(int i = limit; i >= 1 ; i–)
{
CheckPatternSell(i);
CheckPatternBuy(i);
}
return(0);
}
//+——————————————————————+
int getWilliamIndexHigherTFBuy(int index , int st)
{
int count = -1;
for(int i = index; i <= History;i++)
{
double will = iWPR(_Symbol,Time_Frame_Sub,William_Percent_Period,i);
double prev_will = iWPR(_Symbol,Time_Frame_Sub,William_Percent_Period,i+1);
if(will < William_Over_Sold_Level && prev_will >= William_Over_Sold_Level)
{
count = i;
break;
}
if(will > William_Over_Bought_Level )
{
return -1;
}
}
if(count != -1)
{
for(int i = count ; i>= st;i–)
{
double will = iWPR(_Symbol,Time_Frame_Sub,William_Percent_Period,i);
if(will > William_Over_Bought_Level )
{
return -1;
}
}
return count;
}
return -1;
}
int getWilliamIndexHigherTF(int index,int st)
{
int count = -1;
for(int i = index; i <= History;i++)
{
double will = iWPR(_Symbol,Time_Frame_Sub,William_Percent_Period,i);
double prev_will = iWPR(_Symbol,Time_Frame_Sub,William_Percent_Period,i+1);
if(will > William_Over_Bought_Level && prev_will <= William_Over_Bought_Level)
{
count = i;
break;
}
if(will < William_Over_Sold_Level )
{
return -1;
}
}
if(count != -1)
{
for(int i = count ; i>= st;i–)
{
double will = iWPR(_Symbol,Time_Frame_Sub,William_Percent_Period,i);
if(will < William_Over_Sold_Level )
{
return -1;
}
}
return count;
}
return -1;
}
string GetTimeFrameString(int period)
{
switch(period)
{
case PERIOD_M1: return “M1”;
case PERIOD_M5: return “M5”;
case PERIOD_M15: return “M15”;
case PERIOD_M30: return “M30”;
case PERIOD_H1: return “H1”;
case PERIOD_H4: return “H4”;
case PERIOD_D1: return “D1”;
case PERIOD_W1: return “W1”;
case PERIOD_MN1: return “MN1”;
default: return “Unknown Period”;
}
}
void CheckPatternSell(int i)
{
int main_current_index = iBarShift(Symbol(),Time_Frame_Sub,Time[i]);
main_current_index = main_current_index+1;
// Case 1 Sell trigger
if(iWPR(_Symbol,Period(),William_Percent_Period,i) > William_Over_Bought_Level && iWPR(_Symbol,Period(),William_Percent_Period,i+1) < William_Over_Bought_Level)
{
// Print(“Sell William matched @ “+TimeToString(Time[i]));
int breaking_point = getIndexSuperTrendGreenToRed(main_current_index);
if(breaking_point > 0)
{
int main_starting_index = getWilliamIndexHigherTF(breaking_point, main_current_index);
if(main_starting_index >0)
{
/* Print(” Eillian higher index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,main_starting_index)));
Print(“main_starting_index “+main_starting_index + ” main_current_index “+main_current_index);
Print(” Eillian current higher index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,main_current_index)));
*/
for(int j= main_starting_index ; j> main_current_index;j–)
{
if(SuperTrendGreenToRed(j))
{
// Print(“SuperTrend Green to red “+iTime(Symbol(),Time_Frame_Sub,j));
int sepertrend_index = -1;
for(int l = j ; l>=main_current_index;l–)
{
if(SuperTrendRedToGreen(l))
{
//Print(“False Return @ “+iTime(Symbol(),Time_Frame_Sub,l));
sepertrend_index = l;
break;
}
}
if(sepertrend_index ==-1)
{
//Print(“MATCH MATCH”);
int lower_tf_ST_index = iBarShift(Symbol(),PERIOD_CURRENT,iTime(Symbol(),Time_Frame_Sub,j));
//Print(“Red to green Index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,j)));
for(int k = lower_tf_ST_index; k>=i;k–)
{
if(iWPR(_Symbol,Period(),William_Percent_Period,k) < William_Middle_Level)
{
// Print(“Middle band touched “+Time[k]);
bool flag = true;
for(int ko = k; ko>=i+1;ko–)
{
if(iWPR(_Symbol,Period(),William_Percent_Period,ko) > William_Over_Bought_Level)
{
flag = false;
}
}
if(flag)
{
Sell_Case1[i] = High[i];
if(i==1)
{
if(last_alert_time!= Time[1])
{
if(Use_Pop_Up_Alerts)
{
Alert(“Sell WPR crossing on Symbol “+Symbol() + ” and Timeframe “+GetTimeFrameString(_Period) +” @ “+TimeToString(Time[1]) );
}
if(Use_Push_Notifications)
{
SendNotification(“Sell WPR crossing on Symbol “+Symbol() + ” and Timeframe “+GetTimeFrameString(_Period) +” @ “+TimeToString(Time[1]) );
}
last_alert_time = Time[1];
}
}
}
break;
}
}
}
break;
}
}
}
}
}
// Case 2 Sell trigger
if(SuperTrendRedToGreen(main_current_index))
{
//Print(“Sell William matched @ “+TimeToString(Time[i]));
int breaking_point = getIndexSuperTrendGreenToRed(main_current_index);
if(breaking_point > 0)
{
int main_starting_index = getWilliamIndexHigherTF(breaking_point,main_current_index);
if(main_starting_index >0)
{
//Print(” Eillian higher index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,main_starting_index)));
//Print(“main_starting_index “+main_starting_index + ” main_current_index “+main_current_index);
//Print(” Eillian current higher index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,main_current_index)));
for(int j= main_starting_index ; j> main_current_index;j–)
{
if(SuperTrendGreenToRed(j))
{
//Print(“SuperTrend Green to red “+iTime(Symbol(),Time_Frame_Sub,j));
int sepertrend_index = -1;
for(int l = j ; l>=main_current_index+1;l–)
{
if(SuperTrendRedToGreen(l))
{
// Print(“False Return @ “+iTime(Symbol(),Time_Frame_Sub,l));
sepertrend_index = l;
break;
}
}
int shift = iBarShift(Symbol(),Period(),iTime(Symbol(),Time_Frame_Sub,sepertrend_index));
//Print(“Shift “+shift);
if(sepertrend_index == -1 )
{
// Print(“MATCH MATCH”);
int lower_tf_ST_index = iBarShift(Symbol(),Period(),iTime(Symbol(),Time_Frame_Sub,j));
//Print(“Red to green Index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,j)));
bool f = false;
int indexer = -1;
for(int k = lower_tf_ST_index; k>=i;k–)
{
if(iWPR(_Symbol,Period(),William_Percent_Period,k) < William_Middle_Level)
{
indexer = k;
for(int y = k; y>= i;y–)
{
if(iWPR(_Symbol,Period(),William_Percent_Period,y) > William_Over_Bought_Level)
{
f = true;
break;
}
}
}
}
if(f== false)
{
int shift1 = iBarShift(Symbol(),Period(),iTime(Symbol(),Time_Frame_Sub,main_current_index));
int time_differnce = Time_Frame_Sub/Period();
if((shift1 – i) == time_differnce)
{
Sell_Case2[i] = High[i];
if(i==1)
{
if(last_alert_time!= Time[1])
{
if(Use_Pop_Up_Alerts)
{
Alert(“Sell Supertrend crossing on Symbol “+Symbol() + ” and Timeframe “+GetTimeFrameString(_Period) +” @ “+TimeToString(Time[1]) );
}
if(Use_Push_Notifications)
{
SendNotification(“Sell Supertrend crossing on Symbol “+Symbol() + ” and Timeframe “+GetTimeFrameString(_Period) +” @ “+TimeToString(Time[1]) );
}
last_alert_time = Time[1];
}
}
}
}
}
break;
}
}
}
}
}
}
void CheckPatternBuy(int i)
{
int main_current_index = iBarShift(Symbol(),Time_Frame_Sub,Time[i]);
main_current_index = main_current_index+1;
// Case 1 Buy trigger
if(iWPR(_Symbol,Period(),William_Percent_Period,i) < William_Over_Sold_Level && iWPR(_Symbol,Period(),William_Percent_Period,i+1) > William_Over_Sold_Level)
{
int breaking_point = getIndexSuperTrendRedToGreen(main_current_index);
if(breaking_point > 0)
{
int main_starting_index = getWilliamIndexHigherTFBuy(breaking_point,main_current_index);
if(main_starting_index >0)
{
/* Print(” Eillian higher index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,main_starting_index)));
Print(“main_starting_index “+main_starting_index + ” main_current_index “+main_current_index);
Print(” Eillian current higher index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,main_current_index)));
*/
for(int j= main_starting_index ; j> main_current_index;j–)
{
if(SuperTrendRedToGreen(j))
{
// Print(“SuperTrend Green to red “+iTime(Symbol(),Time_Frame_Sub,j));
int sepertrend_index = -1;
for(int l = j ; l>=main_current_index;l–)
{
if(SuperTrendGreenToRed(l))
{
//Print(“False Return @ “+iTime(Symbol(),Time_Frame_Sub,l));
sepertrend_index = l;
break;
}
}
if(sepertrend_index ==-1)
{
//Print(“MATCH MATCH”);
int lower_tf_ST_index = iBarShift(Symbol(),PERIOD_CURRENT,iTime(Symbol(),Time_Frame_Sub,j));
//Print(“Red to green Index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,j)));
for(int k = lower_tf_ST_index; k>=i;k–)
{
if(iWPR(_Symbol,Period(),William_Percent_Period,k) > William_Middle_Level)
{
// Print(“Middle band touched “+Time[k]);
bool flag = true;
for(int ko = k; ko>=i+1;ko–)
{
if(iWPR(_Symbol,Period(),William_Percent_Period,ko) < William_Over_Sold_Level)
{
flag = false;
}
}
if(flag)
{
Buy_Case1[i] = Low[i];
if(i==1)
{
if(last_alert_time!= Time[1])
{
if(Use_Pop_Up_Alerts)
{
Alert(“Buy WPR crossing on Symbol “+Symbol() + ” and Timeframe “+GetTimeFrameString(_Period) +” @ “+TimeToString(Time[1]) );
}
if(Use_Push_Notifications)
{
SendNotification(“Buy WPR crossing on Symbol “+Symbol() + ” and Timeframe “+GetTimeFrameString(_Period) +” @ “+TimeToString(Time[1]) );
}
last_alert_time = Time[1];
}
}
}
break;
}
}
}
break;
}
}
}
}
}
// Case 2 Buy trigger
if(SuperTrendGreenToRed(main_current_index))
{
// Print(“Sell William matched @ “+TimeToString(Time[i]));
int breaking_point = getIndexSuperTrendRedToGreen(main_current_index);
if(breaking_point > 0)
{
int main_starting_index = getWilliamIndexHigherTFBuy(breaking_point,main_current_index);
if(main_starting_index >0)
{
//Print(” Eillian higher index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,main_starting_index)));
//Print(“main_starting_index “+main_starting_index + ” main_current_index “+main_current_index);
//Print(” Eillian current higher index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,main_current_index)));
for(int j= main_starting_index ; j> main_current_index;j–)
{
if(SuperTrendRedToGreen(j))
{
//Print(“SuperTrend Green to red “+iTime(Symbol(),Time_Frame_Sub,j));
int sepertrend_index = -1;
for(int l = j ; l>=main_current_index+1;l–)
{
if(SuperTrendGreenToRed(l))
{
// Print(“False Return @ “+iTime(Symbol(),Time_Frame_Sub,l));
// Print(“Index is “+l);
sepertrend_index = l;
break;
}
}
int shift = iBarShift(Symbol(),Period(),iTime(Symbol(),Time_Frame_Sub,sepertrend_index));
//Print(“Shift “+shift);
if(sepertrend_index == -1 )
{
// Print(“MATCH MATCH”);
int lower_tf_ST_index = iBarShift(Symbol(),Period(),iTime(Symbol(),Time_Frame_Sub,j));
//Print(“Red to green Index “+TimeToString(iTime(Symbol(),Time_Frame_Sub,j)));
bool f = false;
int indexer = -1;
for(int k = lower_tf_ST_index; k>=i;k–)
{
if(iWPR(_Symbol,Period(),William_Percent_Period,k) > William_Middle_Level)
{
indexer = k;
for(int y = k; y>= i;y–)
{
if(iWPR(_Symbol,Period(),William_Percent_Period,y) < William_Over_Sold_Level)
{
f = true;
break;
}
}
}
}
if(f== false)
{
int shift1 = iBarShift(Symbol(),Period(),iTime(Symbol(),Time_Frame_Sub,main_current_index));
int time_differnce = Time_Frame_Sub/Period();
if((shift1 – i) == time_differnce)
{
Buy_Case2[i] = High[i];
if(i==1)
{
if(last_alert_time!= Time[1])
{
if(Use_Pop_Up_Alerts)
{
Alert(“Buy Supertrend crossing on Symbol “+Symbol() + ” and Timeframe “+GetTimeFrameString(_Period) +” @ “+TimeToString(Time[1]) );
}
if(Use_Push_Notifications)
{
SendNotification(“Buy Supertrend crossing on Symbol “+Symbol() + ” and Timeframe “+GetTimeFrameString(_Period) +” @ “+TimeToString(Time[1]) );
}
last_alert_time = Time[1];
}
}
}
}
}
break;
}
}
}
}
}
}
//+——————————————————————+
//| |
//+——————————————————————+
int BarCount()
{
int counted_bars=IndicatorCounted();
//Print(“1. “+IndicatorCounted());
if(counted_bars<0)
return(-1);
if(counted_bars>0)
counted_bars–;
//Print(“2. “+Bars+” “+counted_bars);
int limit=Bars-counted_bars;
//if(counted_bars==0) limit-=1+ZZSpeed2;
//Print(“3. “+limit+” “+History);
limit = MathMin(limit, History);
//Print(“4. “+limit);
return limit;
}
//+——————————————————————+
//| |
//+——————————————————————+
bool SuperTrendRedToGreen(int i)
{
double supercurrentvalue1 = iCustom(_Symbol,Time_Frame_Sub,”Super Trend”,Super_Trend_Period,Super_Trend_Multiplier,0,i);
double supercurrentvalue2 = iCustom(_Symbol,Time_Frame_Sub,”Super Trend”,Super_Trend_Period,Super_Trend_Multiplier,1,i);
double superpreviousvalue1 = iCustom(_Symbol,Time_Frame_Sub,”Super Trend”,Super_Trend_Period,Super_Trend_Multiplier,0,i+1);
double superpreviousvalue2 = iCustom(_Symbol,Time_Frame_Sub,”Super Trend”,Super_Trend_Period,Super_Trend_Multiplier,1,i+1);
// if((supercurrentvalue1 == supercurrentvalue2) && (superpreviousvalue1 > superpreviousvalue2))
// return true;
if(supercurrentvalue1 != EMPTY_VALUE && supercurrentvalue2 == EMPTY_VALUE)
{
if(superpreviousvalue2 != EMPTY_VALUE)
{
return true;
}
}
return false;
}
//+——————————————————————+
//| |
//+——————————————————————+
bool SuperTrendGreenToRed(int i)
{
double supercurrentvalue1 = iCustom(_Symbol,Time_Frame_Sub,”Super Trend”,Super_Trend_Period,Super_Trend_Multiplier,0,i);
double supercurrentvalue2 = iCustom(_Symbol,Time_Frame_Sub,”Super Trend”,Super_Trend_Period,Super_Trend_Multiplier,1,i);
double superpreviousvalue1 = iCustom(_Symbol,Time_Frame_Sub,”Super Trend”,Super_Trend_Period,Super_Trend_Multiplier,0,i+1);
double superpreviousvalue2 = iCustom(_Symbol,Time_Frame_Sub,”Super Trend”,Super_Trend_Period,Super_Trend_Multiplier,1,i+1);
// if((supercurrentvalue1 == supercurrentvalue2) && (superpreviousvalue1 < superpreviousvalue2))
// return true;
if(supercurrentvalue1 == EMPTY_VALUE && supercurrentvalue2 != EMPTY_VALUE)
{
if(superpreviousvalue1 != EMPTY_VALUE)
{
return true;
}
}
return false;
}
int getIndexSuperTrendGreenToRed(int index)
{
for(int i = index;i<History;i++)
{
if(SuperTrendGreenToRed(i))
{
return i;
}
}
return -1;
}
int getIndexSuperTrendRedToGreen(int index)
{
for(int i = index;i<History;i++)
{
if(SuperTrendRedToGreen(i))
{
return i;
}
}
return -1;
}
//+——————————————————————+
//| |
//+——————————————————————+
//+——————————————————————+
//| |
//+——————————————————————+
bool LabelCreate(const string name,const int x, const int y,const color clr,const int font_size)
{
const long chart_ID=0;
const int sub_window=0;
const ENUM_BASE_CORNER corner=CORNER_RIGHT_UPPER;
const string text=”Label”;
const string font=”Arial”;
const double angle=0.0;
const ENUM_ANCHOR_POINT anchor=ANCHOR_RIGHT_LOWER;
const bool back=false;
const bool selection=false;
const bool hidden=true;
const long z_order=0;
ObjectDelete(chart_ID,name);
ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0);
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
return(true);
}
//+——————————————————————+
//| |
//+——————————————————————+
bool LabelDelete(long chart_ID, // chart’s ID
string name) // label name
{
//— reset the error value
ResetLastError();
//— delete the label
if(!ObjectDelete(chart_ID,name))
{
Print(__FUNCTION__,
“: failed to delete a text label! Error code = “,GetLastError());
return(false);
}
//— successful execution
return(true);
}
//+——————————————————————+
//| |
//+——————————————————————+
void LabelUpdate(string labelname,string labeltext)
{
string label = labeltext;
ObjectSetString(0,labelname,OBJPROP_TEXT,label);
}
Buongiorno. Potrei provare a tradurre il tuo codice, ma ho bisogno che tu fornisca anche alcuni screenshot dei risultati dell'indicatore. Come appare sul grafico?
Buongiorno, l’indicatore non ha una finestra dedicata, per sapere se è a grafico viene visualizzata la data odierna in verde. Invece i segnali sono rappresentati da delle semplici frecce per indicare buy o sell ma in realtà sono una comodità la cosa più importante sono le notifiche. Allego uno screen, grazie mille per l’aiuto
Hola qui hai il codice tradotto:
//--------------------------------------------------------------//
//PRC_SuperTrend Williams Filter
//version = 0
//03.09.2024
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//--------------------------------------------------------------//
//-----Inputs---------------------------------------------------//
//--------------------------------------------------------------//
//--Supertrend
STperiod=10
STmulti=3
//--Williams %
Wperiod=140
Wob=-20
Wos=-80
Wmd=-50
//--Drawing settings
signalsCase1=1
signalsCase2=1
//--------------------------------------------------------------//
//-----SuperTrend-----------------------------------------------//
//--------------------------------------------------------------//
ST=Supertrend[STmulti,STperiod]
if ST > close then
r=255
g=0
SuperTrendBearish = 1
SuperTrendBullish = 0
else
r=0
g=255
SuperTrendBearish = 0
SuperTrendBullish = 1
endif
//--------------------------------------------------------------//
//-----Williams %-----------------------------------------------//
//--------------------------------------------------------------//
Will=Williams[Wperiod](close)
//--------------------------------------------------------------//
//-----Trading Signals------------------------------------------//
//--------------------------------------------------------------//
//--Buy Signal (Case 1)
if signalsCase1 and Will crosses over Wos and SuperTrendBullish then
drawarrowup(barindex,low-0.35*tr)coloured("lightgreen")
endif
//--Sell Signal (Case 1)
if signalsCase1 and Will crosses under Wob and SuperTrendBearish then
drawarrowdown(barindex,high+0.35*tr)coloured("red")
endif
//--Buy Signal (Case 2)
if signalsCase2 and SuperTrendBearish[1] and SuperTrendBullish and Will > Wmd then
drawarrowup(barindex,low-0.35*tr)coloured("lightblue")
endif
//--Sell Signal (Case 2)
if signalsCase2 and SuperTrendBullish[1] and SuperTrendBearish and Will < Wmd then
drawarrowdown(barindex,high+0.35*tr)coloured("orange")
endif
//--------------------------------------------------------------//
return ST as "SuperTrend" coloured(r,g,0)
Grazie mille Ivan per la risposta, però l’indicatore non funziona mi mette frecce un po’ ovunque. Quello che dovrebbe succedere è questo per un possibile bearish, per il bullish è identico ma opposto:
In teoria poi i diversi timeframe dovrebbero essere intercambiabili, dovrei essere in grado di vedere le stesse cose ma al posto di m1 e m5 dovrei poter usare 100tik e 1 min ad esempio.
Mi rendo conto che è un bel lavoro da fare quindi se non dovesse essere possibile farlo grazie comunque per l’impegno.
Ok. Non è quello che avevo capito dal codice in MT4 (non sono un esperto di MetaTrader…), però ho programmato la tua spiegazione, anche se ho qualche dubbio di averla compresa bene. Ecco il codice.
//--------------------------------------------------------------//
//PRC_SuperTrend Williams Filter
//version = 0
//03.09.2024
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//--------------------------------------------------------------//
//-----Inputs---------------------------------------------------//
//--------------------------------------------------------------//
//--Supertrend
STperiod=10
STmulti=3
//--Williams %
WperiodM5=140
WperiodM1=14
Wob=-20
Wos=-80
Wmd=-50
//--Drawing settings
signalsCase1=1
signalsCase2=1
//--------------------------------------------------------------//
//-----SuperTrend-----------------------------------------------//
//--------------------------------------------------------------//
TIMEFRAME(5mn,updateonclose)
ST=Supertrend[STmulti,STperiod]
if ST > close then
r=255
g=0
SuperTrendBearish = 1
SuperTrendBullish = 0
else
r=0
g=255
SuperTrendBearish = 0
SuperTrendBullish = 1
endif
//--------------------------------------------------------------//
//-----Williams %-----------------------------------------------//
//--------------------------------------------------------------//
WillM5 = Williams[WperiodM5](close)
// Detectar condiciones de sobrecompra/sobreventa en M5
WillM5ipc = (WillM5 > Wob) // Zona sobrecompra
WillM5ipv = (WillM5 < Wos) // Zona sobreventa
timeframe(1mn)
WillM1 = Williams[WperiodM1](close)
//--------------------------------------------------------------//
//-----Trading Signals------------------------------------------//
//--------------------------------------------------------------//
//--Buy Signal
if signalsCase1 and SuperTrendBullish and WillM5 < Wos and WillM1 > Wmd and checkinglong=0 then
checkinglong=1
endif
if checkinglong and ((SuperTrendBullish[1] and SuperTrendBearish) or WillM1 crosses under Wos )then
checkinglong=0
drawarrowup(barindex,low-0.35*tr)coloured("lightgreen")
elsif checkinglong and WillM5 > Wob then
checkinglong=0
endif
//--Sell Signal
if signalsCase1 and SuperTrendBearish and WillM5 > Wob and WillM1 < Wmd and checkingshort=0 then
checkingshort=1
endif
if checkingshort and ((SuperTrendBullish and SuperTrendBearish[1]) or WillM1 crosses over Wob) then
checkingshort=0
drawarrowdown(barindex,high+0.35*tr)coloured("orange")
elsif checkingshort and WillM5 < Wos then
checkingshort=0
endif
//--------------------------------------------------------------//
return ST as "SuperTrend" coloured(r,g,0)
Descrizione del codice:
Inputs: Si definiscono i parametri principali del SuperTrend (periodo e moltiplicatore) e del Williams %R per i timeframe di 5 minuti (M5) e 1 minuto (M1). Vengono anche impostati i livelli di ipercomprato, ipervenduto e livello medio per Williams %R.
Calcolo del SuperTrend: Si calcola il SuperTrend sul timeframe di 5 minuti (M5) e si stabilisce se la tendenza è rialzista (verde) o ribassista (rossa) basandosi sulla posizione rispetto al prezzo di chiusura.
Calcolo del Williams %R: Si calcola il Williams %R sul timeframe di 5 minuti per identificare se il mercato si trova in ipercomprato o ipervenduto. Successivamente, si calcola anche il Williams %R per il timeframe di 1 minuto per raffinare i segnali di trading.
Segnali di trading (Case 1):
Segnale di acquisto: Se il SuperTrend è rialzista e il Williams %R in M5 è in ipervenduto, mentre quello in M1 è sopra il livello medio, si attiva lo stato di “checkinglong”. Successivamente, se il SuperTrend passa da rialzista a ribassista o il Williams %R in M1 scende sotto il livello di ipervenduto, viene disegnata una freccia di acquisto (verde).
Segnale di vendita: Se il SuperTrend è ribassista e il Williams %R in M5 è in ipercomprato, mentre quello in M1 è sotto il livello medio, si attiva lo stato di “checkingshort”. Successivamente, se il SuperTrend passa da ribassista a rialzista o il Williams %R in M1 supera il livello di ipercomprato, viene disegnata una freccia di vendita (arancione).
Buongiorno Ivan, ho risposto qualche giorno fa al tuo messaggio ma non so perchè la risposta è stata cancellata.
Volevo dirti che l’indicatore non funziona ancora bene e vorrei spiegartelo nel dettaglio. Prima cosa per semplificare di più il codice i tf di riferimento devono essere M1 e 100tik. In secondo luogo l’indicatore dovrebbe mandare in output una variabile “risultato” che cambia di valore tra 0 e 1 in modo tale che posso metterci un allarme che mi avvisa quando c’è un segnale (le frecce non servono solo utili solo su metatrader ma la notifica è più che sufficiente).
Il procedimento che il codice deve fare per un’entrata long è questo:
Allego anche un pdf dove spiego con delle immagini una possibile entrata short in modo da essere il più chiaro possibile
Grazie mille per il tuo impegno e per l’aiuto
Trascrizione indicatore da MQL4 a PROREALCODE
This topic contains 6 replies,
has 2 voices, and was last updated by RubbinRubbin02
1 year, 5 months ago.
| Forum: | ProBuilder: Indicatori & Strumenti Personalizzati |
| Language: | Italian |
| Started: | 08/30/2024 |
| Status: | Active |
| Attachments: | 2 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.