#property copyright "SwingMan"
#property link ""
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 IndianRed
#property indicator_color4 LimeGreen
#property indicator_color5 Yellow
#property indicator_color6 Yellow
#property indicator_color7 Green
extern int PriceChannel_Period=5;
extern int RSI_Period=13;
extern int RSISmooth_Period=2;
extern int RSIVolatilityBand_Period=34;
extern int RSITradeSignal_Period=7;
extern int TrendIndicator_Period=55;
extern int RSI_Price=0;
extern int RSI_MavgMODE=0;
extern int RSITradeSignal_MavgMODE=0;
extern double Factor_ShortBars=0.50;
extern int SignalOffset=5;
double RSIBuf[10000],UpZone[10000],BaseLine[10000],DnZone[10000];
double RSILine[10000],RedLine[10000];
double haBuffer_Low[10000];
double haBuffer_High[10000];
double haBuffer_Open[10000];
double haBuffer_Close[10000];
double mavHighs[];
double mavLows[];
double mavTrend[];
double LongSignal[];
double ShortSignal[];
double StopLong[];
double StopShort[];
string sName="Synergy Signals [v2]";
double dSignalOffset, Spread;
int init()
{
IndicatorShortName(sName);
Comment(sName);
dSignalOffset=SignalOffset*Point;
Spread=MarketInfo(Symbol(), MODE_SPREAD) * Point;
ArraySetAsSeries(RSIBuf, true);
ArraySetAsSeries(UpZone, true);
ArraySetAsSeries(BaseLine, true);
ArraySetAsSeries(DnZone, true);
ArraySetAsSeries(RSILine, true);
ArraySetAsSeries(RedLine, true);
ArraySetAsSeries(haBuffer_Low, true);
ArraySetAsSeries(haBuffer_High, true);
ArraySetAsSeries(haBuffer_Open, true);
ArraySetAsSeries(haBuffer_Close, true);
SetIndexBuffer(0,LongSignal);
SetIndexBuffer(1,ShortSignal);
SetIndexStyle(0,DRAW_ARROW,0,1);
SetIndexStyle(1,DRAW_ARROW,0,1);
SetIndexArrow(0,159);
SetIndexArrow(1,159);
SetIndexLabel(0,"LONG Signal");
SetIndexLabel(1,"SHORT Signal");
SetIndexBuffer(2,StopLong);
SetIndexBuffer(3,StopShort);
SetIndexStyle(2,DRAW_ARROW,0,0);
SetIndexStyle(3,DRAW_ARROW,0,0);
SetIndexArrow(2,251);
SetIndexArrow(3,251);
SetIndexLabel(2,"Stop Long");
SetIndexLabel(3,"Stop Short");
SetIndexBuffer(4,mavHighs);
SetIndexBuffer(5,mavLows);
SetIndexBuffer(6,mavTrend);
SetIndexStyle(4,DRAW_LINE,0,2);
SetIndexStyle(5,DRAW_LINE,0,2);
SetIndexStyle(6,DRAW_LINE,0,2);
SetIndexLabel(4,"High mavg");
SetIndexLabel(5,"Low mavg");
SetIndexLabel(6,"Trend line");
SetIndexDrawBegin(0,TrendIndicator_Period);
SetIndexDrawBegin(1,TrendIndicator_Period);
SetIndexDrawBegin(2,TrendIndicator_Period);
SetIndexDrawBegin(3,TrendIndicator_Period);
SetIndexDrawBegin(4,TrendIndicator_Period);
SetIndexDrawBegin(5,TrendIndicator_Period);
SetIndexDrawBegin(6,TrendIndicator_Period);
return(0);
}
int deinit() { return(0); }
int start()
{
bool TradeLong =false;
bool TradeShort=false;
double MA,RSI[];
ArrayResize(RSI,RSIVolatilityBand_Period);
int counted_bars=IndicatorCounted();
int limit=Bars-counted_bars-1;
for(int i=limit; i>=0; i--)
{
RSIBuf[i]=(iRSI(NULL,0,RSI_Period,RSI_Price,i));
MA=0;
for(int x=i; x<i+RSIVolatilityBand_Period; x++)
{
RSI[x-i]=RSIBuf[x];
MA+=RSIBuf[x]/RSIVolatilityBand_Period;
}
UpZone[i]=(MA + (1.6185 * StDev(RSI,RSIVolatilityBand_Period)));
DnZone[i]=(MA - (1.6185 * StDev(RSI,RSIVolatilityBand_Period)));
BaseLine[i]=((UpZone[i] + DnZone[i])*0.5);
}
for(i=limit-1;i>=0;i--)
{
RSILine[i]=(iMAOnArray(RSIBuf,0,RSISmooth_Period,0,RSI_MavgMODE,i));
RedLine[i]=(iMAOnArray(RSIBuf,0,RSITradeSignal_Period,0,RSITradeSignal_MavgMODE,i));
}
for(i=limit-1;i>=0;i--)
{
mavHighs[i]=iMA(NULL,0,PriceChannel_Period, 0,MODE_SMMA,PRICE_HIGH,i);
mavLows[i] =iMA(NULL,0,PriceChannel_Period, 0,MODE_SMMA,PRICE_LOW,i);
mavTrend[i]=iMA(NULL,0,TrendIndicator_Period,0,MODE_SMMA,PRICE_MEDIAN,i);
}
for(i=limit-1;i>=0;i--)
{
double haOpen, haHigh, haLow, haClose;
haOpen=(haBuffer_Open[i+1]+haBuffer_Close[i+1])*0.50;
haClose=(Open[i]+High[i]+Low[i]+Close[i])*0.25;
haHigh=MathMax(High[i], MathMax(haOpen, haClose));
haLow=MathMin(Low[i], MathMin(haOpen, haClose));
if (haOpen<haClose)
{
haBuffer_Low[i] =haLow;
haBuffer_High[i]=haHigh;
}
else
{
haBuffer_Low[i] =haHigh;
haBuffer_High[i]=haLow;
}
haBuffer_Open[i] =haOpen;
haBuffer_Close[i]=haClose;
if (haBuffer_High[i] > haBuffer_Low[i])
{
double thisHigh=haBuffer_High[i];
double thisLow =haBuffer_Low[i];
}
else
{
thisHigh=haBuffer_Low[i];
thisLow =haBuffer_High[i];
}
bool Long_RSI_PriceLine=(RSILine[i] > 50.0) && (RSILine[i] < 68.0);
bool Long_RSI_AboveTradeSignal =(RSILine[i] > RedLine[i]);
bool Long_RSI_AboveMarketBaseLine=(RSILine[i] > BaseLine[i]);
bool Long_CloseHACandle =(haClose > mavHighs[i]);
bool Long_PriceActionChannelUp =(mavHighs[i] > mavHighs[i+1]);
bool Short_RSI_PriceLine=(RSILine[i] < 50.0) && (RSILine[i] > 32.0);
bool Short_RSI_BelowTradeSignal =(RSILine[i] < RedLine[i]);
bool Short_RSI_BelowMarketBaseLine=(RSILine[i] < BaseLine[i]);
bool Short_CloseHACandle =(haClose < mavLows[i]);
bool Short_PriceActionChannelDown =(mavLows[i] < mavLows[i+1]);
if(Long_RSI_PriceLine && Long_RSI_AboveTradeSignal && Long_RSI_AboveMarketBaseLine &&
Long_CloseHACandle && Long_PriceActionChannelUp )
{
LongSignal[i]=thisHigh + dSignalOffset;
TradeLong =true;
TradeShort=false;
}
if(Short_RSI_PriceLine && Short_RSI_BelowTradeSignal && Short_RSI_BelowMarketBaseLine &&
Short_CloseHACandle && Short_PriceActionChannelDown )
{
ShortSignal[i]=thisLow - dSignalOffset;
TradeLong =false;
TradeShort=true;
}
bool Exit_RSI_PriceLine=(RSILine[i] > 68.0) || (RSILine[i] < 32.0);
bool Exit_BarRange =MathAbs(haBuffer_High[i] - haBuffer_Low[i]) <
Factor_ShortBars*MathAbs(haBuffer_High[i+1] - haBuffer_Low[i+1]);
bool XLong_RSI_BelowTradeSignal=(RSILine[i] < RedLine[i]) && (RSILine[i+1] > RedLine[i+1]);
bool XLong_RSI_BelowUpperVB=(RSILine[i] < UpZone[i]) && (RSILine[i+1] > UpZone[i+1]);
bool XLong_OpenCloseChange =(haBuffer_Close[i] < haBuffer_Open[i]) && (haBuffer_Close[i+1] > haBuffer_Open[i+1]);
bool XLong_ClosePriceChannel=(haClose < mavHighs[i]) || ((haClose < mavHighs[i]) && (haClose > mavLows[i]));
bool XShort_RSI_AboveTradeSignal=(RSILine[i] > RedLine[i]) && (RSILine[i+1] < RedLine[i+1]);
bool XShort_RSI_AboveLoverVB=(RSILine[i] > DnZone[i]) && (RSILine[i+1] < DnZone[i+1]);
bool XShort_OpenCloseChange =(haBuffer_Close[i] > haBuffer_Open[i]) && (haBuffer_Close[i+1] < haBuffer_Open[i+1]);
bool XShort_ClosePriceChannel=(haClose > mavLows[i]) || ((haClose < mavHighs[i]) && (haClose > mavLows[i]));
if(TradeLong && (Exit_RSI_PriceLine || XLong_RSI_BelowTradeSignal || XLong_RSI_BelowUpperVB ||
Exit_BarRange || XLong_OpenCloseChange || XLong_ClosePriceChannel))
{
StopLong[i]=thisLow - dSignalOffset;
}
if(TradeShort && (Exit_RSI_PriceLine || XShort_RSI_AboveTradeSignal || XShort_RSI_AboveLoverVB ||
Exit_BarRange || XShort_OpenCloseChange || XShort_ClosePriceChannel))
{
StopShort[i]=thisHigh + dSignalOffset;
}
}
return(0);
}
double StDev(double& Data[], int Per)
{
return(MathSqrt(Variance(Data,Per)));
}
double Variance(double& Data[], int Per)
{
double sum, ssum;
for(int i=0; i<Per; i++)
{
sum+=Data[i];
ssum+=MathPow(Data[i],2);
}
return((ssum*Per - sum*sum)/(Per*(Per-1)));
}