//+------------------------------------------------------------------+ //| geSigmoid.mq4 | //| Copyright © 2007, ver 1.0 | //| Forte928 | //+------------------------------------------------------------------+ #property copyright "Forte928" #property link "" #define IndicatorName "geSigmoid" #property indicator_chart_window //roperty indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Tomato #property indicator_color2 YellowGreen #property indicator_color3 Wheat #property indicator_color4 LightSeaGreen extern int FirstPoint = 50; extern double Error = 0.005; extern int WidthPoint = 3; extern int WidthLine = 2; //double FreqTOL =0.0001;//Tolerance of frequency calculation for Method 1 double FxView1[]; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Work Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ double TimeBuf1[]; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Initialization program Buffers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void InitBufferam(int iBufferSize) { ArrayResize(TimeBuf1,iBufferSize); return; } void EmptyBufferam() { ArrayInitialize(TimeBuf1,EMPTY_VALUE); // --> ArrayInitialize(FxView1,EMPTY_VALUE); return; } void DoneBufferam() { ArrayResize(TimeBuf1,0); return; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Program Constants ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int MaxPeriod=0; int CalcCount=0; string UniqueName=""; double FxLeft=0; double FxRight=0; int IxLeft=0; int IxRight=0; int IxCount=0; int Counter=2000; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Custom indicator initialization function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int init() { //---- initialization program values -------------------------------- MaxPeriod=0;//MathMax(EMAPrd,WinSize); InitBufferam(MaxCounter(Counter,MaxPeriod)); CalcCount=InitCounter(Counter,MaxPeriod); //---- initialization indicators ------------------------------------- SetupChartLine(0,FxView1,0,WidthLine,"Sigmoid"+FirstPoint);// SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,ValueBuf0); MathSrand(TimeLocal()); UniqueName=IndicatorName+MathRand(); IxLeft=FirstPoint; //---- return(0); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Custom indicator deinitialization function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int deinit() { //---- DoneBufferam(); ObjectDelete(UniqueName+"LF"); ObjectDelete(UniqueName+"RG"); //---- return(0); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Start defination ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int start() { if (!StartCounter(IndicatorName,Counter,CalcCount,MaxPeriod)) return(-1); //------------------------------------------------------------------------------------ EmptyBufferam(); //+-------------------------- Begin Cycle ---------------------------------------------------+\\ if (ObjectFind(UniqueName+"LF")<0) { ObjectCreate(UniqueName+"LF",OBJ_ARROW,0,0,0); ObjectSet(UniqueName+"LF",OBJPROP_TIME1,Time[IxLeft]); ObjectSet(UniqueName+"LF",OBJPROP_PRICE1,Low[IxLeft]+10*Point); ObjectSet(UniqueName+"LF",OBJPROP_ARROWCODE,5); ObjectSet(UniqueName+"LF",OBJPROP_WIDTH,WidthPoint); } if (ObjectFind(UniqueName+"RG")<0) { ObjectCreate(UniqueName+"RG",OBJ_ARROW,0,0,0); ObjectSet(UniqueName+"RG",OBJPROP_TIME1,Time[0]); ObjectSet(UniqueName+"RG",OBJPROP_PRICE1,High[0]+10*Point); ObjectSet(UniqueName+"RG",OBJPROP_ARROWCODE,6); ObjectSet(UniqueName+"RG",OBJPROP_WIDTH,WidthPoint); } IxLeft=iBarShift(NULL,Period(),ObjectGet(UniqueName+"LF",OBJPROP_TIME1),false); IxRight=iBarShift(NULL,Period(),ObjectGet(UniqueName+"RG",OBJPROP_TIME1),false); IxCount=IxLeft-IxRight+1; SetIndexShift(0,IxCount);//(IxLeft-IxRight)); double Alpha=-MathLog(1/Error-1)/(-IxCount); if (Close[IxLeft]>Close[IxRight]) { FxLeft=High[IxLeft]; FxRight=Low[IxRight]; } else { FxLeft=Low[IxLeft]; FxRight=High[IxRight]; } Print(FxLeft," ",FxRight); for (int Rx=IxCount-1;Rx>=0;Rx--){ TimeBuf1[Rx+IxCount]=1/(1+MathExp(-Alpha*(-Rx)))*(FxRight-FxLeft)/0.5+FxLeft; TimeBuf1[Rx]=1/(1+MathExp(-Alpha*(IxCount-Rx)))*(FxRight-FxLeft)/0.5+FxLeft; } ArrayCopy(FxView1,TimeBuf1,IxRight,0,IxCount*2); // ArrayCopy(FxView2,TimeBuf4,Shift,0,CalcCount); // ArrayCopy(FxView3,TimeBuf5,Shift,0,CalcCount); // ArrayCopy(FxView4,TimeBuf6,Shift,0,CalcCount); //---- return(0); } //----------------------------------------------------------------------------------------------- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~ InitCounter ~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int InitCounter(int iPreCount,int iMaxPeriod) { // Rule 1 //if ((Result==0)||(Result>Bars)) Result=Bars; int Result=MaxCounter(iPreCount,iMaxPeriod); // Rule 2 if ((Result+iMaxPeriod)>Bars) Result=Bars-iMaxPeriod; // Rule 3 if (Result<iMaxPeriod) Result=0; else Result=Result+iMaxPeriod; return(Result); } //------------------------------------------ StartCounter -------------------------- bool StartCounter(string WindowName,int iPreCount,int& iCalcCount,int iMaxPeriod) { if ((iPreCount>iCalcCount)||(iPreCount==0)) iCalcCount=InitCounter(iPreCount,iMaxPeriod); if (iCalcCount==0) { Alert(WindowName+" "+Symbol()+"("+Period()+") - Limited Calculate Period"); return(false); } return(true); //int iBarCount=IndicatorCounted(); //if (iBarCount>0) return(true); //Print("StartCounter"); return(false); } //------------------------------------------ StartCounter -------------------------- int MaxCounter(int iPreCount,int iMaxPeriod) { int Result=iPreCount; // Rule 1 //if ((Result==0)||(Result>Bars)) Result=Bars; if (Result==0) Result=Bars-1; if (Result<iMaxPeriod) Result=iMaxPeriod; return(Result+iMaxPeriod); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~ Style active Line ~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void SetupChartLine(int Index,double& ViewAy[],int Style,int Width,string Label) { switch(Style) { case 0 : SetIndexStyle(Index,DRAW_LINE,STYLE_SOLID,Width);break; case 1 : SetIndexStyle(Index,DRAW_HISTOGRAM,STYLE_SOLID,Width);break; case 2 : SetIndexStyle(Index,DRAW_ARROW,STYLE_SOLID,Width);break; default : SetIndexStyle(Index,DRAW_LINE,STYLE_SOLID,Width);break; } if (Label!="") SetIndexLabel(Index,Label); SetIndexBuffer(Index,ViewAy); return(0); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Series array that contains the lowest prices of each bar
Series array that contains the highest prices of each bar
Series array that contains close prices for each bar
Indicator Curves created:
Implements a curve of type DRAW_LINE
Implements a curve of type DRAW_HISTOGRAM
Implements a curve of type DRAW_ARROW
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Other Features:
It issuies visual alerts to the screen