test_group/ba/new/helper/helper.mq5

1049 lines
72 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:31:23 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| helper.mq5 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
#property tester_everytick_calculate ;
double Bid,Ask;
#include<Trade\Trade.mqh>
#include <ChartObjects\ChartObjectsShapes.mqh>
#include <Arrays\ArrayDouble.mqh>
CChartObjectRectangle rect;
CTrade trade;
enum sell_or_buy1
{
sell,// ?@>40BL
buy, // :C?8BL
all // >10
};
enum stops
{
red,// red
blue, // blue
fractal // fractal
};
class CDynamicArray
{
private:
int m_ChunkSize; // 07<5@ 1;>:0
int m_ReservedSize; // 50;L=K9 @07<5@ <0AA820
int m_Size; // >;8G5AB2> 70=OBKE M;5<5=B>2 <0AA820
public:
double Element[]; // !>1AB25==> <0AA82. 0E>48BAO 2 A5:F88 public,
// GB>1K 2 A;CG05 =5>1E>48<>AB8 @01>B0BL A =8< =0?@O<CN
//+------------------------------------------------------------------+
//| >=AB@C:B>@ |
//+------------------------------------------------------------------+
void CDynamicArray(int ChunkSize=1024)
{
m_Size=0; // >;8G5AB2> 70=OBKE M;5<5=B>2
m_ChunkSize=ChunkSize; // 07<5@ 1;>:0
m_ReservedSize=ChunkSize; // 50;L=K9 @07<5@ <0AA820
ArrayResize(Element,m_ReservedSize); // >43>B>2:0 <0AA820
}
//+------------------------------------------------------------------+
//| $C=:F8O 4>102;5=8O 2 :>=5F <0AA820 |
//+------------------------------------------------------------------+
void AddValue(double Value)
{
// #25;8G5=85 :>;8G5AB20 70=OBKE M;5<5=B>2
if(m_Size>m_ReservedSize)
{ // "@51C5<>5 :>;8G5AB2> 1>;LH5 @50;L=>3> @07<5@0 <0AA820
m_ReservedSize+=m_ChunkSize; // 0AAG8BK205< =>2K9 @07<5@ <0AA820
ArrayResize(Element,m_ReservedSize); // #25;8G8205< @50;L=K9 @07<5@ <0AA820
}
// Print("m"+ArrayBsearch(Element,Value));
if(ArrayBsearch(Element,Value)<0){m_Size++;
Element[m_Size-1]=n(Value); // >102;O5< 7=0G5=85
}
}
//+------------------------------------------------------------------+
//| $C=:F8O ?>;CG5=8O :>;8G5AB20 70=OBKE M;5<5=B>2 <0AA820 |
//+------------------------------------------------------------------+
int Size()
{
return(m_Size);
}
string Pri(){
string str="";
for(int i=0;i<m_Size;i++)str+="|"+i+"-"+Element[i];
return str;
}
};
//CDynamicArray val_st,val_tp;
input double koof=0.00314; // :>>D
input double testlot=0.0314;
input bool auto=false;
input sell_or_buy1 s_o_b=all; // ?>8A: A45;>:
input stops use_stop=fractal;
input sell_or_buy1 line_s_o_b=all;
input ENUM_TIMEFRAMES open_frame=PERIOD_H1; //blue
input ENUM_TIMEFRAMES open_frame_min=PERIOD_M1;
input ENUM_TIMEFRAMES stop_frame=PERIOD_M5;
input bool use_line=false;
input bool use_zone=false;
input bool use_max_lost=false;
input int max_lost=3;
input int stop_fr=1;
input string line_name="top_arr_h1";
input double usdrub=73.95;
input double next_risk=0.5;
bool want_new=true;
string now_trend="null";
bool is_open=false;
double inp[4]; // <0AA82 4;O E@0=5=8O 2E>4=KE A83=0;>2
double we[4];
double we_st[11], we_tp[11];
double last_max,last_min;
int last_max_point,last_min_point;
//double val_st[1], val_tp[1];
CArrayDouble val_st,val_tp;
int OnInit()
{
//---
EventSetTimer(2);
/*if(iOpen(NULL,PERIOD_H4,1)>get_fraktal_price(PERIOD_M5,0,1))
now_trend="sell";
else now_trend="buy";
*/
int i=0;
for(i=0;i<ArraySize(we);i++){we[i]=0.5;}
for(i=0;i<ArraySize(we_st);i++){we_st[i]=0.5;we_tp[i]=0.5;}
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
want_new=true;
//get_fraktal(PERIOD_CURRENT,1,7);
//get_fraktal(PERIOD_CURRENT,0,7);
long buy_id,sell_id;
ulong ticket;
//string type;
uint total=PositionsTotal();
int order_buy_c=0,order_buy_stop=0;
int order_sell_c=0,order_sell_stop=0;
double buylot=0,selllot=0,buy_oprice=0,sell_oprice=0,stopprice=0,allprofit=0,all_sl=0,all_tp=0;
int is_stop=0;
bool open=true;
double last_portal_niz=get_fraktal_price(stop_frame,1,stop_fr)-20*_Point;
double last2_top=get_fraktal_price(stop_frame,0,stop_fr)+(SymbolInfoInteger(_Symbol,SYMBOL_SPREAD)+20)*_Point;
int handle=iIchimoku(NULL,stop_frame,9,26,52);
// int handle=iIchimoku(NULL,PERIOD_CURRENT,9,26,52);
double red1[],blue1[],span_a[],span_b[];
if(CopyBuffer(handle,0,0,3,red1)<=0)
return;
ArraySetAsSeries(red1,true);
if(CopyBuffer(handle,1,0,3,blue1)<=0)
return;
ArraySetAsSeries(blue1,true);
if(CopyBuffer(handle,2,0,3,span_a)<=0)
return;
ArraySetAsSeries(span_a,true);
if(CopyBuffer(handle,3,0,3,span_b)<=0)
return;
ArraySetAsSeries(span_b,true);
inp[0]=check_res(red1[0]);
inp[1]=check_res(blue1[0]);
inp[2]=check_res(span_a[0]);
inp[3]=check_res(span_b[0]);
double nero;
double nero_val=Nero_analys(PERIOD_CURRENT);
nero=CalculateNeuron(inp,we);
if(use_stop!=fractal){
// Alert(DoubleToString(inp[1]));
if(use_stop==red){last_portal_niz=red1[0]-20*_Point;last2_top=red1[0]+(SymbolInfoInteger(_Symbol,SYMBOL_SPREAD)+20)*_Point;}
if(use_stop==blue){last_portal_niz=blue1[0]-20*_Point;last2_top=blue1[0]+(SymbolInfoInteger(_Symbol,SYMBOL_SPREAD)+20)*_Point;}
}
//Alert(total);
//--- 1 ?>8A: A45;>:
for(uint i=0; i<total; i++)
{
//--- ?>;CG8< B8:5B >@45@0 ?> 53> ?>78F88 2 A?8A:5
if((ticket=PositionGetTicket(i))>0)
{
//--- ?>;CG8< A2>9AB20 >@45@0
// type =EnumToString(ENUM_ORDER_TYPE(OrderGetInteger(ORDER_TYPE)));
//--- ?>43>B>28< 8 2K2545< 8=D>@<0F8N >1 >@45@5
// Alert(PositionGetInteger(POSITION_TYPE));
if(PositionGetString(POSITION_SYMBOL)==_Symbol)
{
allprofit+=PositionGetDouble(POSITION_PROFIT);
double open_price=PositionGetDouble(POSITION_PRICE_OPEN);
double stop=PositionGetDouble(POSITION_SL);
int id=PositionGetInteger(POSITION_IDENTIFIER);
if(PositionGetInteger(POSITION_TYPE)==1)
{
order_sell_c++;
all_sl+=find_price(open_price,stop,PositionGetDouble(POSITION_VOLUME),"sl");
stopprice+=PositionGetDouble(POSITION_VOLUME)*(stop-open_price)/_Point;
selllot+=PositionGetDouble(POSITION_VOLUME);
want_new=false;
if(last2_top<stop
//&& last2_top<open_price
)
{
if(trade.PositionModify(id,last2_top,PositionGetDouble(POSITION_TP)))
want_new=true;
//---
}
if(stop<open_price)
order_sell_stop++;
}
else
{
order_buy_c++;
all_sl+=find_price(stop,open_price,PositionGetDouble(POSITION_VOLUME),"sl","buy");
stopprice+=PositionGetDouble(POSITION_VOLUME)*(open_price-stop)/_Point;
buylot+=PositionGetDouble(POSITION_VOLUME);
want_new=false;
if(last_portal_niz>stop
// && last_portal_niz>open_price
)
{
trade.PositionModify(id,last_portal_niz,PositionGetDouble(POSITION_TP));
//want_new=true;
}
if(stop>open_price)
order_buy_stop++;
}
}
}
}
Bid=SymbolInfoDouble(NULL,SYMBOL_BID);
Ask=SymbolInfoDouble(NULL,SYMBOL_ASK);
make_fraktal("h1",PERIOD_H1,clrAqua,3);
make_fraktal("m5",PERIOD_M5,clrDarkOrange,1);
make_fraktal("m1",PERIOD_M1,clrYellow,1);
make_fraktal("d1",PERIOD_D1,clrDarkGray,4);
double l_top,l_bot;
l_top=iHigh(_Symbol,PERIOD_D1,1);
l_bot=iLow(_Symbol,PERIOD_D1,1);
if(SymbolInfoDouble(_Symbol,SYMBOL_ASKHIGH)>l_top)
l_top=SymbolInfoDouble(_Symbol,SYMBOL_ASKHIGH);
if(l_bot>SymbolInfoDouble(_Symbol,SYMBOL_BIDLOW))
l_bot=SymbolInfoDouble(_Symbol,SYMBOL_BIDLOW);
double l_top2=l_top;
double l_bot2=l_bot;
if(iOpen(_Symbol,PERIOD_D1,1)<iClose(_Symbol,PERIOD_D1,1))
{
l_top2=l_bot;
l_bot2=l_top;
// n236=t236;
}
ObjectDelete(0,"fib");
//stop_price
int all_orders=order_sell_c+order_buy_c;
if((order_sell_stop==order_sell_c && order_buy_c==0)
|| (order_buy_stop==order_buy_c && order_sell_c==0)
)
{
string last_ord="null";
if(order_sell_c>0)
last_ord="sell";
if(order_buy_c>0)
last_ord="buy";
// 5ABL ;8 A45;:8 4>?>:C?:0
if(all_orders>0){
if(last_ord!="null"){
// if(find_open_add(PERIOD_M1)!="null" && find_open_add(PERIOD_M1)==last_ord)open_order(find_open_add(PERIOD_M1),"add",1);
//1 - niz fraktal 0-vverh
string f_line=find_open_line("s_o_b",PERIOD_M1,PERIOD_M1);
string first=find_open_first(PERIOD_M1);
string f_open=find_open(PERIOD_M1);
string f_line_bok=find_open_line("m5");
if(f_line_bok!="null" && f_line_bok==last_ord)open_order(f_line_bok,"bokline",2,all_sl);
if(f_line!="null" && f_line==last_ord)open_order(f_line,"l1_"+find_open_line("com",1,1),2,all_sl);
if(f_open!="null" && f_open==last_ord)open_order(f_open,"main",2,all_sl);
if(first!="null" && first==last_ord)open_order(first,"ladd1",2,all_sl);
string f_fr=find_open_fraktal(open_frame_min);
if(f_fr!="null" && f_fr==last_ord)open_order(f_fr,"a_fr_"+EnumToString(open_frame_min),2,all_sl);
}
}else{
if(auto==true){
string fr_ooo=find_open_change(PERIOD_M1);
if(fr_ooo!="null"){open_order(fr_ooo,"n_ooo");}
/* string f_fr=find_open_fraktal(open_frame_min);
if(f_fr!="null" && f_fr==now_trend)open_order(f_fr,"lfr_"+EnumToString(open_frame_min),1);
string f_line=find_open_line("s_o_b",PERIOD_M5,PERIOD_M5);
if(f_line!="null" && f_line==now_trend)open_order(f_line,"lf5_"+find_open_line("com"),1);
string find_o=find_open(PERIOD_M5);
if(find_o!="null" && find_o==now_trend)open_order(find_o,"new_open",1);
*/
/*
if(find_open(open_frame)!="null")
open_order(find_open(open_frame),"main_h"+EnumToString(open_frame));
if(find_open_first(PERIOD_M1)!="null")
open_order(find_open(PERIOD_M1),"first1");
if(find_open(PERIOD_M1)!="null")
open_order(find_open(PERIOD_M1),"main1");
if(find_open_add(PERIOD_M1)!="null")
open_order(find_open_add(PERIOD_M1),"add1");
if(find_open_add(PERIOD_M5)!="null")
open_order(find_open_add(PERIOD_M5),"add_m5");
*/
}
}
}
if(line_s_o_b!=all){
if(find_open(open_frame)==find_open(open_frame_min))open_order(find_open(open_frame),"nn"+find_open(open_frame));
}
ObjectCreate(0,"fib",OBJ_FIBO,0,iTime(NULL,PERIOD_D1,1),l_bot2,TimeCurrent(),l_top2);
double testlot2
=make_lot("buy");
double sl=find_price(Bid,stop_price("buy"),testlot2,"sl","buy");
double tp=find_price(Bid,l_top,testlot2);
string st=n(nero_val)+"|"+n(nero_alltime())+"|"+n(all_sl)+";""l"+testlot2+";sl="+n(sl)+";tp="+n(tp)+";" ;
/* if(sl!=0)
st+="b"+n(tp/sl);
if(tp!=0)st+=";s"+n(sl/tp);
*/
//st+="m"+n(all_sl);
double now_line_top=ObjectGetValueByTime(0,"top_arr_m5",TimeCurrent());
double now_line_niz=ObjectGetValueByTime(0,"bot_arr_m5",TimeCurrent());
st+="m1:"+from_to(now_line_niz,now_line_top);
//+"|"+nero;
ObjectSetString(0,"text",OBJPROP_TEXT,st);
// make_bot();
int spred=SymbolInfoInteger(_Symbol,SYMBOL_SPREAD);
double up=get_fraktal_next(PERIOD_M5,0,Bid,"up");
double up2=get_fraktal_next(PERIOD_M5,0,up+(100+spred)*_Point,"up");
double down=get_fraktal_next(PERIOD_M5,1,Bid,"down");
double down2=get_fraktal_next(PERIOD_M5,1,down-(100+spred)*_Point,"down");
make_line("up_line1",up);
make_line("up_line2",up2);
make_line("low_line1",down);
make_line("low_line1",down2);
// ObjectMove(0,"up_line1",0,TimeCurrent(),up);
// ObjectMove(0,"up_line2",0,TimeCurrent(),up2);
//ObjectMove(0,"low_line1",0,TimeCurrent(),down);
// ObjectMove(0,"low_line2",0,TimeCurrent(),down2);
make_rect(PERIOD_CURRENT);
make_rect(PERIOD_M5,2);
make_rect(PERIOD_H1,1,clrAzure);
double next_niz=get_fraktal_next(PERIOD_M5,1,up2);
make_rect1("new_rect",up2,next_niz,iTime(NULL,PERIOD_H1,2),clrAqua);
//Alert(nero);
now_trend=get_trend(PERIOD_CURRENT);
Comment(now_trend,n(all_sl),"w",n(stopprice),"b",n(buylot),"s",n(selllot),"l",make_lot("buy"),"-",order_sell_stop,"-",order_sell_c,st,"-",n(all_sl));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double n(double n)
{
return NormalizeDouble(n,2);
}
double check_res(double price){
double out;
if(Bid>price)out=1;
else out=0.01;
out=from_to(price,Bid);
return out;
}
double get_ind(int hand,int buf){
double ind_val[];
CopyBuffer(hand,buf,0,3,ind_val);ArraySetAsSeries(ind_val,true);
return ind_val[0];
}
double Nero_analys(ENUM_TIMEFRAMES frame){
double red1[],blue1[],span_a[],span_b[],boli_high[],boli_low[],boli_m[],arr_max,arr_min;
int h_boli=iBands(NULL,frame,20,0,2,PRICE_CLOSE);
// ><5@0 1CD5@>2: 0 - BASE_LINE, 1 - UPPER_BAND, 2 - LOWER_BAND
int handle=iIchimoku(NULL,frame,9,26,52);
// int handle=iIchimoku(NULL,PERIOD_CURRENT,9,26,52);
//if(CopyBuffer(h_boli,1,0,3,boli_high)<=0)return;ArraySetAsSeries(boli_high,true);
double l_top,l_bot;
l_top=iHigh(_Symbol,PERIOD_D1,1);
l_bot=iLow(_Symbol,PERIOD_D1,1);
if(SymbolInfoDouble(_Symbol,SYMBOL_ASKHIGH)>l_top)
l_top=SymbolInfoDouble(_Symbol,SYMBOL_ASKHIGH);
if(l_bot>SymbolInfoDouble(_Symbol,SYMBOL_BIDLOW))
l_bot=SymbolInfoDouble(_Symbol,SYMBOL_BIDLOW);
double fr_niz=get_fraktal_price(frame,1,1)-20*_Point;
double fr_top=get_fraktal_price(frame,0,1)+(SymbolInfoInteger(_Symbol,SYMBOL_SPREAD)+20)*_Point;
double all_pr[10],all_val[10], all_val_sum=0;
// massiv
all_pr[0]=get_ind(h_boli,1);
all_pr[1]=get_ind(h_boli,2);
all_pr[2]=get_ind(handle,0); //red
all_pr[3]=get_ind(handle,1); //blue
all_pr[4]=get_ind(handle,2); //span_a
all_pr[5]=get_ind(handle,3); //span_b
//all_pr[6]=l_top;
//all_pr[7]=l_bot;
all_pr[6]=fr_niz;
all_pr[7]=fr_top;
all_pr[8]=iHigh(NULL,frame,iHighest(NULL,frame,MODE_CLOSE,5)); //max 5 bars
all_pr[9]=iLow(NULL,frame,iLowest(NULL,frame,MODE_CLOSE,5)); //min 5 bars
//all_pr[8]=Ask+20*_Point;
/*
inp[0]=check_res(red1[0]);
inp[1]=check_res(blue1[0]);
inp[2]=check_res(span_a[0]);
inp[3]=check_res(span_b[0]);*/
arr_max=all_pr[ArrayMaximum(all_pr)];
arr_min=all_pr[ArrayMinimum(all_pr)];
double maxmin=arr_max-arr_min;
// CDynamicArray val_st,val_tp;
int arr_size=ArraySize(all_pr);
for(int n1=0;n1<arr_size;n1++){
// Bid
double ind_price=n(all_pr[n1]);
double val=(Bid-ind_price)/maxmin;
all_val[n1]=val;
all_val_sum+=val;
//if(Bid>ind_price)array_add(val_st,ind_price); else array_add(val_tp,ind_price);
// val_st.Add()
if(Bid>ind_price){if(val_st.SearchLinear(ind_price)==-1)val_st.Add(ind_price);} else{
if(val_tp.SearchLinear(ind_price)==-1)val_tp.Add(ind_price);
}
} string str1="s";
for(int i=0;i<val_tp.Total();i++)
{
double result=val_tp.At(i);
str1+="|"+i+"-"+result;
}
Print("t"+val_tp.Total()+";s"+val_st.Total()+"|"+str1);
Print("i"+maxmin,"-",all_val_sum+":"+(all_val_sum/arr_size));
// int b=val_st.Size();
Print(print_arr(all_pr));
//for(int e=0;e<b;e++)str1=str1+"|"+val_st[e];
// Print("pr"+print_arr(val_st));
double out=all_val_sum/arr_size;
string str;
if(frame==PERIOD_M1){
if(out>0)str="buy"; else str="sell";
if(now_trend!=str ){SendNotification(_Symbol+" new tr "+str);
// now_trend=str;
}
}
return out;
}
string print_arr(double &x[]){
string str="";
for(int i=0;i<ArraySize(x);i++)str+="|"+i+"-"+x[i];
return str;
}
int array_add(double &x[],double add){
int i=ArraySize(x);
int b=i+1;
ArrayResize(x,b);
Print(i,add);
x[i]=add;
return 1;
}
double nero_alltime(){
//ENUM_TIMEFRAMES
double out=Nero_analys(PERIOD_M1)+Nero_analys(PERIOD_M5)+Nero_analys(PERIOD_M15)+Nero_analys(PERIOD_M30)+Nero_analys(PERIOD_H1)
+Nero_analys(PERIOD_H4)+Nero_analys(PERIOD_D1);
//nero_mas();
return out/7;
}
double nero_mas(){
//val_tp.Sort();
for(int i=0;i<val_tp.Total();i++){
ObjectDelete(0,"tp_l"+i);
make_line("tp_l"+i,val_tp.At(i),clrDarkRed);
}
for(int b=0;b<val_st.Total();b++){
ObjectDelete(0,"sl_l"+b);
make_line("sl_l"+b,val_st.At(b),clrYellowGreen);
}
return 0;
}
double CalculateNeuron(double &x[],double &w[])
{
//--- ?5@5<5==0O 4;O E@0=5=8O A@54=52725H5==>9 AC<<K 2E>4=KE A83=0;>2
double NET=0.0,out;
//---  F8:;5 ?> :>;8G5AB2C 2E>4>2 ?>;CG05< A@54=52725H5==CN AC<<C 2E>4>2
double d1=0.0;
double d2=1.0;
double x_min=ArrayMinimum(x);
double x_max=ArrayMaximum(x);
double xn;
for(int n=0;n<ArraySize(x);n++)
{
// xn=(((x[n]-x_min)*(d2-d1))/(x_max-x_min))+d1;
xn=x[n];
NET+=xn*w[n];
}
//--- C<=>605< A@54=52725H5==CN AC<<C 2E>4>2 =0 4>102>G=K9 :>MDD8F85=B
// NET*=0.4;
//--- ?5@5405< A@54=52725H5==CN AC<<C 2E>4>2 2 DC=:F8N 0:B820F88 8 2>72@0I05< 55 7=0G5=85
//out=1-1/NET;
//double out = (exp(NET)-exp(-NET))/(exp(NET)+exp(-NET));
out=NET;
out=NormalizeDouble(out,5);
return out;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string make_bot(){
ENUM_TIMEFRAMES open_frame=PERIOD_H1;
double ilow=iLow(_Symbol,open_frame,1);
//ObjectCreate(0,"bot_rect",OBJ_RECTANGLE,1,iTime(_Symbol,open_frame,2),ilow);
if(ilow>iLow(_Symbol,open_frame,0))
ilow=iLow(_Symbol,open_frame,0);
if(iOpen(_Symbol,open_frame,1)>iClose(_Symbol,open_frame,1) && (iClose(_Symbol,open_frame,1)-ilow)>10*_Point
// && (Bid-iClose(_Symbol,open_frame,1))>_Point*MathAbs(profit_point(iClose(_Symbol,open_frame,1),iOpen(_Symbol,open_frame,1))/2)
// -&& profit_point(top_rect,Bid)>500
// && s_o_b!="high_fib"
)
{
ObjectMove(0,"bot_rect",0,iTime(_Symbol,open_frame,2),ilow);
ObjectMove(0,"bot_rect",1,TimeCurrent(),iClose(_Symbol,open_frame,1));
}
double ihigh=iHigh(_Symbol,open_frame,0);
if(ihigh<iHigh(_Symbol,open_frame,1))
ihigh=iHigh(_Symbol,open_frame,1);
if(iOpen(_Symbol,open_frame,1)<iClose(_Symbol,open_frame,1) && (ihigh-iClose(_Symbol,open_frame,1))>10*_Point
// && (iClose(_Symbol,open_frame,1)-Bid)>_Point*MathAbs(profit_point(iClose(_Symbol,open_frame,1),iOpen(_Symbol,open_frame,1))/2)
)
{
// s_o_b="sell";
ObjectMove(0,"top_rect",0,iTime(_Symbol,open_frame,2),iClose(_Symbol,open_frame,1));
ObjectMove(0,"top_rect",1,TimeCurrent(),ihigh);
}
return 0;
}
string make_fraktal(string name, ENUM_TIMEFRAMES bframe,color clr=clrRed, int width=1)
{
//1 - niz fraktal 0-vverh
int top1,top2,niz1,niz2;
top1=get_fraktal_point(bframe,0,1);
top2=get_fraktal_point(bframe,0,2);
niz1=get_fraktal_point(bframe,1,1);
niz2=get_fraktal_point(bframe,1,2);
// Alert("0-"+get_fraktal_point(bframe,0,1)+"-"+get_fraktal_point(PERIOD_CURRENT,0,2));
// Alert("1-"+get_fraktal_point(PERIOD_CURRENT,1,1)+"-"+get_fraktal_point(PERIOD_CURRENT,1,2));
string name_top="top_arr_"+name;
string name_bot="bot_arr_"+name;
ObjectDelete(0,name_bot);
ObjectDelete(0,name_top);
ObjectCreate(0,name_top,OBJ_TREND,0,iTime(NULL,bframe,top2),iHigh(NULL,bframe,top2),iTime(NULL,bframe,top1),iHigh(NULL,bframe,top1));
ObjectCreate(0,name_bot,OBJ_TREND,0,iTime(NULL,bframe,niz2),iLow(NULL,bframe,niz2),iTime(NULL,bframe,niz1),iLow(NULL,bframe,niz1));
ObjectSetInteger(0,name_top,OBJPROP_COLOR,clr);
ObjectSetInteger(0,name_top,OBJPROP_WIDTH,width);
ObjectSetInteger(0,name_top,OBJPROP_RAY_RIGHT,true);
ObjectSetInteger(0,name_bot,OBJPROP_COLOR,clr);
ObjectSetInteger(0,name_bot,OBJPROP_WIDTH,width);
ObjectSetInteger(0,name_bot,OBJPROP_RAY_RIGHT,true);
string out="o";
if(top2-top1<10*_Point)
out="top_flat";
return out;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int get_fraktal_point(ENUM_TIMEFRAMES bframe,int buffer,int shift=0)
{
//
int fra=iFractals(NULL,bframe);
if(fra<0)
{
Print("1J5:B iMA =5 A>740=: MA_handle= ",INVALID_HANDLE);
Print("H81:0 8A?>;=5=8O = ",GetLastError());
//--- ?@8=C48B5;L=>5 7025@H5=85 ?@>3@0<<K
return(-1);
}
double fra1[];
int i,b=0,max=200;
CopyBuffer(fra,buffer,0,max,fra1);
ArraySetAsSeries(fra1,true);
string out;
for(i=0; i<max; i++)
{
if(fra1[i]!=EMPTY_VALUE)
{
b++;
if(shift==b)
break;
}
}
// Alert(out);
return i;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double get_fraktal_price(ENUM_TIMEFRAMES bframe,int buffer,int shift=0)
{
int point=get_fraktal_point(bframe,buffer,shift);
double out;
if(buffer==1)
out=iLow(NULL,bframe,point);
else
out=iHigh(NULL,bframe,point);
return out;
}
double get_fraktal_next(ENUM_TIMEFRAMES bframe,int buffer,double pr,string more="up"){
int i,max=200;
double out;
if(more=="up"){
for(i=1; i<max; i++){
out=get_fraktal_price(bframe,buffer,i);
if(out>pr) break;
}
}
else{
for(i=1; i<max; i++){
out=get_fraktal_price(bframe,buffer,i);
if(out<pr) break;
}
}
return out;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double make_rect(ENUM_TIMEFRAMES bframe,int fr=1, color col=clrDarkOrange){
//1 - niz fraktal 0-vverh
get_fraktal_next(bframe,0,Bid,"up");
double niz=get_fraktal_price(bframe,1,fr);
double top=get_fraktal_price(bframe,0,fr);
int topfr=get_fraktal_point(bframe,0,fr);
int botfr=get_fraktal_point(bframe,1,fr);
string name_top="top_r"+EnumToString(bframe);
string name_bot="bot_r"+EnumToString(bframe);
ObjectCreate(0,name_bot,OBJ_RECTANGLE,0,0,0);
if(fr==2)col=clrOrangeRed;
ObjectSetInteger(0,name_bot,OBJPROP_COLOR,col);
ObjectSetInteger(0,name_bot,OBJPROP_FILL,1);
ObjectCreate(0,name_top,OBJ_RECTANGLE,0,0,0);
ObjectSetInteger(0,name_top,OBJPROP_COLOR,col);
ObjectSetInteger(0,name_top,OBJPROP_FILL,1);
ObjectMove(0,name_top,0,iTime(_Symbol,bframe,topfr),top);
double close1=iClose(_Symbol,bframe,topfr);
double open1=iOpen(_Symbol,bframe,topfr);
if(close1<open1)close1=open1;
ObjectMove(0,name_top,1,TimeCurrent(),close1);
double close2=iClose(NULL,bframe,botfr);
double open2=iOpen(NULL,bframe,botfr);
if(close2>open2)close2=open2;
ObjectMove(0,name_bot,0,iTime(NULL,bframe,botfr),close2);
ObjectMove(0,name_bot,1,TimeCurrent(),niz);
return 1;
}
int make_rect1(string name_bot,double price1, double price2, datetime time2,color col=clrDarkOrange){
ObjectCreate(0,name_bot,OBJ_RECTANGLE,0,0,0);
ObjectSetInteger(0,name_bot,OBJPROP_COLOR,col);
ObjectSetInteger(0,name_bot,OBJPROP_FILL,1);
ObjectMove(0,name_bot,0,time2,price2);
ObjectMove(0,name_bot,1,TimeCurrent(),price1);
return 0;
}
int make_line(string name,double price,color col=clrYellow){
ObjectCreate(0,name,OBJ_HLINE,0,TimeCurrent(),price);
ObjectSetInteger(0,name,OBJPROP_COLOR,col);
//--- CAB0=>28< AB8;L >B>1@065=8O ;8=88
// ObjectSetInteger(0,up_line1,OBJPROP_STYLE,style);
//--- CAB0=>28< B>;I8=C ;8=88
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
return 1;
}
string find_open_first(ENUM_TIMEFRAMES bframe){
//1 - niz fraktal 0-vverh
string out="null";
double niz1=get_fraktal_price(bframe,1,1);
double niz2=get_fraktal_price(bframe,1,2);
double niz3=get_fraktal_price(bframe,1,3);
if(niz2<niz3 && niz2<niz1 && Bid>niz1 )out="buy";
double vv1=get_fraktal_price(bframe,0,1);
double vv2=get_fraktal_price(bframe,0,2);
double vv3=get_fraktal_price(bframe,0,3);
if(niz2>niz3 && niz2>niz1 && Bid<niz1 )out="sell";
return out;
}
string find_open_line(string want="s_o_b",ENUM_TIMEFRAMES bframe=PERIOD_M1,ENUM_TIMEFRAMES line_frame=PERIOD_M5){
string out="null";
string out2="null";
//1 - niz fraktal 0-vverh
double f_line_top=get_fraktal_price(line_frame,0,1);
double f_line_bot=get_fraktal_price(line_frame,1,1);
if(want!="s_o_b" && want!="com"){double f_line_top=ObjectGetValueByTime(0,"top_arr_"+want,TimeCurrent());
double f_line_bot=ObjectGetValueByTime(0,"bot_arr_"+want,TimeCurrent());}
double high1=iHigh(NULL,bframe,1);
if(iOpen(NULL,bframe,2)<f_line_top && high1>f_line_top && Bid>high1){out="buy";out2="prob_top";} // probivka
if(iOpen(NULL,bframe,2)<f_line_top && high1>f_line_top && Bid<f_line_top){out="sell";out2="ots_top";} // otskok
double low1=iLow(NULL,bframe,1);
if(iOpen(NULL,bframe,2)>f_line_bot && low1<f_line_bot && Bid<low1){out="sell";out2="prob_niz";} //proboy
if(iOpen(NULL,bframe,2)>f_line_bot && low1<f_line_bot && Bid>f_line_bot){out="buy";out2="ots_bot";} //otskok
if(want=="com")out=out2;
return out;
}
string find_open_fraktal(ENUM_TIMEFRAMES bframe){
string out="null";
double f_line_top=get_fraktal_price(bframe,0,1);
int top=get_fraktal_point(bframe,0,1);
double f_line_bot=get_fraktal_price(bframe,1,1);
int bot=get_fraktal_point(bframe,1,1);
if(Bid>f_line_top && bot<top)out="buy";
if(Bid<f_line_bot && bot>top)out="sell";
return out;
}
string find_open(ENUM_TIMEFRAMES bframe)
{
//1 - niz fraktal 0-vverh
string out="null";
int top1,top2,top3,niz1,niz2,niz3;
top1=get_fraktal_point(bframe,0,1);
top2=get_fraktal_point(bframe,0,2);
niz1=get_fraktal_point(bframe,1,1);
niz2=get_fraktal_point(bframe,1,2);
niz3=get_fraktal_point(bframe,1,3);
top3=get_fraktal_point(bframe,0,3);
if(iHigh(NULL,bframe,top3)<iHigh(NULL,bframe,top2) && iHigh(NULL,bframe,top1)<iHigh(NULL,bframe,top2) &&
iLow(NULL,bframe,niz1)> iLow(NULL,bframe,niz2) && iLow(NULL,bframe,niz1)>Bid)
out="sell";
if(iHigh(NULL,bframe,top2)>iHigh(NULL,bframe,top1)
//&& iHigh(NULL,bframe,top1)>iHigh(NULL,bframe,top2)
&& iLow(NULL,bframe,niz3)>iLow(NULL,bframe,niz2) && iLow(NULL,bframe,niz2)<iLow(NULL,bframe,niz1)
&& iHigh(NULL,bframe,top1)<Bid)
out="buy";
return out;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string find_open_add(ENUM_TIMEFRAMES bframe)
{
string out="null";
double low1=iLow(NULL,bframe,1);
//ObjectGetDouble(0,"bot_arr_m1",
if(get_trend(bframe)=="sell" && get_fraktal_price(bframe,0,1)>Bid)
out="sell";
if(get_trend(bframe)=="buy" && Bid-get_fraktal_price(bframe,1,1)>SymbolInfoInteger(NULL,SYMBOL_SPREAD)*_Point)
out="buy";
return out;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string check_line(string s_b){
string out;
double line=ObjectGetDouble(0,"my",OBJPROP_PRICE);
double line_niz=ObjectGetDouble(0,"my_niz",OBJPROP_PRICE);
if(use_line==true){
if(s_o_b==buy && Bid>line)out="buy";
if(s_o_b==sell && Bid<line)out="sell";
}else out=s_b;
if(use_zone==true){
if(s_o_b==buy){
if(Bid<line && Bid>line_niz)out="buy";
}
if(s_o_b==sell){
if(Bid>line_niz && Bid<line)out="sell";
}
}else out=s_b;
return out;
}
double open_order(string s_b,string com,int bar=2,double sum=0)
{
double lot=make_lot(s_b,sum);
string check=check_line(s_b);
if(SymbolInfoInteger(NULL,SYMBOL_SPREAD)<50 && check==s_b)
{
if(s_b=="sell"){
if(auto==false) trade.Sell(lot,NULL,0,stop_price("sell",bar),0,com);
else{
if(s_o_b==sell || s_o_b==all)trade.Sell(lot,NULL,0,stop_price("sell",bar),0,com);
}
}
if(s_b=="buy"){
if(auto==false)trade.Buy(lot,NULL,0,stop_price("buy",bar),0,com);
else{
if(s_o_b==buy || s_o_b==all) trade.Buy(lot,NULL,0,stop_price("buy",bar),0,com);
}
}
}
return 0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double make_lot(string ss,double sum=0)
{
double free=AccountInfoDouble(ACCOUNT_MARGIN_FREE);
double mkoof=koof;
if(sum>0){
if(sum>testlot*free){
free=sum;mkoof=next_risk;
}else{mkoof=testlot;}
}
double stop=stop_price(ss);
double cross=0.00001;
if(ss=="sell")
cross=stop-Bid;
if(ss=="buy")
cross=Ask-stop;
// return 0;
int point=cross/_Point;
double min=SymbolInfoDouble(NULL,SYMBOL_VOLUME_MIN);
double m;
if(point>0)
m=free*mkoof/point;
else
m=min;
if(AccountInfoString(ACCOUNT_CURRENCY)=="RUB")
m=(free/usdrub)*mkoof/point;
m=NormalizeDouble(m,2);
if(m<=min)
m=min;
return m;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double find_price(double open_price,double to_price, double lot,string want="tp",string s_b="sell")
{
double out=0.1;
if(want=="tp")
{
if(s_b=="sell")
{
out=(open_price-to_price)/_Point*lot;
}
if(s_b=="buy")
{
out=(to_price-open_price)/_Point*lot;
}
}
if(want=="sl")
{
if(s_b=="buy")
{
out=(open_price-to_price)/_Point*lot;
}
if(s_b=="sell")
{
out=(open_price-to_price)/_Point*lot;
}
}
if(AccountInfoString(ACCOUNT_CURRENCY)=="RUB")out=out*usdrub/100;
return out;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double stop_price(string s_b,int bar=1)
{
double out,add;
add=(SymbolInfoInteger(_Symbol,SYMBOL_SPREAD)+20)*_Point;
int level=SymbolInfoInteger(NULL,SYMBOL_TRADE_STOPS_LEVEL);
if(s_b=="sell")
{
double top1=get_fraktal_point(stop_frame,0,bar);
top1=get_fraktal_next(stop_frame,0,top1);
out=iHigh(NULL,stop_frame,top1)+add;
if((out-Ask)/_Point <level)
out=Ask+(level+10)*_Point;
}
if(s_b=="buy")
{
double niz=get_fraktal_point(stop_frame,1,bar);
niz=get_fraktal_next(stop_frame,1,niz);
out=iLow(NULL,stop_frame,niz)-10*_Point;
if((Ask-out)/_Point <level)
out=Bid-(level+10)*_Point;
}
return out;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string get_trend(ENUM_TIMEFRAMES bframe)
{
//1 - niz fraktal 0-vverh
string out="null";
int niz_point1=get_fraktal_point(bframe,1,1);
int niz_point2=get_fraktal_point(bframe,1,2);
int top_point1=get_fraktal_point(bframe,0,1);
int top_point2=get_fraktal_point(bframe,0,2);
double top_price1=get_fraktal_price(bframe,0,1);
double top_price2=get_fraktal_price(bframe,0,2);
double niz_price1=get_fraktal_price(bframe,1,1);
double niz_price2=get_fraktal_price(bframe,1,2);
if(niz_price1>niz_price2 && top_price1>top_price2){
out="buy";
if(Bid>top_price1 )out="cool_buy";
if(Bid<niz_price1){out="change_sell";last_min=niz_price1;last_min_point=niz_point1;}
}
if(niz_price1<niz_price2 && top_price1<top_price2){
out="sell";
if(Bid>top_price1){out="change_buy"; last_max=top_price1;last_max_point=top_point1;}
if(Bid<niz_price1)out="cool_sell";
}
return out;
}
string find_open_change(ENUM_TIMEFRAMES bframe){
string trend=get_trend(bframe);
string out="null";
int top_point1=get_fraktal_point(bframe,0,1);
double top_price1=get_fraktal_price(bframe,0,1);
// from buy change to sell
if(trend=="change_sell"){
if(last_min > top_price1 && last_min_point> top_point1)out="sell";
}
int niz_point1=get_fraktal_point(bframe,1,1);
double niz_price1=get_fraktal_price(bframe,1,1);
if(trend=="change_buy"){
if(last_max <niz_price1 && niz_point1<last_max_point)out="buy";
}
return out;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool free_balance()
{
double free=AccountInfoDouble(ACCOUNT_MARGIN_FREE);
double bal=AccountInfoDouble(ACCOUNT_BALANCE);
// if(free>bal)
return 0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double stop_balance()
{
return 0;
}
int from_to(double niz,double vverh){
int out=(vverh-niz)/_Point;
return out;
}
/*
double open_order(){
MqlTradeRequest m_request; // request data
MqlTradeResult m_result;
m_request.action =TRADE_ACTION_DEAL;
m_request.symbol =NULL;
//m_request.magic =m_magic;
m_request.volume =0.01;
m_request.type =ORDER_TYPE_SELL;
m_request.price =Bid;
/* m_request.sl =sl;
m_request.tp =tp;
m_request.deviation=m_deviation;
m_request.comment="test";
return(OrderSend(m_request,m_result));
}
*/
//+------------------------------------------------------------------+