Hi Vladimir,
I always find your codes.This is another good EA.I ask you : i need a trailing stop.Please,build it into code.
Thanks a lot
Hi Vladimir,
I changed the Polish Layer code written by you for my own purposes. I want to combine the results of several indicators and draw this out of the results. How can I do it?
Hi Vladimir,
I changed the Polish Layer code written by you for my own purposes. I want to combine the results of several indicators and draw this out of the results. How can I do it?
Describe in detail what you did. Show the code. Tell me what more needs to be done.
How can I insert the code correctly? Or just copy-paste? I can see the Alt+S function,but i do not know how it works.
Forum on trading, automated trading systems and testing trading strategies
General rules and best pratices of the Forum.
Alain Verleyen, 2017.07.19 11:03
When you post code please use the SRC button !
#include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> #include <Trade\AccountInfo.mqh> CPositionInfo m_position; // trade position object CTrade m_trade; // trading object CSymbolInfo m_symbol; // symbol info object CAccountInfo m_account; // account info wrapper //--- input parameters input ENUM_TIMEFRAMES per_kis = PERIOD_M15; input ENUM_TIMEFRAMES per_nagy = PERIOD_H1; input int kis_trend_gyors_per= 99; input int kis_trend_lassú_per= 99; input int nagy_trend_gyors_per= 99; input int nagy_trend_lassú_per= 99; input ENUM_MA_METHOD MA_method_kis = MODE_SMA; input ENUM_MA_METHOD MA_method_nagy = MODE_SMA; input int ST_indikátor_periódus = 14; input int RSI_indikátor_periódus = 14; input int STh_alsó = 20; input int ST_lassuló = 3; input ushort TakeProfit=11111; input ushort StopLoss=90; input ushort TrailingStop=20; input double Lots=0.1; ulong m_magic=1; // magic number ulong m_slippage=30; // slippage int handle_iMA_kis_trend_gyors; // variable for storing the handle of the iMA indicator int handle_iMA_kis_trend_lassú; int handle_iMA_nagy_trend_gyors; int handle_iMA_nagy_trend_lassú; int handle_iRSI; int handle_iStochastic_M15; // variable for storing the handle of the iStochastic indicator ENUM_ACCOUNT_MARGIN_MODE m_margin_mode; double m_adjusted_point; // point value adjusted for 3 or 5 points //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { SetMarginMode(); if(!IsHedging()) { Print("Hedging only!"); return(INIT_FAILED); } if(TrailingStop>=TakeProfit) { Print("Error! TrailingStop>=TakeProfit!"); return(INIT_PARAMETERS_INCORRECT); } //--- m_symbol.Name(Symbol()); // sets symbol name if(!RefreshRates()) { Print("Error RefreshRates. Bid=",DoubleToString(m_symbol.Bid(),Digits()), ", Ask=",DoubleToString(m_symbol.Ask(),Digits())); return(INIT_FAILED); } m_symbol.Refresh(); //--- m_trade.SetExpertMagicNumber(m_magic); //--- m_trade.SetDeviationInPoints(m_slippage); //--- tuning for 3 or 5 digits int digits_adjust=1; m_adjusted_point=m_symbol.Point()*digits_adjust; //--- create handle of the indicator iMA handle_iMA_kis_trend_gyors=iMA(m_symbol.Name(),per_kis,kis_trend_gyors_per,0, MA_method_kis,PRICE_CLOSE); //--- create handle of the indicator iMA handle_iMA_kis_trend_lassú=iMA(m_symbol.Name(),per_kis,kis_trend_lassú_per ,0,MA_method_kis , PRICE_CLOSE ); //--- create handle of the indicator iMA handle_iMA_nagy_trend_gyors=iMA(m_symbol.Name(),per_nagy,nagy_trend_gyors_per ,0, MA_method_nagy , PRICE_CLOSE ); //--- create handle of the indicator iMA handle_iMA_nagy_trend_lassú=iMA(m_symbol.Name(),per_nagy,nagy_trend_lassú_per ,0, MA_method_nagy , PRICE_CLOSE ); //--- create handle of the indicator iRSI handle_iRSI=iRSI(m_symbol.Name(),per_kis,RSI_indikátor_periódus, PRICE_CLOSE); //--- create handle of the indicator iStochastic handle_iStochastic_M15=iStochastic(m_symbol.Name(),per_kis,ST_indikátor_periódus,3,ST_lassuló,MODE_SMA,STO_CLOSECLOSE); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(kis_trend_gyors_per>=kis_trend_lassú_per || nagy_trend_gyors_per>=nagy_trend_lassú_per) return; static datetime PrevBars=0; datetime time_0=iTime(0); if(time_0==PrevBars) return; PrevBars=time_0; //--- вычисляем начальные параметры индикаторов для поиска условий входа double MA_kis_trend_gyors = iMAGet(handle_iMA_kis_trend_gyors,0); double MA_kis_trend_lassú = iMAGet(handle_iMA_kis_trend_lassú,0); double MA_nagy_trend_gyors = iMAGet(handle_iMA_nagy_trend_gyors,0); double MA_nagy_trend_lassú = iMAGet(handle_iMA_nagy_trend_lassú,0); double Stoh_fast = iStochasticGet(MAIN_LINE,0); double Stoh_fast_prew=iStochasticGet(MAIN_LINE,1); double RSI0 = iRSIGet(0); double RSI1 = iRSIGet(1); double StRSI=(Stoh_fast*RSI0)/100;//------------------------------------------------------------------------ I would like to draw out these outcomes. double StRSI_prew=(Stoh_fast_prew*RSI1)/100;//-------------------------------------------------------------- double price_M15=iClose(1,NULL,per_kis); bool Long=false; if(MA_kis_trend_gyors>MA_kis_trend_lassú && MA_nagy_trend_gyors>MA_nagy_trend_lassú) Long=true; if(!Long ) return; //--- проверка условий для совершения сделки if(Long==true ) { if( StRSI>STh_alsó && StRSI_prew<=STh_alsó ) { if(!RefreshRates()) return; //--- check volume before OrderSend to avoid "not enough money" error (CTrade) double chek_volime_lot=m_trade.CheckVolume(m_symbol.Name(),Lots,m_symbol.Ask(),ORDER_TYPE_BUY); if(chek_volime_lot!=0.0) if(chek_volime_lot>=Lots) { Print("BUY разница (MA_M15-price_M15) = ",DoubleToString(MA_kis_trend_gyors,m_symbol.Digits()), " MA_M15 = ",DoubleToString(MA_kis_trend_gyors,m_symbol.Digits()), " price_M15 = ",DoubleToString(MA_kis_trend_gyors,m_symbol.Digits())); double sl=m_symbol.NormalizePrice(m_symbol.Bid()-StopLoss*m_adjusted_point); double tp=m_symbol.NormalizePrice(m_symbol.Bid()+TakeProfit*m_adjusted_point); if(m_trade.Buy(Lots,NULL,m_symbol.Ask(),sl,tp)) { if(m_trade.ResultDeal()==0) Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); else Print("Buy -> true. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); } else Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); } } } //--- трейлинг if(TrailingStop==0) return; for(int i=PositionsTotal()-1;i>=0;i--) if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties if(m_position.Symbol()==Symbol() && m_position.Magic()==m_magic) { if(m_position.PositionType()==POSITION_TYPE_BUY) { if(!RefreshRates()) continue; if(m_symbol.Bid()-m_position.PriceOpen()>TrailingStop*m_adjusted_point) { if(m_position.StopLoss()<m_symbol.Bid()-TrailingStop*m_adjusted_point) { if(!m_trade.PositionModify(m_position.Ticket(), m_symbol.NormalizePrice(m_symbol.Bid()-TrailingStop*m_adjusted_point), m_position.TakeProfit())) Print("PositionModify -> false. Result Retcode: ",m_trade.ResultRetcode(), ", description of result: ",m_trade.ResultRetcodeDescription()); } } } } //--- return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void SetMarginMode(void) { m_margin_mode=(ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool IsHedging(void) { return(m_margin_mode==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING); } //+------------------------------------------------------------------+ //| Refreshes the symbol quotes data | //+------------------------------------------------------------------+ bool RefreshRates() { //--- refresh rates if(!m_symbol.RefreshRates()) return(false); //--- protection against the return value of "zero" if(m_symbol.Ask()==0 || m_symbol.Bid()==0) return(false); //--- return(true); } //+------------------------------------------------------------------+ //| Get value of buffers for the iMA | //+------------------------------------------------------------------+ double iMAGet(int handle_iMA,const int index) { double MA[1]; //--- reset error code ResetLastError(); //--- fill a part of the iMABuffer array with values from the indicator buffer that has 0 index if(CopyBuffer(handle_iMA,0,index,1,MA)<0) { //--- if the copying fails, tell the error code PrintFormat("Failed to copy data from the iMA indicator, error code %d",GetLastError()); //--- quit with zero result - it means that the indicator is considered as not calculated return(0.0); } return(MA[0]); } //+------------------------------------------------------------------+ //| Get value of buffers for the iStochastic | //| the buffer numbers are the following: | //| 0 - MAIN_LINE, 1 - SIGNAL_LINE | //+------------------------------------------------------------------+ double iStochasticGet(const int buffer,const int index) { double Stochastic[1]; //--- reset error code ResetLastError(); //--- fill a part of the iStochasticBuffer array with values from the indicator buffer that has 0 index if(CopyBuffer(handle_iStochastic_M15,buffer,index,1,Stochastic)<0) { //--- if the copying fails, tell the error code PrintFormat("Failed to copy data from the iStochastic indicator, error code %d",GetLastError()); //--- quit with zero result - it means that the indicator is considered as not calculated return(0.0); } return(Stochastic[0]); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Get value of buffers for the iRSI | //+------------------------------------------------------------------+ double iRSIGet(const int index) { double RSI[1]; //--- reset error code ResetLastError(); //--- fill a part of the iRSI array with values from the indicator buffer that has 0 index if(CopyBuffer(handle_iRSI,0,index,1,RSI)<0) { //--- if the copying fails, tell the error code PrintFormat("Failed to copy data from the iRSI indicator, error code %d",GetLastError()); //--- quit with zero result - it means that the indicator is considered as not calculated return(0.0); } return(RSI[0]); } //+------------------------------------------------------------------+ //| Get Close for specified bar index | //+------------------------------------------------------------------+ double iClose(const int index,string symbol=NULL,ENUM_TIMEFRAMES timeframe=PERIOD_CURRENT) { if(symbol==NULL) symbol=Symbol(); if(timeframe==0) timeframe=per_kis; double Close[1]; double close=0; int copied=CopyClose(symbol,timeframe,index,1,Close); if(copied>0) close=Close[0]; return(close); } //+------------------------------------------------------------------+ //| Get Time for specified bar index | //+------------------------------------------------------------------+ datetime iTime(const int index,string symbol=NULL,ENUM_TIMEFRAMES timeframe=PERIOD_CURRENT) { if(symbol==NULL) symbol=Symbol(); if(timeframe==0) timeframe=per_kis; datetime Time[1]; datetime time=0; int copied=CopyTime(symbol,timeframe,index,1,Time); if(copied>0) time=Time[0]; return(time); } //+------------------------------------------------------------------+
Combining Polish Layer and Get Trend. I highlighted the issue with a blank background.
//--- create handle of the indicator iMA handle_iMA_kis_trend_gyors=iMA(m_symbol.Name(),per_kis,kis_trend_gyors_per,0,MA_method_kis,PRICE_CLOSE); //--- if the handle is not created if(handle_iMA_kis_trend_gyors==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle \"handle_iMA_kis_trend_gyors\" of the iMA indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(per_kis), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- create handle of the indicator iMA handle_iMA_kis_trend_lassú=iMA(m_symbol.Name(),per_kis,kis_trend_lassú_per,0,MA_method_kis,PRICE_CLOSE); //--- if the handle is not created if(handle_iMA_kis_trend_lassú==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle \"handle_iMA_kis_trend_lassú\" of the iMA indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(per_kis), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- create handle of the indicator iMA handle_iMA_nagy_trend_gyors=iMA(m_symbol.Name(),per_nagy,nagy_trend_gyors_per,0,MA_method_nagy,PRICE_CLOSE); //--- if the handle is not created if(handle_iMA_nagy_trend_gyors==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle \"handle_iMA_nagy_trend_gyors\" of the iMA indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(per_kis), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- create handle of the indicator iMA handle_iMA_nagy_trend_lassú=iMA(m_symbol.Name(),per_nagy,nagy_trend_lassú_per,0,MA_method_nagy,PRICE_CLOSE); //--- if the handle is not created if(handle_iMA_nagy_trend_lassú==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle \"handle_iMA_nagy_trend_lassú\" of the iMA indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(per_kis), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- create handle of the indicator iRSI handle_iRSI=iRSI(m_symbol.Name(),per_kis,RSI_indikátor_periódus,PRICE_CLOSE); //--- if the handle is not created if(handle_iRSI==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle \"handle_iRSI\" of the iRSI indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(per_kis), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- create handle of the indicator iStochastic handle_iStochastic_M15=iStochastic(m_symbol.Name(),per_kis,ST_indikátor_periódus,3,ST_lassuló,MODE_SMA,STO_CLOSECLOSE); //--- if the handle is not created if(handle_iStochastic_M15==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle \"handle_iStochastic_M15\" of the iStochastic indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(per_kis), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); }
//--- I would like to draw out these outcomes. double StRSI=(Stoh_fast*RSI0)/100.0; double StRSI_prew=(Stoh_fast_prew*RSI1)/100.0; //---
I would like to draw out the result of Stochastic multiplied by RSI.
I do not understand .
Try to explain in other words or draw a picture.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Polish Layer:
The Expert Advisor is based on the following indicators: RSI, WPR, Stochastic, Moving Average, deMarker
Author: Vladimir Karputov