//****** project (module expert): tf-test-g1_module_exp.mq5 //+------------------------------------------------------------------+ //| The program code is generated Modular project generator | //| Copyright 2010-2017, Sergey Pavlov (DC2008) | //| http://www.mql5.com/ru/users/dc2008 | //+------------------------------------------------------------------+ #property copyright "Copyright 2010-2017, Sergey Pavlov (DC2008)" #property link "http://www.mql5.com/ru/users/dc2008" #property link "1.00" #property link "Example of a multimodule expert: project TF-TEST-G1 Main module." #property link "The project uses 7 external modules." //--- #include //--- MqlTick last_tick; CTrade trade; //--- input string e_ordner="Shared Projects\\Indicatoren\\3133\\"; input int e_bands_period=80; // Moving average period int e_bands_shift=0; // shift input double e_deviation=3.0; // Number of standard deviations input ENUM_APPLIED_PRICE e_applied_price=PRICE_CLOSE; // Price type input bool on_module=true; // whether or not to use plug-ins //--- double lot=0.01; // Fixed lot double min_lot=0.01; // Minimum allowable lot bool on_trade=false; // Trade function flag //--- Variable for storing the indicator iBands handle int handle_Bands; //--- module 1 bool on_lot=false; int handle_m1; //--- module 2 bool on_SL=false; int handle_m2; //--- module 3 bool on_TP=false; int handle_m3; //--- module 4 bool on_Trail=false; int handle_m4; //--- module 5 bool on_signals=false; int handle_m5; //--- module 6 bool on_Filter=false; int handle_m6; //--- module 7 bool on_Breakeven=false; int handle_m7; //+------------------------------------------------------------------+ //| Structure of trading signals | //+------------------------------------------------------------------+ struct sSignal { bool Buy; // Buy signal bool Sell; // Sell signal }; //+------------------------------------------------------------------+ //| Trading signals generator | //+------------------------------------------------------------------+ sSignal Buy_or_Sell() { sSignal res= {false,false}; //--- MODULE 5 if(on_signals) { // If there is an additional module double buffer_m5[]; ArraySetAsSeries(buffer_m5,true); if(CopyBuffer(handle_m5,0,0,1,buffer_m5)<0) return(res); Print(__FUNCTION__+" buffer_m5 : "+(string)buffer_m5[0]); if(buffer_m5[0]<-1) res.Sell=true; if(buffer_m5[0]>1) res.Buy=true; } //--- MODULE 6 if(on_Filter) { // If there is an additional module double buffer_m6[]; ArraySetAsSeries(buffer_m6,true); if(CopyBuffer(handle_m6,0,0,1,buffer_m6)<0) return(res); lot=buffer_m6[0]; if(buffer_m6[0]<1) res.Buy=false; if(buffer_m6[0]>-1) res.Sell=false; } //--- //--- Indicator buffers double UpperBuffer[]; double LowerBuffer[]; double MiddleBuffer[]; ArraySetAsSeries(MiddleBuffer,true); CopyBuffer(handle_Bands,0,0,1,MiddleBuffer); ArraySetAsSeries(UpperBuffer,true); CopyBuffer(handle_Bands,1,0,1,UpperBuffer); ArraySetAsSeries(LowerBuffer,true); CopyBuffer(handle_Bands,2,0,1,LowerBuffer); //--- Timeseries double L[]; double H[]; ArraySetAsSeries(L,true); CopyLow(_Symbol,_Period,0,1,L); ArraySetAsSeries(H,true); CopyHigh(_Symbol,_Period,0,1,H); if(H[0]>UpperBuffer[0]&& L[0]>MiddleBuffer[0]) res.Sell=true; if(L[0]0) { // If there is an additional module double buffer_m4[]; ArraySetAsSeries(buffer_m4,true); if(CopyBuffer(handle_m4,0,0,1,buffer_m4)<0) return; double TR=buffer_m4[0]; if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) if(PositionGetDouble(POSITION_PRICE_CURRENT)-TR*_Point>PositionGetDouble(POSITION_PRICE_OPEN)) { double price_SL=PositionGetDouble(POSITION_PRICE_CURRENT)-TR*_Point; if(price_SL>PositionGetDouble(POSITION_SL)) trade.PositionModify(_Symbol,NormalizeDouble(price_SL,Digits()),0); } if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) if(PositionGetDouble(POSITION_PRICE_CURRENT)+TR*_Point0) { // If there is an additional module double buffer_m7[]; ArraySetAsSeries(buffer_m7,true); if(CopyBuffer(handle_m7,0,0,1,buffer_m7)<0) return; double TRB=buffer_m7[0]; if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) if(PositionGetDouble(POSITION_PRICE_CURRENT)-TRB*_Point>PositionGetDouble(POSITION_PRICE_OPEN)) { double price_SL=PositionGetDouble(POSITION_PRICE_CURRENT)-5*_Point; if(price_SL>PositionGetDouble(POSITION_SL)) trade.PositionModify(_Symbol,NormalizeDouble(price_SL,Digits()),PositionGetDouble(POSITION_TP)); } if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) if(PositionGetDouble(POSITION_PRICE_CURRENT)+TRB*_Point