#property link "madebykalabster@yandex.ru"
//----
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Gold
#property indicator_color4 Aqua
//---- buffers
double P1Buffer[];
double P2Buffer[];
double P3Buffer[];
double P4Buffer[];
//----
double PP, Q;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0, P1Buffer);
SetIndexBuffer(1, P2Buffer);
SetIndexBuffer(2, P3Buffer);
SetIndexBuffer(3, P4Buffer);
//----
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2);
SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 2);
//----
Comment("Waddah Attar Pivot");
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("DayP");
ObjectDelete("WeekP");
ObjectDelete("MonthP");
ObjectDelete("H4");
ObjectDelete("txtDayP");
ObjectDelete("txtWeekP");
ObjectDelete("txtMonthP");
ObjectDelete("txtH4");
Comment("");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i, dayi, counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0)
return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0)
counted_bars--;
int limit = Bars - counted_bars;
//----
for(i = limit - 1; i >= 0; i--)
{
//H4 PIVOT
dayi = iBarShift(Symbol(), PERIOD_H4, Time[i], false);
Q = (iHigh(Symbol(), PERIOD_H4,dayi + 1) - iLow(Symbol(), PERIOD_H4, dayi + 1));
PP = (iHigh(Symbol(), PERIOD_H4, dayi + 1) + iLow(Symbol(), PERIOD_H4, dayi + 1) + iClose(Symbol(), PERIOD_H4, dayi + 1)) / 3;
P4Buffer[i] = PP;
SetPrice("H4", Time[i], PP, indicator_color4);
SetText("txtH4", "H4 Pivot", Time[i], PP, indicator_color4);
//DAY PIVOT
dayi = iBarShift(Symbol(), PERIOD_D1, Time[i], false);
Q = (iHigh(Symbol(), PERIOD_D1,dayi + 1) - iLow(Symbol(), PERIOD_D1, dayi + 1));
PP = (iHigh(Symbol(), PERIOD_D1, dayi + 1) + iLow(Symbol(), PERIOD_D1, dayi + 1) + iClose(Symbol(), PERIOD_D1, dayi + 1)) / 3;
P1Buffer[i] = PP;
SetPrice("DayP", Time[i], PP, indicator_color1);
SetText("txtDayP", "Day Pivot", Time[i], PP, indicator_color1);
//WEEKLY PIVOT
dayi = iBarShift(Symbol(), PERIOD_W1, Time[i], false);
Q = (iHigh(Symbol(), PERIOD_W1,dayi + 1) - iLow(Symbol(), PERIOD_W1, dayi + 1));
PP = (iHigh(Symbol(), PERIOD_W1, dayi + 1) + iLow(Symbol(), PERIOD_W1, dayi + 1) + iClose(Symbol(), PERIOD_W1, dayi + 1)) / 3;
P2Buffer[i] = PP;
SetPrice("WeekP", Time[i], PP, indicator_color2);
SetText("txtWeekP", "Week Pivot", Time[i], PP, indicator_color2);
//MONTHLY PIVOT
dayi = iBarShift(Symbol(), PERIOD_MN1, Time[i], false);
Q = (iHigh(Symbol(), PERIOD_MN1,dayi + 1) - iLow(Symbol(), PERIOD_MN1, dayi + 1));
PP = (iHigh(Symbol(), PERIOD_MN1, dayi + 1) + iLow(Symbol(), PERIOD_MN1, dayi + 1) + iClose(Symbol(), PERIOD_MN1, dayi + 1)) / 3;
P3Buffer[i] = PP;
SetPrice("MonthP", Time[i], PP, indicator_color3);
SetText("txtMonthP", "Month Pivot", Time[i], PP, indicator_color3);
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void SetPrice(string name, datetime Tm, double Prc, color clr)
{
if(ObjectFind(name) == -1)
{
ObjectCreate(name, OBJ_ARROW, 0, Tm, Prc);
ObjectSet(name, OBJPROP_COLOR, clr);
ObjectSet(name, OBJPROP_WIDTH, 1);
ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
}
else
{
ObjectSet(name, OBJPROP_TIME1, Tm);
ObjectSet(name, OBJPROP_PRICE1, Prc);
ObjectSet(name, OBJPROP_COLOR, clr);
ObjectSet(name, OBJPROP_WIDTH, 1);
ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void SetText(string name, string txt, datetime Tm, double Prc, color clr)
{
if(ObjectFind(name) == -1)
{
ObjectCreate(name, OBJ_TEXT, 0, Tm, Prc);
ObjectSetText(name, txt, 10, "Times New Roman", clr);
ObjectSet(name, OBJPROP_CORNER, 2);
}
else
{
ObjectSet(name, OBJPROP_TIME1, Tm);
ObjectSet(name, OBJPROP_PRICE1, Prc);
ObjectSetText(name, txt, 10, "Times New Roman", clr);
ObjectSet(name, OBJPROP_CORNER, 2);
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Custom.mq4 |
//| Copyright 2019, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 2; // увеличение лота
extern bool FLAG1 = true; // переключатель
extern double MaxLot = 5; // максимальный лот
extern double Level = 4; // уровень
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int Slip = 30; // реквот
extern int Shift = 0; // на каком баре сигнал индикатора
extern int Magic = 123; // магик
extern string Expiration = "15";
extern bool Reverse = 0;
extern string IndName="VCustom3";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,Expiration,Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int Loss()
{
int loss=0;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0)
{
if(OrderClosePrice()-OrderOpenPrice()<0) loss++;
if(OrderClosePrice()-OrderOpenPrice()>0) break;
}
if(OrderType()==1)
{
if(OrderClosePrice()-OrderOpenPrice()>0) loss++;
if(OrderClosePrice()-OrderOpenPrice()<0) break;
}
}
}
}
return(loss);
}
//--------------------------------------------------------------------
int Poss()
{
int loss=0;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0)
{
if(OrderClosePrice()-OrderOpenPrice()>0) loss++;
if(OrderClosePrice()-OrderOpenPrice()<0) break;
}
if(OrderType()==1)
{
if(OrderClosePrice()-OrderOpenPrice()<0) loss++;
if(OrderClosePrice()-OrderOpenPrice()>0) break;
}
}
}
}
return(loss);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot;
if(FLAG1 == true)
{
lot=NormalizeDouble(Lots*MathPow(KLot,Loss()),2);
}
else lot=NormalizeDouble(Lots*MathPow(KLot,Poss()),2);
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double ind1=iCustom(NULL,0,IndName,3,Shift);
double ind2=iCustom(NULL,0,IndName,3,Shift+1);
if(CountTrades()<1 && !Reverse)
{
if(ind1>Level && ind2<Level) PutOrder(0,Ask);
if(ind1<-Level && ind2>-Level) PutOrder(1,Bid);
}
if(CountTrades()<1 && Reverse)
{
if(ind1<-Level && ind2>-Level) PutOrder(0,Ask);
if(ind1>Level && ind2<Level) PutOrder(1,Bid);
}
Comment("\n Losses: ",Loss(), "\n Posses: ",Poss(),
"\n Ind: ",ind1);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| индикатор направления Тренда |
//| Зотов ИВ zot@pisem.net |
//+------------------------------------------------------------------+
#property copyright "zot@pisem.net"
#property link "zot@pisem.net"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Red
//---- input parameters
extern int period=34;
extern int method=3; // MODE_SMA
extern int price=0; // PRICE_CLOSE
//---- buffers
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];
double Buy[],Sel[]; //стрелочки
bool UP = true;
bool DN = true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(5);
SetIndexBuffer(0, Uptrend); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,clrGreen);//ArraySetAsSeries(Uptrend, true);
SetIndexBuffer(1, Dntrend); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,clrRed);//ArraySetAsSeries(Dntrend, true);
SetIndexBuffer(2, Buy); SetIndexStyle(2,DRAW_ARROW,EMPTY,1,clrGreen); SetIndexArrow(2,233); SetIndexEmptyValue(2,0.0); //strelka vverh Buy[i]= Low[i]-10*Point;
SetIndexBuffer(3, Sel); SetIndexStyle(3,DRAW_ARROW,EMPTY,1,clrRed ); SetIndexArrow(3,234); SetIndexEmptyValue(3,0.0); //strelka vniz Sel[i]= High[i]+10*Point;
SetIndexBuffer(4, ExtMapBuffer);
ArraySetAsSeries(ExtMapBuffer, true);
IndicatorShortName("Trend("+period+")");
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
double WMA(int x, int p)
{
return(iMA(NULL, 0, p, 0, method, price, x));
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
if(counted_bars < 0)
return(-1);
int x = 0;
int p = MathSqrt(period);
int e = Bars - counted_bars + period + 1;
double vect[], trend[];
if(e > Bars)
e = Bars;
ArrayResize(vect, e);
ArraySetAsSeries(vect, true);
ArrayResize(trend, e);
ArraySetAsSeries(trend, true);
for(x = 0; x < e; x++)
{
vect[x] = 2*WMA(x, period) - WMA(x, period);
//Print("Bar date/time: ", TimeToStr(Time[x]), " close: ", Close[x], " vect[", x, "] = ", vect[x], " 2*WMA(p/2) = ", 2*WMA(x, period/2), " WMA(p) = ", WMA(x, period));
}
for(x = 0; x < e-period; x++)
ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x);
for(x = e-period; x >= 0; x--)
{
trend[x] = trend[x+1];
if (ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1;
if (ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1;
if (trend[x]>0)
{
Uptrend[x] = ExtMapBuffer[x];
if (UP == true)
{
Buy[x]= Low[x]-10*Point; UP = false; DN = true;
}
if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
Dntrend[x] = EMPTY_VALUE;
}
else
if (trend[x]<0)
{
Dntrend[x] = ExtMapBuffer[x];
if (DN == true)
{
Sel[x]= High[x]+10*Point; DN = false; UP = true;
}
if (trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
Uptrend[x] = EMPTY_VALUE;
}
//Print( " trend=",trend[x]);
}
return(0);
}
//+------------------------------------------------------------------+
kalabster