//+------------------------------------------------------------------+ //| test2423.mq4 | //| Copyright 2022, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_chart_window #include int numInput=4; int numHiddenA = 4; int numHiddenB = 5; int numOutput=3; DeepNeuralNetwork dnn(numInput,numHiddenA,numHiddenB,numOutput); //--- weight values double w0=1.0; double w1=1.0; double w2=1.0; double w3=1.0; double w4=1.0; double w5=1.0; double w6=1.0; double w7=1.0; double w8=1.0; double w9=1.0; double w10=1.0; double w11=1.0; double w12=1.0; double w13=1.0; double w14=1.0; double w15=1.0; double b0=1.0; double b1=1.0; double b2=1.0; double b3=1.0; double w40=1.0; double w41=1.0; double w42=1.0; double w43=1.0; double w44=1.0; double w45=1.0; double w46=1.0; double w47=1.0; double w48=1.0; double w49=1.0; double w50=1.0; double w51=1.0; double w52=1.0; double w53=1.0; double w54=1.0; double w55=1.0; double w56=1.0; double w57=1.0; double w58=1.0; double w59=1.0; double b4=1.0; double b5=1.0; double b6=1.0; double b7=1.0; double b8=1.0; double w60=1.0; double w61=1.0; double w62=1.0; double w63=1.0; double w64=1.0; double w65=1.0; double w66=1.0; double w67=1.0; double w68=1.0; double w69=1.0; double w70=1.0; double w71=1.0; double w72=1.0; double w73=1.0; double w74=1.0; double b9=1.0; double b10=1.0; double b11=1.0; double _xValues[4]; // array for storing inputs double weight[63]; // array for storing weights double out; // variable for storing the output of the neuron //| | //+------------------------------------------------------------------+ int OnInit() { weight[0]=w0; weight[1]=w1; weight[2]=w2; weight[3]=w3; weight[4]=w4; weight[5]=w5; weight[6]=w6; weight[7]=w7; weight[8]=w8; weight[9]=w9; weight[10]=w10; weight[11]=w11; weight[12]=w12; weight[13]=w13; weight[14]=w14; weight[15]=w15; weight[16]=b0; weight[17]=b1; weight[18]=b2; weight[19]=b3; weight[20]=w40; weight[21]=w41; weight[22]=w42; weight[23]=w43; weight[24]=w44; weight[25]=w45; weight[26]=w46; weight[27]=w47; weight[28]=w48; weight[29]=w49; weight[30]=w50; weight[31]=w51; weight[32]=w52; weight[33]=w53; weight[34]=w54; weight[35]=w55; weight[36]=w56; weight[37]=w57; weight[38]=w58; weight[39]=w59; weight[40]=b4; weight[41]=b5; weight[42]=b6; weight[43]=b7; weight[44]=b8; weight[45]=w60; weight[46]=w61; weight[47]=w62; weight[48]=w63; weight[49]=w64; weight[50]=w65; weight[51]=w66; weight[52]=w67; weight[53]=w68; weight[54]=w69; weight[55]=w70; weight[56]=w71; weight[57]=w72; weight[58]=w73; weight[59]=w74; weight[60]=b9; weight[61]=b10; weight[62]=b11; 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(rates_total!=20) //i just put 20 so that the code inside the curly braces would get executed { MqlRates rates[]; ArraySetAsSeries(rates,true); int copied=CopyRates(_Symbol,0,1,5,rates); //compute the percent of the upper shadow, lower shadow and body in base of sum 100% int error=CandlePatterns(rates[1].high,rates[1].low,rates[1].open,rates[1].close,rates[1].close-rates[1].open,_xValues); dnn.SetWeights(weight); double yValues[]; dnn.ComputeOutputs(_xValues,yValues); //--- if the output value of the neuron is mare than 80% if(yValues[0]>0.8) { ObjectCreate("UsdHourTwo", OBJ_LABEL,0,0,0); ObjectSet("UsdHourTwo", OBJPROP_CORNER, CORNER_RIGHT_UPPER); ObjectSet("UsdOne", OBJPROP_XDISTANCE,30); ObjectSetText("UsdHourTwo","+1",10,"Arial",Yellow); //the objectlabel result would be +1 buy } //--- if the output value of the neuron is mare than 80% if(yValues[1]>0.8) { ObjectCreate("UsdHourTwo", OBJ_LABEL,0,0,0); ObjectSet("UsdHourTwo", OBJPROP_CORNER, CORNER_RIGHT_UPPER); ObjectSet("UsdOne", OBJPROP_XDISTANCE,30); ObjectSetText("UsdHourTwo","-1|",10,"Arial",Yellow); //the objectlabel result would be -1 sell } //--- if the output value of the neuron is mare than 80% if(yValues[2]>0.8) { ObjectCreate("UsdHourTwo", OBJ_LABEL,0,0,0); ObjectSet("UsdHourTwo", OBJPROP_CORNER, CORNER_RIGHT_UPPER); ObjectSet("UsdOne", OBJPROP_XDISTANCE,30); ObjectSetText("UsdHourTwo","0",10,"Arial",Yellow); //the objectlabel result would be 0 ignore/hold } } return(rates_total); } //+------------------------------------------------------------------+ //|percentage of each part of the candle respecting total size | //+------------------------------------------------------------------+ int CandlePatterns(double high,double low,double open,double close,double uod,double &xInputs[]) { double p100=high-low; double highPer=0; double lowPer=0; double bodyPer=0; double trend=0; if(uod>0) { highPer=high-close; lowPer=open-low; bodyPer=close-open; trend=1; } else { highPer=high-open; lowPer=close-low; bodyPer=open-close; trend=0; } if(p100==0)return(-1); xInputs[0]=highPer/p100; xInputs[1]=lowPer/p100; xInputs[2]=bodyPer/p100; xInputs[3]=trend; return(1); }