Code: Select all
int init(){ //This section contains code which executes only on startup
//This paints level lines on the chart, at a percentage of the chart range. I have chosen 20% and 80%.
double WindowPriceRange=WindowPriceMax()-WindowPriceMin();
ObjectCreate("_Level1",OBJ_HLINE,0,Time[0],WindowPriceMin()+WindowPriceRange*0.2); ObjectSet("_Level1",OBJPROP_COLOR,Yellow); ObjectSet("_Level1",OBJPROP_STYLE,STYLE_SOLID);
ObjectCreate("_Level2",OBJ_HLINE,0,Time[0],WindowPriceMin()+WindowPriceRange*0.8); ObjectSet("_Level2",OBJPROP_COLOR,Yellow); ObjectSet("_Level2",OBJPROP_STYLE,STYLE_SOLID);
} // End of init routine
//-------------------------------------------------------------------------------------------------------------------------------
int start(){
// This routine paints a 0-100 stochastic oscillator on the main chart, instead of creating a separate chart window.
double WindowPriceRange=WindowPriceMax()-WindowPriceMin(); // Determine the range of the chart window
double Indicator1PricePos, Indicator1PricePosPrev, Indicator2PricePos, Indicator2PricePosPrev;
ObjectMove("_Level1",0,Time[0],WindowPriceMin()+WindowPriceRange*0.2); // Move the level lines if the chart is zoomed, etc.
ObjectMove("_Level2",0,Time[0],WindowPriceMin()+WindowPriceRange*0.8); // Move the level lines if the chart is zoomed, etc.
int c; // define a counting variable for a loop
while (c<Bars) // define the limits of the loop
{
Indicator1PricePos=(WindowPriceMin()+((iStochastic(NULL,0,14,3,7,MODE_SMA,0,MODE_MAIN,c)/100)*WindowPriceRange));
Indicator1PricePosPrev=(WindowPriceMin()+((iStochastic(NULL,0,14,3,7,MODE_SMA,0,MODE_MAIN,c+1)/100)*WindowPriceRange));
Indicator2PricePos=(WindowPriceMin()+((iStochastic(NULL,0,14,3,7,MODE_SMA,0,MODE_SIGNAL,c)/100)*WindowPriceRange));
Indicator2PricePosPrev=(WindowPriceMin()+((iStochastic(NULL,0,14,3,7,MODE_SMA,0,MODE_SIGNAL,c+1)/100)*WindowPriceRange));
ObjectCreate("_Indicator1"+c,OBJ_TREND,0,Time[c],Low[c]); ObjectSet("_Indicator1"+c,OBJPROP_PRICE1,Indicator1PricePosPrev); ObjectSet("_Indicator1"+c,OBJPROP_PRICE2,Indicator1PricePos); ObjectSet("_Indicator1"+c,OBJPROP_TIME1,Time[c+1]); ObjectSet("_Indicator1"+c,OBJPROP_TIME2,Time[c]); ObjectSet("_Indicator1"+c,OBJPROP_RAY,0); ObjectSet("_Indicator1"+c,OBJPROP_COLOR,DodgerBlue); ObjectSet("_Indicator1"+c,OBJPROP_WIDTH,1); ObjectSet("_Indicator1"+c,OBJPROP_BACK,1);
ObjectCreate("_Indicator2"+c,OBJ_TREND,0,Time[c],Low[c]); ObjectSet("_Indicator2"+c,OBJPROP_PRICE1,Indicator2PricePosPrev); ObjectSet("_Indicator2"+c,OBJPROP_PRICE2,Indicator2PricePos); ObjectSet("_Indicator2"+c,OBJPROP_TIME1,Time[c+1]); ObjectSet("_Indicator2"+c,OBJPROP_TIME2,Time[c]); ObjectSet("_Indicator2"+c,OBJPROP_RAY,0); ObjectSet("_Indicator2"+c,OBJPROP_COLOR,Blue); ObjectSet("_Indicator2"+c,OBJPROP_WIDTH,1); ObjectSet("_Indicator2"+c,OBJPROP_BACK,1);
c++;
} // End of this loop
} // End of start routine
//-------------------------------------------------------------------------------------------------------------------------------
int deinit(){ //This section contains code which executes only on shutdown of the EA. Things like deleting drawing objects, etc.
ObjectsDeleteAll();
} // End of deinit routine
- On startup, two horizontal lines are painted onto the chart window. These are user-definable limit lines, for visual purposes.
- If the chart moves or is zoomed in/out, these lines will adjust their position relative to the window. So, providing there are sufficient incoming ticks, these lines will rearrange themselves.
- A loop calculates the stochastic main and signal lines for each particular bar, and paints them onto the chart, joining them up with the values for the previous bar.
That's about it, really! I hope someone finds it useful.