1)свеча закрылась под каналом
2) heiken_ashi красного цвета (сигнализирует о продаже)
3)предыдущая свеча была синего цвета (heiken_ashi) или внутри канала/над каналом (trend risk)
double sl=0,tp=0;
double open=iOpen(NULL,0,1);
double close=iClose(NULL,0,1);
double Ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);
CopyBuffer(RiskHandle,0,1,1,up);
CopyBuffer(RiskHandle,1,1,1,dn);
CopyBuffer(HAHandle,0,1,1,op);
CopyBuffer(HAHandle,3,1,1,cl);
if(PositionsTotal()<1 && bars!=Bars(NULL,0))
{
if(close>up[0] && open<up[0] && cl[0]>op[0])
{
sl=NormalizeDouble(Bid-Stop*_Point,_Digits);
tp=NormalizeDouble(Bid+Take*_Point,_Digits);
trade.PositionOpen(_Symbol,0,Lot(),Ask,sl,tp);
}
if(close<dn[0] && open>dn[0] && cl[0]<op[0])
{
sl=NormalizeDouble(Ask+Stop*_Point,_Digits);
tp=NormalizeDouble(Ask-Take*_Point,_Digits);
trade.PositionOpen(_Symbol,1,Lot(),Bid,sl,tp);
}
bars=Bars(NULL,0);
}
//+------------------------------------------------------------------+
//| |
//| Auto trend forecaster.mq4 |
//| |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 DodgerBlue
#property indicator_color2 OrangeRed
extern int TMperiod = 26;
extern double Intensity = 1.9;
extern int SL_distance_pips = 200;
int metod = MODE_SMMA;
int price = PRICE_LOW;
double blu[];
double red[];
double prev[];
double up[];
double dn[];
datetime t;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DisplayAlert(string as_0, double ad_8, double ad_16, double ad_24)
{
string ls_32;
string ls_40;
string ls_48;
if(Time[0] != t)
{
t = Time[0];
if(ad_24 != 0.0)
ls_48 = "Price " + DoubleToStr(ad_24, 4);
else
ls_48 = "";
if(ad_8 != 0.0)
ls_40 = ", TakeProfit " + DoubleToStr(ad_8, 4);
else
ls_40 = "";
if(ad_16 != 0.0)
ls_32 = ", StopLoss " + DoubleToStr(ad_16, 4);
else
ls_32 = "";
Alert("Auto TREND " + as_0 + ls_48 + ls_40 + ls_32 + " ", Symbol(), ", ", Period(), " min");
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
int li_0;
if(TMperiod == 8)
li_0 = 2;
else
li_0 = 4;
IndicatorBuffers(3);
string ls_4 = "(" + TMperiod + ")";
SetIndexBuffer(0, blu);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, li_0);
SetIndexLabel(0, "" + ls_4);
SetIndexBuffer(1, red);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, li_0);
SetIndexLabel(1, "" + ls_4);
SetIndexBuffer(2, prev);
ArraySetAsSeries(prev, TRUE);
SetIndexStyle(3,DRAW_ARROW,0,3,Blue);
SetIndexArrow(3,108);
SetIndexBuffer(3,up);
SetIndexStyle(4,DRAW_ARROW,0,3,Red);
SetIndexArrow(4,108);
SetIndexBuffer(4,dn);
IndicatorShortName("AUTO TREND FORECASTER");
IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS) + 1.0);
return (0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
return (0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double WMA(int ai_0, int a_period_4)
{
return (iMA(NULL, 0, a_period_4, 0, metod, price, ai_0));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double lda_20[];
double lda_24[];
double ld_36;
int l_ind_counted_0 = IndicatorCounted();
if(l_ind_counted_0 < 0)
return (-1);
int i = 1;
int l_period_8 = MathFloor(MathSqrt(TMperiod));
int li_12 = MathFloor(TMperiod / Intensity);
int li_16 = Bars - l_ind_counted_0 + TMperiod + 1;
if(li_16 > Bars)
li_16 = Bars;
ArraySetAsSeries(lda_20, TRUE);
ArrayResize(lda_20, li_16);
ArraySetAsSeries(lda_24, TRUE);
ArrayResize(lda_24, li_16);
double ld_28 = Close[1];
for(i = 0; i < li_16; i++)
lda_20[i] = 2.0 * WMA(i, li_12) - WMA(i, TMperiod);
for(i = 0; i < li_16 - TMperiod; i++)
prev[i] = iMAOnArray(lda_20, 0, l_period_8, 0, metod, i);
for(i = li_16 - TMperiod; i > 0; i--)
{
lda_24[i] = lda_24[i + 1];
if(prev[i] > prev[i + 1])
lda_24[i] = 1;
if(prev[i] < prev[i + 1])
lda_24[i] = -1;
if(lda_24[i] > 0.0)
{
blu[i] = prev[i];
if(lda_24[i + 1] < 0.0)
blu[i + 1] = prev[i + 1];
if(lda_24[i + 1] < 0.0)
{
if(i == 1)
{
ld_36 = ld_28 - SL_distance_pips * Point;
DisplayAlert("UP Buy ", 0, ld_36, ld_28);
up[i]=ld_36;
}
}
red[i] = EMPTY_VALUE;
}
else
{
if(lda_24[i] < 0.0)
{
red[i] = prev[i];
if(lda_24[i + 1] > 0.0)
red[i + 1] = prev[i + 1];
if(lda_24[i + 1] > 0.0)
{
if(i == 1)
{
ld_36 = ld_28 + SL_distance_pips * Point;
DisplayAlert("DOWN Sell ", 0, ld_36, ld_28);
dn[i]=ld_36;
}
}
blu[i] = EMPTY_VALUE;
}
}
}
Comment("\n UP: ",up[7]);
return (0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Charts.mq5 |
//| Copyright 2020, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property indicator_chart_window
#property indicator_plots 0
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
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[])
{
//---
double pr=0,p1=0,p2=0;
datetime t1=0,t2=0;
string nm="",sm="";
for(int i=0; i<ObjectsTotal(0,-1); i++)
{
if(ObjectGetInteger(0,ObjectName(0,i),OBJPROP_TYPE)==OBJ_HLINE)
{
nm=ObjectName(0,i);
pr=ObjectGetDouble(0,ObjectName(0,i),OBJPROP_PRICE);
sm=_Symbol;
Print("\n Name: ",nm);
Print("Price: ",pr);
Print("Symbol: ",sm);
}
}
int k=0;
long curr=0,prev=ChartFirst();
while(k<33)
{
curr=ChartNext(prev);
if(curr<0)
break;
if(nm!="" && ChartSymbol(curr)==sm)
{
ObjectCreate(curr,nm,OBJ_HLINE,0,0,NormalizeDouble(pr,_Digits));
}
prev=curr;
k++;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
p1=ObjectGetDouble(0,ObjectName(0,i),OBJPROP_PRICE1);
wpr1<-70 && wpr2>-70
2. цена при достижении которой надо закрыть
3. цена куда перенести стоп-лосс
AM2