- #property indicator_chart_window
- #property indicator_buffers 2
- #property indicator_color1 Red
- //---- input parameters
- extern double atr_range=100;
- extern double ima_range=10;
- extern double atr_factor=3;
- extern int Mode=0;
- extern double DeltaPrice=30;
- double TrStop[];
- double ATR[];
- int init()
- {
- SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
- SetIndexBuffer(0,TrStop);
- SetIndexStyle(1,DRAW_NONE);
- SetIndexBuffer(1,ATR);
- string short_name="!! RisenbergVolatilityCapture";
- IndicatorShortName(short_name);
- SetIndexLabel(1,"range base");
- return(0);
- }
-
-
- int deinit()
- {
- return(0);
- }
- int start()
- {
- int i;
- double DeltaStop;
- int counted_bars=IndicatorCounted();
- if(counted_bars<0) return(-1);
- if(counted_bars>0) counted_bars--;
- int limit=Bars-counted_bars;
- if(counted_bars==0) limit-=1+1;
-
-
- for(i=0; i<limit; i++)
- {
- ATR<i>=iATR(NULL,0,atr_range,i);</i><i>
- }
- for(i=limit-1; i>=0; i --)
- {
- if(Mode==0)
- {
- DeltaStop=iMAOnArray(ATR,0,ima_range,0,MODE_EMA,i)*atr_factor;
- }
- else
- {
- DeltaStop=DeltaPrice*Point;
- }
- if(Close<i>==TrStop[i+1])</i><i>
- {
- TrStop<i>=TrStop[i+1];</i><i>
- }
- else
- {
- if(Close[i+1]<TrStop[i+1] && Close<i><TrStop[i+1])</i><i>
- {
- TrStop<i>=MathMin(TrStop[i+1],Close<i>+DeltaStop);</i></i><i><i>
- }
- else
- {
- if(Close[i+1]>TrStop[i+1] && Close<i>>TrStop[i+1])</i><i>
- {
- TrStop<i>=MathMax(TrStop[i+1],Close<i>-DeltaStop);</i></i><i><i>
- }
- else
- {
- if(Close<i>>TrStop[i+1]) TrStop<i>=Close<i>-DeltaStop; else TrStop<i>=Close<i>+DeltaStop;</i></i></i></i></i><i><i><i>
- }
- }
- }
- }
- Return(0);
- }
-
- </i></i></i></i></i></i></i></i></i></i></i></i>
复制代码
|