| Coding Forum Collaborate, receive help, or discuss coding related issues. |
![]() | | Tweet | |
| | #1 | ||
![]() | Mt4 Code to Tradestation //+------------------------------------------------------------------+ //| 3x Stochastic.mq4 | //+------------------------------------------------------------------+ #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 Silver #property indicator_style1 STYLE_DOT #property indicator_color2 Yellow //Neutral #property indicator_color3 Lime //UPPER #property indicator_color4 Red //LOWER #property indicator_width2 2 #property indicator_width3 2 #property indicator_width4 2 #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_level1 20 #property indicator_level2 80 //---- indicator parameters extern int Sto_Period = 21; extern int Smooth = 9; extern int Signal = 9; //---- indicator buffers double Sto[]; double Sig[]; double Upper[]; double Lower[]; //---- double tmp[][12]; int draw_begin, pBars, mcnt_bars; string TF, fast_name; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- drawing settings SetIndexStyle(0,DRAW_LINE ); SetIndexStyle(1,DRAW_LINE ); SetIndexStyle(2,DRAW_LINE ); SetIndexStyle(3,DRAW_LINE ); draw_begin=Sto_Period+Smo oth+Signal; //---- indicator name IndicatorShortName("3x Stochastic ("+Sto_Period+","+Smooth+ ","+Signal+")"); SetIndexLabel(0,"Sto"); SetIndexLabel(1,"Sig"); SetIndexLabel(2,NULL); SetIndexLabel(3,NULL); //---- indicator buffers mapping SetIndexBuffer(0,Sto); SetIndexBuffer(1,Sig); SetIndexBuffer(2,Upper); SetIndexBuffer(3,Lower); SetIndexDrawBegin(0,draw_ begin); SetIndexDrawBegin(1,draw_ begin); SetIndexDrawBegin(2,draw_ begin); SetIndexDrawBegin(3,draw_ begin); //---- initialization done return(0); } int start() { int limit, y, i, shift, cnt_bars=IndicatorCounted (); double K[], mSto[], mSig[]; int mBars = iBars(NULL,0); if(mBars != pBars) { ArrayResize(K,mBars); ArrayResize(mSto,mBars); ArrayResize(mSig,mBars); ArrayResize(tmp,mBars); pBars = mBars; } if(cnt_bars<1) { for(i=1;i<=draw_begin;i++ ) {Sto[Bars-i]=0; Sig[Bars-i]=0;} mcnt_bars = 1; } if(mcnt_bars > 1) mcnt_bars--; for(y=mcnt_bars-1;y<mBars;y++) { shift = mBars-y-1; double aPrice = iMA(NULL,0,1,0,0,0,shift) ; double up = 0; double dn = 10000000000; for(i=0;i<Sto_Period;i++) { up = MathMax(up,iHigh(NULL,0,s hift+i)); dn = MathMin(dn,iLow(NULL,0,sh ift+i)); } if(up-dn > 0) K[y] = 100*(aPrice - dn)/(up - dn); else K[y] = 0; mSto[y] = Ensign(K[y],mSto,Smooth,y); mSig[y] = Ensign(mSto[y],mSig,Signal,y); Sto[shift] = mSto[y]; Sig[shift] = mSig[y]; // Colors if (Sig[shift] > Sig[shift+1]) { Upper[shift] = Sig[shift]; Upper[shift+1] = Sig[shift+1]; } else { Upper[shift] = EMPTY_VALUE; if (Upper[shift+2] == EMPTY_VALUE) Upper[shift+1] = EMPTY_VALUE; } if (Sig[shift] < Sig[shift+1]) { Lower[shift] = Sig[shift]; Lower[shift+1] = Sig[shift+1]; } else { Lower[shift] = EMPTY_VALUE; if (Lower[shift+2] == EMPTY_VALUE) Lower[shift+1] = EMPTY_VALUE; } } mcnt_bars = mBars-1; return(0); } // Ensign smooth ! double Ensign(double price,double array[],int per,int bar) { if(bar == 2) double ema = price; else if(bar > 2) ema = array[bar-1] + 1.0/(per)*(price - array[bar-1]); //if(bar > 2) ema = array[bar-1] + 2.0/(1+per)*(price - array[bar-1]); EMA - classic formula return(ema); } | ||
| |
|
| | #2 | ||
![]() | Re: Mt4 Code to Tradestation Quote:
the header should have given you a clue what this indicator is about.
__________________ Only an idiot would reply to a stupid post | ||
| |
|
![]() |
| Thread Tools | |
| Display Modes | Help Others By Rating This Thread |
| |
| ∧ Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Convert MT4 Indicator into Tradestation Eld? | goody01 | Coding Forum | 26 | 10-14-2011 12:04 PM |
| Introduction | gassah | Technical Analysis | 78 | 09-08-2010 08:53 AM |
| Help Convert JMA MT4 to Multicharts ELD? Code Inside... | Black Swan | Coding Forum | 2 | 11-11-2009 04:47 PM |
| Copying Code into Tradestation | sdcindy | Support Center | 4 | 09-01-2009 07:56 AM |
| Tradestation Code Help | ephi144 | Coding Forum | 3 | 11-29-2008 08:05 PM |