//+------------------------------------------------------------------+
//| SwingMan HiLo Activator2.mq4 |
//| SwingMan |
//| soc607@t-online.de |
//+------------------------------------------------------------------+
#property copyright "SwingMan"
#property link "soc607@t-online.de"
#property indicator_chart_window
//---- indicator settings
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters ----------------------------------------------
extern int Period_HiLo = 10;
//--------------------------------------------------------------------
//---- indicator buffers
double BufferHighs[];
double BufferLows[];
//-- Arrays
double dHighs[],dLows[];
//-- variables
int iTrend;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//-- Arrays
ArraySetAsSeries(dHighs,true);
ArraySetAsSeries(dLows,true);
//---- indicator buffers mapping
SetIndexBuffer(0,BufferHighs);
SetIndexBuffer(1,BufferLows);
//---- drawing settings
SetIndexStyle(0,DRAW_LINE,0,2); // Highs
SetIndexStyle(1,DRAW_LINE,0,2); // Lows
IndicatorDigits(Digits);
SetIndexDrawBegin(0,Period_HiLo);
SetIndexDrawBegin(1,Period_HiLo);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("SwingMan HiLoActivator2");
Comment("SwingMan HiLoActivator2 (" + Period_HiLo +") ");
SetIndexLabel(0,"Highs");
SetIndexLabel(1,"Lows");
//--
iTrend = 0;
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
if (counted_bars<0) return(-1);
if(Bars<=10) return(0);
if (counted_bars>0) counted_bars--;
int limit = Bars - counted_bars;
ArrayResize(dHighs,Bars);
ArrayResize(dLows,Bars);
//----
for (int i = 0; i <=limit-1; i++)
{
dHighs[i] = iMA(NULL, 0, Period_HiLo, 0, MODE_SMA, PRICE_HIGH, i);
dLows[i] = iMA(NULL, 0, Period_HiLo, 0, MODE_SMA, PRICE_LOW, i);
}
for (i=limit-Period_HiLo; i >=0; i--)
{
BufferHighs[i] = EMPTY_VALUE;
BufferLows[i] = EMPTY_VALUE;
//-- first trend
if (iTrend == 0) {
if (Close[i] > dHighs[i]) iTrend = 1;
else
if (Close[i] < dLows[i]) iTrend = -1;
}
//-- up trend
if (iTrend == 1) {
if (Close[i] < dLows[i]) {
BufferHighs[i] = dHighs[i];
iTrend = -1;
}
else {
BufferLows[i] = dLows[i];
}
}
else
//-- down trend
if (iTrend == -1) {
if (Close[i] > dHighs[i]) {
BufferLows[i] = dLows[i];
iTrend = 1;
}
else {
BufferHighs[i] = dHighs[i];
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Files:
SwingMan_HiLo_Activator2.mq4
4 kb
- Ask!
- Why division don't works??
- Coding help
-
Play videoPlease edit your post.
For large amounts of code, attach it.
ArrayResize(dHighs,Bars); ArrayResize(dLows,Bars); : if (Close[i] > dHighs[i]) iTrend = 1;
Those two must be buffers not arrays. Resizing arrays will not shift existing values, but the if statement assumes they are.- Do not use separate a variable (iTrend.) After the first run, you must retrieve the trend for index one to be used on index 0. Either process bar zero never or only once.
int limit = Bars - counted_bars; for (int i = 0; i <=limit-1; i++) : dHighs[i] = iMA(NULL, 0, Period_HiLo, 0, MODE_SMA, PRICE_HIGH, i);
The look back length for MA is Period_HiLo. The look back length for trend is that plus 1. Do your lookbacks correctly.- Help you with what? You haven't stated a problem.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register